Subversion Repositories oidplus

Rev

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