1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XOOPS Kernel Class |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14
|
|
|
* @package kernel |
15
|
|
|
* @since 2.0.0 |
16
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
17
|
|
|
*/ |
18
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A category of configs |
22
|
|
|
* |
23
|
|
|
* @author Kazumi Ono <[email protected]> |
24
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
25
|
|
|
* |
26
|
|
|
* @package kernel |
27
|
|
|
*/ |
28
|
|
|
class XoopsConfigCategory extends XoopsObject |
29
|
|
|
{ |
30
|
|
|
//PHP 8.2 Dynamic properties deprecated |
31
|
|
|
public $confcat_id; |
32
|
|
|
public $confcat_name; |
33
|
|
|
public $confcat_order; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
$this->initVar('confcat_id', XOBJ_DTYPE_INT, null); |
43
|
|
|
$this->initVar('confcat_name', XOBJ_DTYPE_OTHER, null); |
44
|
|
|
$this->initVar('confcat_order', XOBJ_DTYPE_INT, 0); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns Class Base Variable confcat_id |
49
|
|
|
* @param string $format |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
public function id($format = 'N') |
53
|
|
|
{ |
54
|
|
|
return $this->getVar('confcat_id', $format); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns Class Base Variable confcat_id |
59
|
|
|
* @param string $format |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function confcat_id($format = '') |
63
|
|
|
{ |
64
|
|
|
return $this->getVar('confcat_id', $format); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns Class Base Variable confcat_name |
69
|
|
|
* @param string $format |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function confcat_name($format = '') |
73
|
|
|
{ |
74
|
|
|
return $this->getVar('confcat_name', $format); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns Class Base Variable confcat_order |
79
|
|
|
* @param string $format |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
|
|
public function confcat_order($format = '') |
83
|
|
|
{ |
84
|
|
|
return $this->getVar('confcat_order', $format); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* XOOPS configuration category handler class. |
90
|
|
|
* |
91
|
|
|
* This class is responsible for providing data access mechanisms to the data source |
92
|
|
|
* of XOOPS configuration category class objects. |
93
|
|
|
* |
94
|
|
|
* @author Kazumi Ono <[email protected]> |
95
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
96
|
|
|
* |
97
|
|
|
* @package kernel |
98
|
|
|
* @subpackage config |
99
|
|
|
*/ |
100
|
|
|
class XoopsConfigCategoryHandler extends XoopsObjectHandler |
101
|
|
|
{ |
102
|
|
|
/** |
103
|
|
|
* Create a new category |
104
|
|
|
* |
105
|
|
|
* @param bool $isNew Flag the new object as "new"? |
106
|
|
|
* |
107
|
|
|
* @return XoopsConfigCategory New {@link XoopsConfigCategory} |
108
|
|
|
*/ |
109
|
|
|
public function create($isNew = true) |
110
|
|
|
{ |
111
|
|
|
$confcat = new XoopsConfigCategory(); |
112
|
|
|
if ($isNew) { |
113
|
|
|
$confcat->setNew(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $confcat; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Retrieve a {@link XoopsConfigCategory} |
121
|
|
|
* |
122
|
|
|
* @param int $id ID |
123
|
|
|
* |
124
|
|
|
* @return XoopsConfigCategory|false {@link XoopsConfigCategory}, false on fail |
125
|
|
|
*/ |
126
|
|
|
public function get($id) |
127
|
|
|
{ |
128
|
|
|
$confcat = false; |
129
|
|
|
$id = (int)$id; |
130
|
|
|
if ($id > 0) { |
131
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('configcategory') . ' WHERE confcat_id=' . $id; |
132
|
|
|
$result = $this->db->query($sql); |
|
|
|
|
133
|
|
|
if (!$this->db->isResultSet($result)) { |
134
|
|
|
return $confcat; |
135
|
|
|
} |
136
|
|
|
$numrows = $this->db->getRowsNum($result); |
|
|
|
|
137
|
|
|
if ($numrows == 1) { |
138
|
|
|
$confcat = new XoopsConfigCategory(); |
139
|
|
|
$confcat->assignVars($this->db->fetchArray($result)); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $confcat; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Store a {@link XoopsConfigCategory} |
148
|
|
|
* |
149
|
|
|
* @param XoopsObject|XoopsConfigCategory $confcat a XoopsConfigCategory object |
150
|
|
|
* |
151
|
|
|
* @return bool true on success, otherwise false |
152
|
|
|
*/ |
153
|
|
|
public function insert(XoopsObject $confcat) |
154
|
|
|
{ |
155
|
|
|
$className = 'XoopsConfigCategory'; |
156
|
|
|
if (!($confcat instanceof $className)) { |
157
|
|
|
return false; |
158
|
|
|
} |
159
|
|
|
if (!$confcat->isDirty()) { |
160
|
|
|
return true; |
161
|
|
|
} |
162
|
|
|
if (!$confcat->cleanVars()) { |
163
|
|
|
return false; |
164
|
|
|
} |
165
|
|
|
foreach ($confcat->cleanVars as $k => $v) { |
166
|
|
|
${$k} = $v; |
167
|
|
|
} |
168
|
|
|
if ($confcat->isNew()) { |
169
|
|
|
$confcat_id = $this->db->genId('configcategory_confcat_id_seq'); |
|
|
|
|
170
|
|
|
$sql = sprintf('INSERT INTO %s (confcat_id, confcat_name, confcat_order) VALUES (%u, %s, %u)', $this->db->prefix('configcategory'), $confcat_id, $this->db->quoteString($confcat_name), $confcat_order); |
|
|
|
|
171
|
|
|
} else { |
172
|
|
|
$sql = sprintf('UPDATE %s SET confcat_name = %s, confcat_order = %u WHERE confcat_id = %u', $this->db->prefix('configcategory'), $this->db->quoteString($confcat_name), $confcat_order, $confcat_id); |
|
|
|
|
173
|
|
|
} |
174
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
if (empty($confcat_id)) { |
178
|
|
|
$confcat_id = $this->db->getInsertId(); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
$confcat->assignVar('confcat_id', $confcat_id); |
181
|
|
|
|
182
|
|
|
return $confcat_id; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Delete a {@link XoopsConfigCategory} |
187
|
|
|
* |
188
|
|
|
* @param XoopsObject|XoopsConfigCategory $confcat a XoopsConfigCategory object |
189
|
|
|
* |
190
|
|
|
* @return bool true on success, otherwise false |
191
|
|
|
*/ |
192
|
|
|
public function delete(XoopsObject $confcat) |
193
|
|
|
{ |
194
|
|
|
$className = 'XoopsConfigCategory'; |
195
|
|
|
if (!($confcat instanceof $className)) { |
196
|
|
|
return false; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$sql = sprintf('DELETE FROM %s WHERE confcat_id = %u', $this->db->prefix('configcategory'), $confcat->getVar('confcat_id')); |
|
|
|
|
200
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
201
|
|
|
return false; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return true; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get some {@link XoopsConfigCategory}s |
209
|
|
|
* |
210
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} |
211
|
|
|
* @param bool $id_as_key Use the IDs as keys to the array? |
212
|
|
|
* |
213
|
|
|
* @return array Array of {@link XoopsConfigCategory}s |
214
|
|
|
*/ |
215
|
|
|
public function getObjects(CriteriaElement $criteria = null, $id_as_key = false) |
216
|
|
|
{ |
217
|
|
|
$ret = array(); |
218
|
|
|
$limit = $start = 0; |
219
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('configcategory'); |
220
|
|
|
if (isset($criteria) && \method_exists($criteria, 'renderWhere')) { |
221
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
222
|
|
|
$sort = !in_array($criteria->getSort(), array( |
223
|
|
|
'confcat_id', |
224
|
|
|
'confcat_name', |
225
|
|
|
'confcat_order')) ? 'confcat_order' : $criteria->getSort(); |
226
|
|
|
$sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder(); |
227
|
|
|
$limit = $criteria->getLimit(); |
228
|
|
|
$start = $criteria->getStart(); |
229
|
|
|
} |
230
|
|
|
$result = $this->db->query($sql, $limit, $start); |
231
|
|
|
if (!$this->db->isResultSet($result)) { |
232
|
|
|
return $ret; |
233
|
|
|
} |
234
|
|
|
/** @var array $myrow */ |
235
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
236
|
|
|
$confcat = new XoopsConfigCategory(); |
237
|
|
|
$confcat->assignVars($myrow); |
238
|
|
|
if (!$id_as_key) { |
239
|
|
|
$ret[] =& $confcat; |
240
|
|
|
} else { |
241
|
|
|
$ret[$myrow['confcat_id']] = &$confcat; |
242
|
|
|
} |
243
|
|
|
unset($confcat); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
return $ret; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/**#@+ |
250
|
|
|
* @deprecated |
251
|
|
|
* @param int $modid |
252
|
|
|
* @return bool |
253
|
|
|
*/ |
254
|
|
|
public function getCatByModule($modid = 0) |
|
|
|
|
255
|
|
|
{ |
256
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated'); |
257
|
|
|
|
258
|
|
|
return false; |
259
|
|
|
} |
260
|
|
|
/**#@-*/ |
261
|
|
|
} |
262
|
|
|
|