Subversion Repositories oidplus

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. class OIDplusOther extends OIDplusObject {
  21.         private $other;
  22.  
  23.         public function __construct($other) {
  24.                 $this->other = $other;
  25.         }
  26.  
  27.         public static function parse($node_id) {
  28.                 @list($namespace, $other) = explode(':', $node_id, 2);
  29.                 if ($namespace !== 'other') return false;
  30.                 return new self($other);
  31.         }
  32.  
  33.         public static function objectTypeTitle() {
  34.                 return "Other objects";
  35.         }
  36.  
  37.         public static function objectTypeTitleShort() {
  38.                 return "Object";
  39.         }
  40.  
  41.         public static function ns() {
  42.                 return 'other';
  43.         }
  44.  
  45.         public static function root() {
  46.                 return 'other:';
  47.         }
  48.  
  49.         public function isRoot() {
  50.                 return $this->other == '';
  51.         }
  52.  
  53.         public function nodeId() {
  54.                 return 'other:'.$this->other;
  55.         }
  56.  
  57.         public function addString($str) {
  58.                 if ($this->isRoot()) {
  59.                         return 'other:'.$str;
  60.                 } else {
  61.                         return $this->nodeId() . '\\' . $str;
  62.                 }
  63.         }
  64.  
  65.         public function crudShowId(OIDplusObject $parent) {
  66.                 if ($parent->isRoot()) {
  67.                         return substr($this->nodeId(), strlen($parent->nodeId()));
  68.                 } else {
  69.                         return substr($this->nodeId(), strlen($parent->nodeId())+1);
  70.                 }
  71.         }
  72.  
  73.         public function crudInsertPrefix() {
  74.                 return '';
  75.         }
  76.  
  77.         public function jsTreeNodeName(OIDplusObject $parent = null) {
  78.                 if ($parent == null) return $this->objectTypeTitle();
  79.                 if ($parent->isRoot()) {
  80.                         return substr($this->nodeId(), strlen($parent->nodeId()));
  81.                 } else {
  82.                         return substr($this->nodeId(), strlen($parent->nodeId())+1);
  83.                 }
  84.         }
  85.  
  86.         public function defaultTitle() {
  87.                 $ary = explode('\\', $this->other); // TODO: aber wenn ein arc ein "\" enthält, geht es nicht. besser von db ablesen?
  88.                 $ary = array_reverse($ary);
  89.                 return $ary[0];
  90.         }
  91.  
  92.         public function getContentPage(&$title, &$content) {
  93.                 if ($this->isRoot()) {
  94.                         $title = OIDplusOther::objectTypeTitle();
  95.  
  96.                         $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string(self::root())."'");
  97.                         if (OIDplus::db()->num_rows($res) > 0) {
  98.                                 $content  = 'Please select an object in the tree view at the left to show its contents.';
  99.                         } else {
  100.                                 $content  = 'Currently, no misc objects are registered in the system.';
  101.                         }
  102.  
  103.                         if (OIDplus::authUtils()::isAdminLoggedIn()) {
  104.                                 $content .= '<h2>Manage root objects</h2>';
  105.                         } else {
  106.                                 $content .= '<h2>Available objects</h2>';
  107.                         }
  108.                         $content .= '%%CRUD%%';
  109.                 } else {
  110.                         $content = '<h2>Description</h2><br><br>%%DESC%%<br><br>'; // TODO: add more meta information about the object type
  111.  
  112.                         if ($this->userHasWriteRights()) {
  113.                                 $content .= '<h2>Create or change subsequent objects</h2>';
  114.                         } else {
  115.                                 $content .= '<h2>Subsequent objects</h2>';
  116.                         }
  117.                         $content .= '%%CRUD%%';
  118.                 }
  119.         }
  120. }
  121.  
  122. OIDplusObject::$registeredObjectTypes[] = 'OIDplusOther';
  123.