Rev 21 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 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) { |
||
16 | daniel-mar | 24 | // No syntax checks |
2 | daniel-mar | 25 | $this->other = $other; |
26 | } |
||
27 | |||
28 | public static function parse($node_id) { |
||
29 | @list($namespace, $other) = explode(':', $node_id, 2); |
||
30 | if ($namespace !== 'other') return false; |
||
31 | return new self($other); |
||
32 | } |
||
33 | |||
34 | public static function objectTypeTitle() { |
||
35 | return "Other objects"; |
||
36 | } |
||
37 | |||
38 | public static function objectTypeTitleShort() { |
||
39 | return "Object"; |
||
40 | } |
||
41 | |||
42 | public static function ns() { |
||
43 | return 'other'; |
||
44 | } |
||
45 | |||
46 | public static function root() { |
||
47 | return 'other:'; |
||
48 | } |
||
49 | |||
50 | public function isRoot() { |
||
51 | return $this->other == ''; |
||
52 | } |
||
53 | |||
54 | public function nodeId() { |
||
55 | return 'other:'.$this->other; |
||
56 | } |
||
57 | |||
58 | public function addString($str) { |
||
59 | if ($this->isRoot()) { |
||
60 | return 'other:'.$str; |
||
61 | } else { |
||
62 | return $this->nodeId() . '\\' . $str; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public function crudShowId(OIDplusObject $parent) { |
||
67 | if ($parent->isRoot()) { |
||
68 | return substr($this->nodeId(), strlen($parent->nodeId())); |
||
69 | } else { |
||
70 | return substr($this->nodeId(), strlen($parent->nodeId())+1); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | public function crudInsertPrefix() { |
||
75 | return ''; |
||
76 | } |
||
77 | |||
78 | public function jsTreeNodeName(OIDplusObject $parent = null) { |
||
79 | if ($parent == null) return $this->objectTypeTitle(); |
||
80 | if ($parent->isRoot()) { |
||
81 | return substr($this->nodeId(), strlen($parent->nodeId())); |
||
82 | } else { |
||
83 | return substr($this->nodeId(), strlen($parent->nodeId())+1); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | public function defaultTitle() { |
||
88 | $ary = explode('\\', $this->other); // TODO: aber wenn ein arc ein "\" enthält, geht es nicht. besser von db ablesen? |
||
89 | $ary = array_reverse($ary); |
||
90 | return $ary[0]; |
||
91 | } |
||
92 | |||
16 | daniel-mar | 93 | public function isLeafNode() { |
94 | return false; |
||
95 | } |
||
96 | |||
34 | daniel-mar | 97 | public function getContentPage(&$title, &$content, &$icon) { |
2 | daniel-mar | 98 | if ($this->isRoot()) { |
99 | $title = OIDplusOther::objectTypeTitle(); |
||
100 | |||
101 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string(self::root())."'"); |
||
102 | if (OIDplus::db()->num_rows($res) > 0) { |
||
103 | $content = 'Please select an object in the tree view at the left to show its contents.'; |
||
104 | } else { |
||
105 | $content = 'Currently, no misc objects are registered in the system.'; |
||
106 | } |
||
107 | |||
16 | daniel-mar | 108 | if (!$this->isLeafNode()) { |
109 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
||
110 | $content .= '<h2>Manage root objects</h2>'; |
||
111 | } else { |
||
112 | $content .= '<h2>Available objects</h2>'; |
||
113 | } |
||
114 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 115 | } |
116 | } else { |
||
11 | daniel-mar | 117 | $content = '<h2>Description</h2>%%DESC%%'; // TODO: add more meta information about the object type |
2 | daniel-mar | 118 | |
16 | daniel-mar | 119 | if (!$this->isLeafNode()) { |
120 | if ($this->userHasWriteRights()) { |
||
121 | $content .= '<h2>Create or change subsequent objects</h2>'; |
||
122 | } else { |
||
123 | $content .= '<h2>Subsequent objects</h2>'; |
||
124 | } |
||
125 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 126 | } |
21 | daniel-mar | 127 | |
128 | $content .= '<br>%%WHOIS%%'; |
||
2 | daniel-mar | 129 | } |
130 | } |
||
20 | daniel-mar | 131 | |
132 | public function one_up() { |
||
133 | // TODO |
||
134 | return false; |
||
135 | } |
||
136 | |||
137 | public function distance($to) { |
||
138 | // TODO |
||
139 | return null; |
||
140 | } |
||
2 | daniel-mar | 141 | } |
142 | |||
143 | OIDplusObject::$registeredObjectTypes[] = 'OIDplusOther'; |