|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* XOOPS form element |
|
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-2017 XOOPS Project (www.xoops.org) |
|
13
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) |
|
14
|
|
|
* @package kernel |
|
15
|
|
|
* @subpackage form |
|
16
|
|
|
* @since 2.0.0 |
|
17
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* A group of form elements |
|
24
|
|
|
*/ |
|
25
|
|
|
class XoopsFormElementTray extends XoopsFormElement |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* array of form element objects |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
* @access private |
|
32
|
|
|
*/ |
|
33
|
|
|
private $_elements = array(); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* required elements |
|
37
|
|
|
* |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
public $_required = array(); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* HTML to seperate the elements |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
* @access private |
|
47
|
|
|
*/ |
|
48
|
|
|
private $_delimeter; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* constructor |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $caption Caption for the group. |
|
54
|
|
|
* @param string $delimeter HTML to separate the elements |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
* |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct($caption, $delimeter = ' ', $name = '') |
|
59
|
|
|
{ |
|
60
|
|
|
$this->setName($name); |
|
61
|
|
|
$this->setCaption($caption); |
|
62
|
|
|
$this->_delimeter = $delimeter; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Is this element a container of other elements? |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool true |
|
69
|
|
|
*/ |
|
70
|
|
|
public function isContainer() |
|
71
|
|
|
{ |
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Find out if there are required elements. |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
|
|
public function isRequired() |
|
81
|
|
|
{ |
|
82
|
|
|
return !empty($this->_required); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Add an element to the group |
|
87
|
|
|
* |
|
88
|
|
|
* @param XoopsFormElement $formElement {@link XoopsFormElement} to add |
|
89
|
|
|
* @param bool $required |
|
90
|
|
|
* |
|
91
|
|
|
*/ |
|
92
|
|
|
public function addElement(XoopsFormElement $formElement, $required = false) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->_elements[] = $formElement; |
|
95
|
|
View Code Duplication |
if (!$formElement->isContainer()) { |
|
96
|
|
|
if ($required) { |
|
97
|
|
|
$formElement->_required = true; |
|
98
|
|
|
$this->_required[] = $formElement; |
|
99
|
|
|
} |
|
100
|
|
|
} else { |
|
101
|
|
|
$required_elements = $formElement->getRequired(); |
|
|
|
|
|
|
102
|
|
|
$count = count($required_elements); |
|
103
|
|
|
for ($i = 0; $i < $count; ++$i) { |
|
104
|
|
|
$this->_required[] = &$required_elements[$i]; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* get an array of "required" form elements |
|
111
|
|
|
* |
|
112
|
|
|
* @return array array of {@link XoopsFormElement}s |
|
113
|
|
|
*/ |
|
114
|
|
|
public function &getRequired() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->_required; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get an array of the elements in this group |
|
121
|
|
|
* |
|
122
|
|
|
* @param bool $recurse get elements recursively? |
|
123
|
|
|
* @return array Array of {@link XoopsFormElement} objects. |
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
public function &getElements($recurse = false) |
|
126
|
|
|
{ |
|
127
|
|
|
if (!$recurse) { |
|
128
|
|
|
return $this->_elements; |
|
129
|
|
|
} else { |
|
130
|
|
|
$ret = array(); |
|
131
|
|
|
$count = count($this->_elements); |
|
132
|
|
|
for ($i = 0; $i < $count; ++$i) { |
|
133
|
|
|
if (!$this->_elements[$i]->isContainer()) { |
|
134
|
|
|
$ret[] = &$this->_elements[$i]; |
|
135
|
|
|
} else { |
|
136
|
|
|
$elements = &$this->_elements[$i]->getElements(true); |
|
137
|
|
|
$count2 = count($elements); |
|
138
|
|
|
for ($j = 0; $j < $count2; ++$j) { |
|
139
|
|
|
$ret[] = &$elements[$j]; |
|
140
|
|
|
} |
|
141
|
|
|
unset($elements); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return $ret; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Get the delimiter of this group |
|
151
|
|
|
* |
|
152
|
|
|
* @param bool $encode To sanitizer the text? |
|
153
|
|
|
* @return string The delimiter |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getDelimeter($encode = false) |
|
156
|
|
|
{ |
|
157
|
|
|
return $encode ? htmlspecialchars(str_replace(' ', ' ', $this->_delimeter)) : $this->_delimeter; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* prepare HTML to output this group |
|
162
|
|
|
* |
|
163
|
|
|
* @return string HTML output |
|
164
|
|
|
*/ |
|
165
|
|
|
public function render() |
|
166
|
|
|
{ |
|
167
|
|
|
return XoopsFormRenderer::getInstance()->get()->renderFormElementTray($this); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.