Rev 224 | 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 | |||
112 | daniel-mar | 20 | if (!defined('IN_OIDPLUS')) die(); |
21 | |||
227 | daniel-mar | 22 | class OIDplusObjectTypePluginOther extends OIDplusObjectTypePlugin { |
2 | daniel-mar | 23 | |
222 | daniel-mar | 24 | public static function getPluginInformation() { |
25 | $out = array(); |
||
26 | $out['name'] = 'Other'; |
||
27 | $out['author'] = 'ViaThinkSoft'; |
||
28 | $out['version'] = null; |
||
29 | $out['descriptionHTML'] = null; |
||
30 | return $out; |
||
31 | } |
||
32 | |||
227 | daniel-mar | 33 | public static function getObjectTypeClassName() { |
34 | return 'OIDplusOther'; |
||
35 | } |
||
36 | |||
37 | } |
||
38 | |||
39 | class OIDplusOther extends OIDplusObject { |
||
40 | private $other; |
||
41 | |||
2 | daniel-mar | 42 | public function __construct($other) { |
16 | daniel-mar | 43 | // No syntax checks |
2 | daniel-mar | 44 | $this->other = $other; |
45 | } |
||
46 | |||
47 | public static function parse($node_id) { |
||
48 | @list($namespace, $other) = explode(':', $node_id, 2); |
||
49 | if ($namespace !== 'other') return false; |
||
50 | return new self($other); |
||
51 | } |
||
52 | |||
53 | public static function objectTypeTitle() { |
||
54 | return "Other objects"; |
||
55 | } |
||
56 | |||
57 | public static function objectTypeTitleShort() { |
||
58 | return "Object"; |
||
59 | } |
||
60 | |||
61 | public static function ns() { |
||
62 | return 'other'; |
||
63 | } |
||
64 | |||
65 | public static function root() { |
||
66 | return 'other:'; |
||
67 | } |
||
68 | |||
69 | public function isRoot() { |
||
70 | return $this->other == ''; |
||
71 | } |
||
72 | |||
73 | public function nodeId() { |
||
74 | return 'other:'.$this->other; |
||
75 | } |
||
76 | |||
77 | public function addString($str) { |
||
78 | if ($this->isRoot()) { |
||
79 | return 'other:'.$str; |
||
80 | } else { |
||
81 | return $this->nodeId() . '\\' . $str; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | public function crudShowId(OIDplusObject $parent) { |
||
86 | if ($parent->isRoot()) { |
||
87 | return substr($this->nodeId(), strlen($parent->nodeId())); |
||
88 | } else { |
||
89 | return substr($this->nodeId(), strlen($parent->nodeId())+1); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | public function crudInsertPrefix() { |
||
94 | return ''; |
||
95 | } |
||
96 | |||
97 | public function jsTreeNodeName(OIDplusObject $parent = null) { |
||
98 | if ($parent == null) return $this->objectTypeTitle(); |
||
99 | if ($parent->isRoot()) { |
||
100 | return substr($this->nodeId(), strlen($parent->nodeId())); |
||
101 | } else { |
||
102 | return substr($this->nodeId(), strlen($parent->nodeId())+1); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | public function defaultTitle() { |
||
107 | $ary = explode('\\', $this->other); // TODO: aber wenn ein arc ein "\" enthält, geht es nicht. besser von db ablesen? |
||
108 | $ary = array_reverse($ary); |
||
109 | return $ary[0]; |
||
110 | } |
||
111 | |||
16 | daniel-mar | 112 | public function isLeafNode() { |
113 | return false; |
||
114 | } |
||
115 | |||
34 | daniel-mar | 116 | public function getContentPage(&$title, &$content, &$icon) { |
55 | daniel-mar | 117 | $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : ''; |
118 | |||
2 | daniel-mar | 119 | if ($this->isRoot()) { |
120 | $title = OIDplusOther::objectTypeTitle(); |
||
121 | |||
150 | daniel-mar | 122 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ?", array(self::root())); |
2 | daniel-mar | 123 | if (OIDplus::db()->num_rows($res) > 0) { |
124 | $content = 'Please select an object in the tree view at the left to show its contents.'; |
||
125 | } else { |
||
126 | $content = 'Currently, no misc objects are registered in the system.'; |
||
127 | } |
||
128 | |||
16 | daniel-mar | 129 | if (!$this->isLeafNode()) { |
130 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
||
131 | $content .= '<h2>Manage root objects</h2>'; |
||
132 | } else { |
||
133 | $content .= '<h2>Available objects</h2>'; |
||
134 | } |
||
135 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 136 | } |
137 | } else { |
||
192 | daniel-mar | 138 | $title = $this->getTitle(); |
139 | |||
11 | daniel-mar | 140 | $content = '<h2>Description</h2>%%DESC%%'; // TODO: add more meta information about the object type |
2 | daniel-mar | 141 | |
16 | daniel-mar | 142 | if (!$this->isLeafNode()) { |
143 | if ($this->userHasWriteRights()) { |
||
144 | $content .= '<h2>Create or change subsequent objects</h2>'; |
||
145 | } else { |
||
146 | $content .= '<h2>Subsequent objects</h2>'; |
||
147 | } |
||
148 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 149 | } |
150 | } |
||
151 | } |
||
20 | daniel-mar | 152 | |
153 | public function one_up() { |
||
38 | daniel-mar | 154 | $oid = $this->other; |
155 | |||
156 | $p = strrpos($oid, '\\'); |
||
157 | if ($p === false) return $oid; |
||
158 | if ($p == 0) return '\\'; |
||
159 | |||
160 | $oid_up = substr($oid, 0, $p); |
||
161 | |||
162 | return self::parse(self::ns().':'.$oid_up); |
||
20 | daniel-mar | 163 | } |
164 | |||
165 | public function distance($to) { |
||
38 | daniel-mar | 166 | if (!is_object($to)) $to = OIDplusObject::parse($to); |
167 | if (!($to instanceof $this)) return false; |
||
168 | |||
169 | $a = $to->other; |
||
170 | $b = $this->other; |
||
171 | |||
172 | if (substr($a,0,1) == '\\') $a = substr($a,1); |
||
173 | if (substr($b,0,1) == '\\') $b = substr($b,1); |
||
174 | |||
175 | $ary = explode('\\', $a); |
||
176 | $bry = explode('\\', $b); |
||
177 | |||
178 | $min_len = min(count($ary), count($bry)); |
||
179 | |||
180 | for ($i=0; $i<$min_len; $i++) { |
||
181 | if ($ary[$i] != $bry[$i]) return false; |
||
182 | } |
||
183 | |||
184 | return count($ary) - count($bry); |
||
20 | daniel-mar | 185 | } |
2 | daniel-mar | 186 | } |