1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Xoops\Core\ObjectTree; |
4
|
|
|
use Xoops\Form\Select; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
You may not change or alter any portion of this comment or credits |
8
|
|
|
of supporting developers from this source code or any supporting source code |
9
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
10
|
|
|
|
11
|
|
|
This program is distributed in the hope that it will be useful, |
12
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* XOOPS tree class |
18
|
|
|
* |
19
|
|
|
* @copyright 2000-2019 XOOPS Project (https://xoops.org) |
20
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
21
|
|
|
* @since 2.0.0 |
22
|
|
|
* @author Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/) |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* A tree structures with {@link XoopsObject}s as nodes |
27
|
|
|
* |
28
|
|
|
* @package Kernel |
29
|
|
|
* @subpackage Core |
30
|
|
|
* @author Kazumi Ono <[email protected]> |
31
|
|
|
* |
32
|
|
|
* @property-read array $_tree direct access to tree (deprecated) |
33
|
|
|
*/ |
34
|
|
|
class XoopsObjectTree extends ObjectTree |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param XoopsObject[] $objectArr array of XoopsObject that form the tree |
40
|
|
|
* @param string $myId field name of the ID for each object |
41
|
|
|
* @param string $parentId field name of the ID in each object of parent object |
42
|
|
|
* @param string|null $rootId optional field name of the root object ID, |
43
|
|
|
* i.e. the top comment in a series of nested comments |
44
|
|
|
*/ |
45
|
|
|
public function __construct($objectArr, $myId, $parentId, $rootId = null) |
46
|
|
|
{ |
47
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
48
|
|
|
\Xoops::getInstance()->deprecated( |
49
|
|
|
"XoopsObjectTree is deprecated, please use Xoops\\Core\\ObjectTree, " . |
50
|
|
|
"accessed from {$trace[0]['file']} line {$trace[0]['line']}," |
51
|
|
|
); |
52
|
|
|
parent::__construct($objectArr, $myId, $parentId, $rootId); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Make options for a select box from |
59
|
|
|
* |
60
|
|
|
* @param string $fieldName Name of the member variable from the |
61
|
|
|
* node objects that should be used as the title for the options. |
62
|
|
|
* @param string $selected Value to display as selected |
63
|
|
|
* @param int $key ID of the object to display as the root of select options |
64
|
|
|
* @param string $ret (reference to a string when called from outside) Result from previous recursions |
65
|
|
|
* @param string $prefix_orig String to indent items at deeper levels |
66
|
|
|
* @param string $prefix_curr String to indent the current item |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
* @deprecated since 2.5.9, please use makeSelectElement() functionality |
70
|
|
|
*/ |
71
|
|
|
protected function makeSelBoxOptions($fieldName, $selected, $key, &$ret, $prefix_orig, $prefix_curr = '') |
72
|
|
|
{ |
73
|
|
|
if ($key > 0) { |
74
|
|
|
$value = $this->tree[$key]['obj']->getVar($this->myId); |
75
|
|
|
$ret .= '<option value="' . $value . '"'; |
76
|
|
|
if ($value == $selected) { |
77
|
|
|
$ret .= ' selected'; |
78
|
|
|
} |
79
|
|
|
$ret .= '>' . $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName) . '</option>'; |
80
|
|
|
$prefix_curr .= $prefix_orig; |
81
|
|
|
} |
82
|
|
|
if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) { |
83
|
|
|
foreach ($this->tree[$key]['child'] as $childKey) { |
84
|
|
|
$this->makeSelBoxOptions($fieldName, $selected, $childKey, $ret, $prefix_orig, $prefix_curr); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Make a select box with options from the tree |
91
|
|
|
* |
92
|
|
|
* @param string $name Name of the select box |
93
|
|
|
* @param string $fieldName Name of the member variable from the |
94
|
|
|
* node objects that should be used as the title for the options. |
95
|
|
|
* @param string $prefix String to indent deeper levels |
96
|
|
|
* @param string $selected Value to display as selected |
97
|
|
|
* @param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
98
|
|
|
* @param integer $key ID of the object to display as the root of select options |
99
|
|
|
* @param string $extra extra content to add to the element |
100
|
|
|
* @return string HTML select box |
101
|
|
|
* |
102
|
|
|
* @deprecated since 2.5.9, please use makeSelectElement() |
103
|
|
|
*/ |
104
|
|
|
public function makeSelBox( |
105
|
|
|
$name, |
106
|
|
|
$fieldName, |
107
|
|
|
$prefix = '-', |
108
|
|
|
$selected = '', |
109
|
|
|
$addEmptyOption = false, |
110
|
|
|
$key = 0, |
111
|
|
|
$extra = '' |
112
|
|
|
) { |
113
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
114
|
|
|
\Xoops::getInstance()->deprecated( |
115
|
|
|
"makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), " . |
116
|
|
|
"accessed from {$trace[0]['file']} line {$trace[0]['line']}," |
117
|
|
|
); |
118
|
|
|
$ret = '<select name="' . $name . '" id="' . $name . '" ' . $extra . '>'; |
119
|
|
|
if (false !== (bool)$addEmptyOption) { |
120
|
|
|
$ret .= '<option value="0"></option>'; |
121
|
|
|
} |
122
|
|
|
$this->makeSelBoxOptions($fieldName, $selected, $key, $ret, $prefix); |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $ret . '</select>'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Make a select box with options from the tree |
129
|
|
|
* |
130
|
|
|
* @param string $name Name of the select box |
131
|
|
|
* @param string $fieldName Name of the member variable from the |
132
|
|
|
* node objects that should be used as the title for the options. |
133
|
|
|
* @param string $prefix String to indent deeper levels |
134
|
|
|
* @param string $selected Value to display as selected |
135
|
|
|
* @param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
136
|
|
|
* @param integer $key ID of the object to display as the root of select options |
137
|
|
|
* @param string $extra extra content to add to the element |
138
|
|
|
* @param string $caption optional caption for form element |
139
|
|
|
* |
140
|
|
|
* @return Select form element |
141
|
|
|
* |
142
|
|
|
* @deprecated use Xoops\Core\ObjectTree::makeSelect() |
143
|
|
|
*/ |
144
|
|
|
public function makeSelectElement( |
145
|
|
|
$name, |
146
|
|
|
$fieldName, |
147
|
|
|
$prefix = '-', |
148
|
|
|
$selected = '', |
149
|
|
|
$addEmptyOption = false, |
150
|
|
|
$key = 0, |
151
|
|
|
$extra = '', |
152
|
|
|
$caption = '' |
153
|
|
|
) { |
154
|
|
|
$element = new Select($caption, $name, $selected); |
155
|
|
|
$element->setExtra($extra); |
|
|
|
|
156
|
|
|
|
157
|
|
|
if (false !== (bool)$addEmptyOption) { |
158
|
|
|
$element->addOption('0', ' '); |
159
|
|
|
} |
160
|
|
|
$this->addSelectOptions($element, $fieldName, $key, $prefix); |
161
|
|
|
|
162
|
|
|
return $element; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Magic __get method |
167
|
|
|
* |
168
|
|
|
* Some modules did not respect the leading underscore is private convention and broke |
169
|
|
|
* when code was modernized. This will keep them running for now. |
170
|
|
|
* |
171
|
|
|
* @param string $name unknown variable name requested |
172
|
|
|
* currently only '_tree' is supported |
173
|
|
|
* |
174
|
|
|
* @return mixed value |
175
|
|
|
*/ |
176
|
|
|
public function __get($name) |
177
|
|
|
{ |
178
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
179
|
|
|
if ($name === '_tree') { |
180
|
|
|
\Xoops::getInstance()->deprecated( |
181
|
|
|
"XoopsObjectTree::\$_tree is deprecated since 2.5.9, please use makeSelectElement(), " . |
182
|
|
|
"accessed from {$trace[0]['file']} line {$trace[0]['line']}," |
183
|
|
|
); |
184
|
|
|
return $this->tree; |
185
|
|
|
} |
186
|
|
|
trigger_error( |
187
|
|
|
'Undefined property: XoopsObjectTree::$' . $name . |
188
|
|
|
" in {$trace[0]['file']} line {$trace[0]['line']}, ", |
189
|
|
|
E_USER_NOTICE); |
190
|
|
|
return null; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.