|
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 Config-Option |
|
22
|
|
|
* |
|
23
|
|
|
* @author Kazumi Ono <[email protected]> |
|
24
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
25
|
|
|
* |
|
26
|
|
|
* @package kernel |
|
27
|
|
|
*/ |
|
28
|
|
|
class XoopsConfigOption extends XoopsObject |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Constructor |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct(); |
|
36
|
|
|
$this->initVar('confop_id', XOBJ_DTYPE_INT, null); |
|
37
|
|
|
$this->initVar('confop_name', XOBJ_DTYPE_TXTBOX, null, true, 255); |
|
38
|
|
|
$this->initVar('confop_value', XOBJ_DTYPE_TXTBOX, null, true, 255); |
|
39
|
|
|
$this->initVar('conf_id', XOBJ_DTYPE_INT, 0); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns Class Base Variable confop_id |
|
44
|
|
|
* @param string $format |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
public function id($format = 'N') |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->getVar('confop_id', $format); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns Class Base Variable confop_id |
|
54
|
|
|
* @param string $format |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
|
|
public function confop_id($format = '') |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getVar('confop_id', $format); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns Class Base Variable confop_name |
|
64
|
|
|
* @param string $format |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
|
|
public function confop_name($format = '') |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->getVar('confop_name', $format); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns Class Base Variable confop_value |
|
74
|
|
|
* @param string $format |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function confop_value($format = '') |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getVar('confop_value', $format); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns Class Base Variable conf_id |
|
84
|
|
|
* @param string $format |
|
85
|
|
|
* @return mixed |
|
86
|
|
|
*/ |
|
87
|
|
|
public function conf_id($format = '') |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getVar('conf_id', $format); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* XOOPS configuration option handler class. |
|
95
|
|
|
* This class is responsible for providing data access mechanisms to the data source |
|
96
|
|
|
* of XOOPS configuration option class objects. |
|
97
|
|
|
* |
|
98
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
99
|
|
|
* @author Kazumi Ono <[email protected]> |
|
100
|
|
|
* |
|
101
|
|
|
* @package kernel |
|
102
|
|
|
* @subpackage config |
|
103
|
|
|
*/ |
|
104
|
|
|
class XoopsConfigOptionHandler extends XoopsObjectHandler |
|
105
|
|
|
{ |
|
106
|
|
|
/** |
|
107
|
|
|
* Create a new option |
|
108
|
|
|
* |
|
109
|
|
|
* @param bool $isNew Flag the option as "new"? |
|
110
|
|
|
* |
|
111
|
|
|
* @return XoopsConfigOption {@link XoopsConfigOption} |
|
112
|
|
|
*/ |
|
113
|
|
|
public function create($isNew = true) |
|
114
|
|
|
{ |
|
115
|
|
|
$confoption = new XoopsConfigOption(); |
|
116
|
|
|
if ($isNew) { |
|
117
|
|
|
$confoption->setNew(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $confoption; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get an option from the database |
|
125
|
|
|
* |
|
126
|
|
|
* @param int $id ID of the option |
|
127
|
|
|
* |
|
128
|
|
|
* @return XoopsConfigOption reference to the {@link XoopsConfigOption}, FALSE on fail |
|
129
|
|
|
*/ |
|
130
|
|
|
public function get($id) |
|
131
|
|
|
{ |
|
132
|
|
|
$confoption = false; |
|
133
|
|
|
$id = (int)$id; |
|
134
|
|
|
if ($id > 0) { |
|
135
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('configoption') . ' WHERE confop_id=' . $id; |
|
136
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
|
|
137
|
|
|
return $confoption; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
$numrows = $this->db->getRowsNum($result); |
|
|
|
|
|
|
140
|
|
|
if ($numrows == 1) { |
|
141
|
|
|
$confoption = new XoopsConfigOption(); |
|
142
|
|
|
$confoption->assignVars($this->db->fetchArray($result)); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $confoption; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Insert a new {@link XoopsConfigOption} |
|
151
|
|
|
* |
|
152
|
|
|
* @param XoopsObject|XoopsConfigOption $confoption a XoopsConfigOption object |
|
153
|
|
|
* |
|
154
|
|
|
* @return bool true on success, otherwise false |
|
155
|
|
|
*/ |
|
156
|
|
|
public function insert(XoopsObject $confoption) |
|
157
|
|
|
{ |
|
158
|
|
|
$className = 'XoopsConfigOption'; |
|
159
|
|
|
if (!($confoption instanceof $className)) { |
|
160
|
|
|
return false; |
|
161
|
|
|
} |
|
162
|
|
|
if (!$confoption->isDirty()) { |
|
163
|
|
|
return true; |
|
164
|
|
|
} |
|
165
|
|
|
if (!$confoption->cleanVars()) { |
|
166
|
|
|
return false; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$confop_id = $confoption->getVar('confop_id'); |
|
170
|
|
|
$confop_name = $confoption->getVar('confop_name'); |
|
171
|
|
|
$confop_value = $confoption->getVar('confop_value'); |
|
172
|
|
|
$conf_id = $confoption->getVar('conf_id'); |
|
173
|
|
|
|
|
174
|
|
|
if ($confoption->isNew()) { |
|
175
|
|
|
$confop_id = $this->db->genId('configoption_confop_id_seq'); |
|
|
|
|
|
|
176
|
|
|
$sql = sprintf( |
|
177
|
|
|
'INSERT INTO %s (confop_id, confop_name, confop_value, conf_id) VALUES (%u, %s, %s, %u)', |
|
178
|
|
|
$this->db->prefix('configoption'), |
|
179
|
|
|
$confop_id, |
|
180
|
|
|
$this->db->quote($confop_name), |
|
|
|
|
|
|
181
|
|
|
$this->db->quote($confop_value), |
|
182
|
|
|
$conf_id |
|
|
|
|
|
|
183
|
|
|
); |
|
184
|
|
|
} else { |
|
185
|
|
|
$sql = sprintf( |
|
186
|
|
|
'UPDATE %s SET confop_name = %s, confop_value = %s WHERE confop_id = %u', |
|
187
|
|
|
$this->db->prefix('configoption'), |
|
188
|
|
|
$this->db->quote($confop_name), |
|
189
|
|
|
$this->db->quote($confop_value), |
|
190
|
|
|
$confop_id |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
|
|
194
|
|
|
return false; |
|
195
|
|
|
} |
|
196
|
|
|
if (empty($confop_id)) { |
|
197
|
|
|
$confop_id = $this->db->getInsertId(); |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
$confoption->assignVar('confop_id', $confop_id); |
|
200
|
|
|
|
|
201
|
|
|
return $confop_id; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Delete a {@link XoopsConfigOption} |
|
206
|
|
|
* |
|
207
|
|
|
* @param XoopsObject|XoopsConfigOption $confoption a XoopsConfigOption object |
|
208
|
|
|
* |
|
209
|
|
|
* @return bool true on success, otherwise false |
|
210
|
|
|
*/ |
|
211
|
|
|
public function delete(XoopsObject $confoption) |
|
212
|
|
|
{ |
|
213
|
|
|
$className = 'XoopsConfigOption'; |
|
214
|
|
|
if (!($confoption instanceof $className)) { |
|
215
|
|
|
return false; |
|
216
|
|
|
} |
|
217
|
|
|
$sql = sprintf('DELETE FROM %s WHERE confop_id = %u', $this->db->prefix('configoption'), $confoption->getVar('confop_id')); |
|
|
|
|
|
|
218
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
|
|
219
|
|
|
return false; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
return true; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Get some {@link XoopsConfigOption}s |
|
227
|
|
|
* |
|
228
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} |
|
229
|
|
|
* @param bool $id_as_key Use the IDs as array-keys? |
|
230
|
|
|
* |
|
231
|
|
|
* @return array Array of {@link XoopsConfigOption}s |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getObjects(CriteriaElement $criteria = null, $id_as_key = false) |
|
234
|
|
|
{ |
|
235
|
|
|
$ret = array(); |
|
236
|
|
|
$limit = $start = 0; |
|
237
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('configoption'); |
|
238
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
239
|
|
|
$sql .= ' ' . $criteria->renderWhere() . ' ORDER BY confop_id ' . $criteria->getOrder(); |
|
|
|
|
|
|
240
|
|
|
$limit = $criteria->getLimit(); |
|
241
|
|
|
$start = $criteria->getStart(); |
|
242
|
|
|
} |
|
243
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
244
|
|
|
if (!$result) { |
|
245
|
|
|
return $ret; |
|
246
|
|
|
} |
|
247
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
248
|
|
|
$confoption = new XoopsConfigOption(); |
|
249
|
|
|
$confoption->assignVars($myrow); |
|
250
|
|
|
if (!$id_as_key) { |
|
251
|
|
|
$ret[] =& $confoption; |
|
252
|
|
|
} else { |
|
253
|
|
|
$ret[$myrow['confop_id']] = &$confoption; |
|
254
|
|
|
} |
|
255
|
|
|
unset($confoption); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return $ret; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* get count of matching configoption rows |
|
263
|
|
|
* |
|
264
|
|
|
* @param CriteriaElement $criteria |
|
265
|
|
|
* |
|
266
|
|
|
* @return int Count of matching XoopsConfigOption |
|
267
|
|
|
*/ |
|
268
|
|
|
public function getCount(CriteriaElement $criteria = null) |
|
269
|
|
|
{ |
|
270
|
|
|
$sql = 'SELECT COUNT(*) as `count` FROM ' . $this->db->prefix('configoption'); |
|
271
|
|
|
if (isset($criteria) && $criteria instanceof \CriteriaElement) { |
|
272
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
|
273
|
|
|
} |
|
274
|
|
|
$result = $this->db->query($sql); |
|
275
|
|
|
$row = $this->db->fetchArray($result); |
|
276
|
|
|
$count = $row['count']; |
|
277
|
|
|
$this->db->freeRecordSet($result); |
|
|
|
|
|
|
278
|
|
|
return (int)$count; |
|
279
|
|
|
} |
|
280
|
|
|
} |
|
281
|
|
|
|