Rev 277 | 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 | |||
227 | daniel-mar | 20 | class OIDplusOther extends OIDplusObject { |
21 | private $other; |
||
22 | |||
2 | daniel-mar | 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() { |
||
360 | daniel-mar | 35 | return _L('Other objects'); |
2 | daniel-mar | 36 | } |
37 | |||
38 | public static function objectTypeTitleShort() { |
||
360 | daniel-mar | 39 | return _L('Object'); |
2 | daniel-mar | 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 | |||
247 | daniel-mar | 54 | public function nodeId($with_ns=true) { |
55 | return $with_ns ? 'other:'.$this->other : $this->other; |
||
2 | daniel-mar | 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) { |
55 | daniel-mar | 98 | $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : ''; |
99 | |||
2 | daniel-mar | 100 | if ($this->isRoot()) { |
101 | $title = OIDplusOther::objectTypeTitle(); |
||
102 | |||
261 | daniel-mar | 103 | $res = OIDplus::db()->query("select * from ###objects where parent = ?", array(self::root())); |
236 | daniel-mar | 104 | if ($res->num_rows() > 0) { |
360 | daniel-mar | 105 | $content = _L('Please select an object in the tree view at the left to show its contents.'); |
2 | daniel-mar | 106 | } else { |
360 | daniel-mar | 107 | $content = _L('Currently, no misc. objects are registered in the system.'); |
2 | daniel-mar | 108 | } |
109 | |||
16 | daniel-mar | 110 | if (!$this->isLeafNode()) { |
111 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
||
360 | daniel-mar | 112 | $content .= '<h2>'._L('Manage root objects').'</h2>'; |
16 | daniel-mar | 113 | } else { |
360 | daniel-mar | 114 | $content .= '<h2>'._L('Available objects').'</h2>'; |
16 | daniel-mar | 115 | } |
116 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 117 | } |
118 | } else { |
||
192 | daniel-mar | 119 | $title = $this->getTitle(); |
120 | |||
360 | daniel-mar | 121 | $content = '<h2>'._L('Description').'</h2>%%DESC%%'; // TODO: add more meta information about the object type |
2 | daniel-mar | 122 | |
16 | daniel-mar | 123 | if (!$this->isLeafNode()) { |
124 | if ($this->userHasWriteRights()) { |
||
360 | daniel-mar | 125 | $content .= '<h2>'._L('Create or change subsequent objects').'</h2>'; |
16 | daniel-mar | 126 | } else { |
360 | daniel-mar | 127 | $content .= '<h2>'._L('Subsequent objects').'</h2>'; |
16 | daniel-mar | 128 | } |
129 | $content .= '%%CRUD%%'; |
||
2 | daniel-mar | 130 | } |
131 | } |
||
132 | } |
||
20 | daniel-mar | 133 | |
134 | public function one_up() { |
||
38 | daniel-mar | 135 | $oid = $this->other; |
136 | |||
137 | $p = strrpos($oid, '\\'); |
||
138 | if ($p === false) return $oid; |
||
139 | if ($p == 0) return '\\'; |
||
140 | |||
141 | $oid_up = substr($oid, 0, $p); |
||
142 | |||
143 | return self::parse(self::ns().':'.$oid_up); |
||
20 | daniel-mar | 144 | } |
145 | |||
146 | public function distance($to) { |
||
38 | daniel-mar | 147 | if (!is_object($to)) $to = OIDplusObject::parse($to); |
148 | if (!($to instanceof $this)) return false; |
||
149 | |||
150 | $a = $to->other; |
||
151 | $b = $this->other; |
||
152 | |||
153 | if (substr($a,0,1) == '\\') $a = substr($a,1); |
||
154 | if (substr($b,0,1) == '\\') $b = substr($b,1); |
||
155 | |||
156 | $ary = explode('\\', $a); |
||
157 | $bry = explode('\\', $b); |
||
158 | |||
159 | $min_len = min(count($ary), count($bry)); |
||
160 | |||
161 | for ($i=0; $i<$min_len; $i++) { |
||
162 | if ($ary[$i] != $bry[$i]) return false; |
||
163 | } |
||
164 | |||
165 | return count($ary) - count($bry); |
||
20 | daniel-mar | 166 | } |
360 | daniel-mar | 167 | } |