Subversion Repositories oidplus

Rev

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 OIDplusJava extends OIDplusObject {
21
        private $java;
22
 
2 daniel-mar 23
        public function __construct($java) {
16 daniel-mar 24
                // TODO: syntax checks
2 daniel-mar 25
                $this->java = $java;
26
        }
27
 
28
        public static function parse($node_id) {
29
                @list($namespace, $java) = explode(':', $node_id, 2);
30
                if ($namespace !== 'java') return false;
31
                return new self($java);
32
        }
33
 
34
        public static function objectTypeTitle() {
360 daniel-mar 35
                return _L('Java Package Names');
2 daniel-mar 36
        }
37
 
38
        public static function objectTypeTitleShort() {
360 daniel-mar 39
                return _L('Package');
2 daniel-mar 40
        }
41
 
42
        public static function ns() {
43
                return 'java';
44
        }
45
 
46
        public static function root() {
47
                return 'java:';
48
        }
49
 
50
        public function isRoot() {
51
                return $this->java == '';
52
        }
53
 
247 daniel-mar 54
        public function nodeId($with_ns=true) {
55
                return $with_ns ? 'java:'.$this->java : $this->java;
2 daniel-mar 56
        }
57
 
58
        public function addString($str) {
59
                if ($this->isRoot()) {
60
                        return 'java:'.$str;
61
                } else {
360 daniel-mar 62
                        if (strpos($str,'.') !== false) throw new OIDplusException(_L('Please only submit one arc.'));
2 daniel-mar 63
                        return $this->nodeId() . '.' . $str;
64
                }
65
        }
66
 
67
        public function crudShowId(OIDplusObject $parent) {
68
                return $this->java;
69
        }
70
 
71
        public function crudInsertPrefix() {
72
                return $this->isRoot() ? '' : substr($this->addString(''), strlen(self::ns())+1);
73
        }
74
 
75
        public function jsTreeNodeName(OIDplusObject $parent = null) {
76
                if ($parent == null) return $this->objectTypeTitle();
77
                return $this->java;
78
        }
79
 
80
        public function defaultTitle() {
81
                return $this->java;
82
        }
83
 
16 daniel-mar 84
        public function isLeafNode() {
85
                return false;
86
        }
87
 
34 daniel-mar 88
        public function getContentPage(&$title, &$content, &$icon) {
55 daniel-mar 89
                $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : '';
90
 
2 daniel-mar 91
                if ($this->isRoot()) {
92
                        $title = OIDplusJava::objectTypeTitle();
93
 
261 daniel-mar 94
                        $res = OIDplus::db()->query("select * from ###objects where parent = ?", array(self::root()));
236 daniel-mar 95
                        if ($res->num_rows() > 0) {
360 daniel-mar 96
                                $content  = _L('Please select a Java Package Name in the tree view at the left to show its contents.');
2 daniel-mar 97
                        } else {
360 daniel-mar 98
                                $content  = _L('Currently, no Java Package Name is registered in the system.');
2 daniel-mar 99
                        }
100
 
16 daniel-mar 101
                        if (!$this->isLeafNode()) {
102
                                if (OIDplus::authUtils()::isAdminLoggedIn()) {
360 daniel-mar 103
                                        $content .= '<h2>'._L('Manage root objects').'</h2>';
16 daniel-mar 104
                                } else {
360 daniel-mar 105
                                        $content .= '<h2>'._L('Available objects').'</h2>';
16 daniel-mar 106
                                }
107
                                $content .= '%%CRUD%%';
2 daniel-mar 108
                        }
109
                } else {
192 daniel-mar 110
                        $title = $this->getTitle();
111
 
2 daniel-mar 112
                        $content = '<h3>'.explode(':',$this->nodeId())[1].'</h3>';
113
 
360 daniel-mar 114
                        $content .= '<h2>'._L('Description').'</h2>%%DESC%%'; // TODO: add more meta information about the object type
2 daniel-mar 115
 
16 daniel-mar 116
                        if (!$this->isLeafNode()) {
117
                                if ($this->userHasWriteRights()) {
360 daniel-mar 118
                                        $content .= '<h2>'._L('Create or change subsequent objects').'</h2>';
16 daniel-mar 119
                                } else {
360 daniel-mar 120
                                        $content .= '<h2>'._L('Subsequent objects').'</h2>';
16 daniel-mar 121
                                }
122
                                $content .= '%%CRUD%%';
2 daniel-mar 123
                        }
124
                }
125
        }
20 daniel-mar 126
 
127
        public function one_up() {
36 daniel-mar 128
                $oid = $this->java;
129
 
130
                $p = strrpos($oid, '.');
131
                if ($p === false) return $oid;
132
                if ($p == 0) return '.';
133
 
134
                $oid_up = substr($oid, 0, $p);
135
 
136
                return self::parse(self::ns().':'.$oid_up);
20 daniel-mar 137
        }
138
 
139
        public function distance($to) {
36 daniel-mar 140
                if (!is_object($to)) $to = OIDplusObject::parse($to);
141
                if (!($to instanceof $this)) return false;
142
 
143
                $a = $to->java;
144
                $b = $this->java;
145
 
146
                if (substr($a,0,1) == '.') $a = substr($a,1);
147
                if (substr($b,0,1) == '.') $b = substr($b,1);
148
 
149
                $ary = explode('.', $a);
150
                $bry = explode('.', $b);
151
 
152
                $min_len = min(count($ary), count($bry));
153
 
154
                for ($i=0; $i<$min_len; $i++) {
155
                        if ($ary[$i] != $bry[$i]) return false;
156
                }
157
 
158
                return count($ary) - count($bry);
20 daniel-mar 159
        }
360 daniel-mar 160
}