Subversion Repositories oidplus

Rev

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