Passed
Push — cirework ( 7349fb...97b46e )
by Richard
04:26
created

XoopsConfigItem::getConfOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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       XOOPS Project (http://xoops.org)
13
 * @license         GNU GPL 2 or later (http://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
 * @version         $Id$
18
 */
19
20
namespace Xoops\Core\Kernel\Handlers;
21
22
use Xoops\Core\Kernel\Dtype;
23
use Xoops\Core\Kernel\XoopsObject;
24
25
/**
26
 * deprecated
27
 * Config type
28
 */
29
define('XOOPS_CONF', 1);
30
define('XOOPS_CONF_USER', 2);
31
define('XOOPS_CONF_METAFOOTER', 3);
32
define('XOOPS_CONF_CENSOR', 4);
33
define('XOOPS_CONF_SEARCH', 5);
34
define('XOOPS_CONF_MAILER', 6);
35
define('XOOPS_CONF_AUTH', 7);
36
37
/**
38
 * Configuration Item
39
 *
40
 * @category  Xoops\Core\Kernel\Handlers\XoopsConfigItem
41
 * @package   Xoops\Core\Kernel
42
 * @author    Kazumi Ono    <[email protected]>
43
 * @copyright 2000-2015 XOOPS Project (http://xoops.org)
44
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
45
 * @link      http://xoops.org
46
 */
47
class XoopsConfigItem extends XoopsObject
48
{
49
50
    /**
51
     * Config options
52
     *
53
     * @var    array
54
     */
55
    private $configurationOptions = array();
56
57
    /**
58
     * Constructor
59
     */
60 22
    public function __construct()
61
    {
62 22
        $this->initVar('conf_id', Dtype::TYPE_INTEGER, null, false);
63 22
        $this->initVar('conf_modid', Dtype::TYPE_INTEGER, null, false);
64 22
        $this->initVar('conf_catid', Dtype::TYPE_INTEGER, null, false);
65 22
        $this->initVar('conf_name', Dtype::TYPE_OTHER);
66 22
        $this->initVar('conf_title', Dtype::TYPE_TEXT_BOX);
67 22
        $this->initVar('conf_value', Dtype::TYPE_TEXT_AREA);
68 22
        $this->initVar('conf_desc', Dtype::TYPE_OTHER);
69 22
        $this->initVar('conf_formtype', Dtype::TYPE_OTHER);
70 22
        $this->initVar('conf_valuetype', Dtype::TYPE_OTHER);
71 22
        $this->initVar('conf_order', Dtype::TYPE_INTEGER);
72 22
    }
73
74
    /**
75
     * getter
76
     *
77
     * @param string $format Dtype::FORMAT_xxxx constant
78
     *
79
     * @return mixed
80
     */
81 1
    public function id($format = Dtype::FORMAT_NONE)
82
    {
83 1
        return $this->getVar('conf_id', $format);
84
    }
85
86
    /**
87
     * getter
88
     *
89
     * @param string $format Dtype::FORMAT_xxxx constant
90
     *
91
     * @return mixed
92
     */
93 1
    public function conf_id($format = '')
94
    {
95 1
        return $this->getVar('conf_id', $format);
96
    }
97
98
    /**
99
     * getter
100
     *
101
     * @param string $format Dtype::FORMAT_xxxx constant
102
     *
103
     * @return mixed
104
     */
105 1
    public function conf_modid($format = '')
106
    {
107 1
        return $this->getVar('conf_modid', $format);
108
    }
109
110
    /**
111
     * getter
112
     *
113
     * @param string $format Dtype::FORMAT_xxxx constant
114
     *
115
     * @return mixed
116
     */
117 1
    public function conf_catid($format = '')
118
    {
119 1
        return $this->getVar('conf_catid', $format);
120
    }
121
122
    /**
123
     * getter
124
     *
125
     * @param string $format Dtype::FORMAT_xxxx constant
126
     *
127
     * @return mixed
128
     */
129 1
    public function conf_name($format = '')
130
    {
131 1
        return $this->getVar('conf_name', $format);
132
    }
133
134
    /**
135
     * getter
136
     *
137
     * @param string $format Dtype::FORMAT_xxxx constant
138
     *
139
     * @return mixed
140
     */
141 1
    public function conf_title($format = '')
142
    {
143 1
        return $this->getVar('conf_title', $format);
144
    }
145
146
    /**
147
     * getter
148
     *
149
     * @param string $format Dtype::FORMAT_xxxx constant
150
     *
151
     * @return mixed
152
     */
153 1
    public function conf_value($format = '')
154
    {
155 1
        return $this->getVar('conf_value', $format);
156
    }
157
158
    /**
159
     * getter
160
     *
161
     * @param string $format Dtype::FORMAT_xxxx constant
162
     *
163
     * @return mixed
164
     */
165 1
    public function conf_desc($format = '')
166
    {
167 1
        return $this->getVar('conf_desc', $format);
168
    }
169
170
    /**
171
     * getter
172
     *
173
     * @param string $format Dtype::FORMAT_xxxx constant
174
     *
175
     * @return mixed
176
     */
177 1
    public function conf_formtype($format = '')
178
    {
179 1
        return $this->getVar('conf_formtype', $format);
180
    }
181
182
    /**
183
     * getter
184
     *
185
     * @param string $format Dtype::FORMAT_xxxx constant
186
     *
187
     * @return mixed
188
     */
189 1
    public function conf_valuetype($format = '')
190
    {
191 1
        return $this->getVar('conf_valuetype', $format);
192
    }
193
194
    /**
195
     * getter
196
     *
197
     * @param string $format Dtype::FORMAT_xxxx constant
198
     *
199
     * @return mixed
200
     */
201 1
    public function conf_order($format = '')
202
    {
203 1
        return $this->getVar('conf_order', $format);
204
    }
205
206
    /**
207
     * Get a config value in a format ready for output
208
     *
209
     * @return    string
210
     */
211 1
    public function getConfValueForOutput()
212
    {
213 1
        switch ($this->getVar('conf_valuetype')) {
214 1
            case 'int':
215 1
                return (int)($this->getVar('conf_value', 'n'));
216
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
217 1
            case 'array':
218 1
                $value = @unserialize($this->getVar('conf_value', 'n'));
219 1
                return $value ? $value : array();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value ? $value : array() also could return the type array which is incompatible with the documented return type string.
Loading history...
220 1
            case 'float':
221
                $value = $this->getVar('conf_value', 'n');
222
                return (float)$value;
223
                break;
224 1
            case 'textarea':
225
                return $this->getVar('conf_value');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getVar('conf_value') also could return the type array which is incompatible with the documented return type string.
Loading history...
226
            default:
227 1
                return $this->getVar('conf_value', 'n');
228
                break;
229
        }
230
    }
231
232
    /**
233
     * Set a config value
234
     *
235
     * @param mixed $value       Value by reference
236
     *
237
     * @return void
238
     */
239
    public function setConfValueForInput(&$value)
240
    {
241
        switch ($this->getVar('conf_valuetype')) {
242
            case 'array':
243
                if (!is_array($value)) {
244
                    $value = explode('|', trim($value));
245
                }
246
                $this->setVar('conf_value', serialize($value));
247
                break;
248
            case 'text':
249
                $this->setVar('conf_value', trim($value));
250
                break;
251
            default:
252
                $this->setVar('conf_value', $value);
253
                break;
254
        }
255
    }
256
257
    /**
258
     * Assign one or more configuration options
259
     *
260
     * @param XoopsConfigOption|XoopsConfigOption[] $option configuration option(s)
261
     *
262
     * @return void
263
     */
264 1
    public function setConfOptions($option)
265
    {
266 1
        if (is_array($option)) {
267 1
            $count = count($option);
268 1
            for ($i = 0; $i < $count; ++$i) {
269
                $this->setConfOptions($option[$i]);
270
            }
271
        } else {
272
            if (is_object($option)) {
273
                $this->configurationOptions[] = $option;
274
            }
275
        }
276 1
    }
277
278
    /**
279
     * Get the configuration options for this item
280
     *
281
     * @return XoopsConfigOption[]
282
     */
283 3
    public function getConfOptions()
284
    {
285 3
        return $this->configurationOptions;
286
    }
287
288
    /**
289
     * Clear options from this item
290
     *
291
     * @return void
292
     **/
293
    public function clearConfOptions()
294
    {
295
        $this->configurationOptions = array();
296
    }
297
}
298