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 OIDplusJava extends OIDplusObject {
  21.         private $java;
  22.  
  23.         public function __construct($java) {
  24.                 $this->java = $java;
  25.         }
  26.  
  27.         public static function parse($node_id) {
  28.                 @list($namespace, $java) = explode(':', $node_id, 2);
  29.                 if ($namespace !== 'java') return false;
  30.                 return new self($java);
  31.         }
  32.  
  33.         public static function objectTypeTitle() {
  34.                 return "Java Package Names";
  35.         }
  36.  
  37.         public static function objectTypeTitleShort() {
  38.                 return "Package";
  39.         }
  40.  
  41.         public static function ns() {
  42.                 return 'java';
  43.         }
  44.  
  45.         public static function root() {
  46.                 return 'java:';
  47.         }
  48.  
  49.         public function isRoot() {
  50.                 return $this->java == '';
  51.         }
  52.  
  53.         public function nodeId() {
  54.                 return 'java:'.$this->java;
  55.         }
  56.  
  57.         public function addString($str) {
  58.                 if ($this->isRoot()) {
  59.                         return 'java:'.$str;
  60.                 } else {
  61.                         if (strpos($str,'.') !== false) die("Please only submit one arc.");
  62.                         return $this->nodeId() . '.' . $str;
  63.                 }
  64.         }
  65.  
  66.         public function crudShowId(OIDplusObject $parent) {
  67.                 return $this->java;
  68.         }
  69.  
  70.         public function crudInsertPrefix() {
  71.                 return $this->isRoot() ? '' : substr($this->addString(''), strlen(self::ns())+1);
  72.         }
  73.  
  74.         public function jsTreeNodeName(OIDplusObject $parent = null) {
  75.                 if ($parent == null) return $this->objectTypeTitle();
  76.                 return $this->java;
  77.         }
  78.  
  79.         public function defaultTitle() {
  80.                 return $this->java;
  81.         }
  82.  
  83.         public function getContentPage(&$title, &$content) {
  84.                 if ($this->isRoot()) {
  85.                         $title = OIDplusJava::objectTypeTitle();
  86.  
  87.                         $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string(self::root())."'");
  88.                         if (OIDplus::db()->num_rows($res) > 0) {
  89.                                 $content  = 'Please select a Java Package Name in the tree view at the left to show its contents.';
  90.                         } else {
  91.                                 $content  = 'Currently, no Java Package Name is registered in the system.';
  92.                         }
  93.  
  94.                         if (OIDplus::authUtils()::isAdminLoggedIn()) {
  95.                                 $content .= '<h2>Manage root objects</h2>';
  96.                         } else {
  97.                                 $content .= '<h2>Available objects</h2>';
  98.                         }
  99.                         $content .= '%%CRUD%%';
  100.                 } else {
  101.                         $content = '<h3>'.explode(':',$this->nodeId())[1].'</h3>';
  102.  
  103.                         $content .= '<h2>Description</h2><br><br>%%DESC%%<br><br>'; // TODO: add more meta information about the object type
  104.  
  105.                         if ($this->userHasWriteRights()) {
  106.                                 $content .= '<h2>Create or change subsequent objects</h2>';
  107.                         } else {
  108.                                 $content .= '<h2>Subsequent objects</h2>';
  109.                         }
  110.                         $content .= '%%CRUD%%';
  111.  
  112.                 }
  113.         }
  114. }
  115.  
  116. OIDplusObject::$registeredObjectTypes[] = 'OIDplusJava';
  117.