@@ -51,230 +51,230 @@ |
||
51 | 51 | */ |
52 | 52 | class SelectArtistForm extends \XoopsFormElement |
53 | 53 | { |
54 | - /** |
|
55 | - * Options |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - public $_options = []; |
|
60 | - /** |
|
61 | - * Allow multiple selections? |
|
62 | - * |
|
63 | - * @var bool |
|
64 | - */ |
|
65 | - public $_multiple = false; |
|
66 | - /** |
|
67 | - * Number of rows. "1" makes a dropdown list. |
|
68 | - * |
|
69 | - * @var int |
|
70 | - */ |
|
71 | - public $_size; |
|
72 | - /** |
|
73 | - * Pre-selcted values |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $_value = []; |
|
54 | + /** |
|
55 | + * Options |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + public $_options = []; |
|
60 | + /** |
|
61 | + * Allow multiple selections? |
|
62 | + * |
|
63 | + * @var bool |
|
64 | + */ |
|
65 | + public $_multiple = false; |
|
66 | + /** |
|
67 | + * Number of rows. "1" makes a dropdown list. |
|
68 | + * |
|
69 | + * @var int |
|
70 | + */ |
|
71 | + public $_size; |
|
72 | + /** |
|
73 | + * Pre-selcted values |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $_value = []; |
|
78 | 78 | |
79 | - /** |
|
80 | - * Constructor |
|
81 | - * |
|
82 | - * @param string $caption Caption |
|
83 | - * @param string $name "name" attribute |
|
84 | - * @param mixed $value Pre-selected value (or array of them). |
|
85 | - * @param int $size Number or rows. "1" makes a drop-down-list |
|
86 | - * @param bool $multiple Allow multiple selections? |
|
87 | - * @param int $ownid |
|
88 | - */ |
|
89 | - public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0) |
|
90 | - { |
|
91 | - global $_form_object_options; |
|
92 | - \xoops_loadLanguage('modinfo', 'songlist'); |
|
79 | + /** |
|
80 | + * Constructor |
|
81 | + * |
|
82 | + * @param string $caption Caption |
|
83 | + * @param string $name "name" attribute |
|
84 | + * @param mixed $value Pre-selected value (or array of them). |
|
85 | + * @param int $size Number or rows. "1" makes a drop-down-list |
|
86 | + * @param bool $multiple Allow multiple selections? |
|
87 | + * @param int $ownid |
|
88 | + */ |
|
89 | + public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0) |
|
90 | + { |
|
91 | + global $_form_object_options; |
|
92 | + \xoops_loadLanguage('modinfo', 'songlist'); |
|
93 | 93 | |
94 | - $this->setCaption($caption); |
|
95 | - $this->setName($name); |
|
96 | - $this->_multiple = $multiple; |
|
97 | - $this->_size = (int)$size; |
|
98 | - if (isset($value)) { |
|
99 | - $this->setValue($value); |
|
100 | - } |
|
101 | - $this->addOption('0', \_MI_SONGLIST_NONE); |
|
102 | - if (!isset($_form_object_options['artists'])) { |
|
103 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
104 | - $criteria = new \Criteria(''); |
|
105 | - $criteria->setSort('name'); |
|
106 | - $criteria->setOrder('ASC'); |
|
107 | - foreach ($artistsHandler->getObjects($criteria, true) as $id => $obj) { |
|
108 | - $_form_object_options['artists'][$id] = $obj->getVar('name'); |
|
109 | - } |
|
110 | - } |
|
111 | - // if (Request::hasVar('artists', 'form_object_options')) { |
|
112 | - if (isset($_form_object_options['artists'])) { |
|
113 | - foreach ($_form_object_options['artists'] as $id => $value) { |
|
114 | - $this->addOption($id, $value); |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
94 | + $this->setCaption($caption); |
|
95 | + $this->setName($name); |
|
96 | + $this->_multiple = $multiple; |
|
97 | + $this->_size = (int)$size; |
|
98 | + if (isset($value)) { |
|
99 | + $this->setValue($value); |
|
100 | + } |
|
101 | + $this->addOption('0', \_MI_SONGLIST_NONE); |
|
102 | + if (!isset($_form_object_options['artists'])) { |
|
103 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
104 | + $criteria = new \Criteria(''); |
|
105 | + $criteria->setSort('name'); |
|
106 | + $criteria->setOrder('ASC'); |
|
107 | + foreach ($artistsHandler->getObjects($criteria, true) as $id => $obj) { |
|
108 | + $_form_object_options['artists'][$id] = $obj->getVar('name'); |
|
109 | + } |
|
110 | + } |
|
111 | + // if (Request::hasVar('artists', 'form_object_options')) { |
|
112 | + if (isset($_form_object_options['artists'])) { |
|
113 | + foreach ($_form_object_options['artists'] as $id => $value) { |
|
114 | + $this->addOption($id, $value); |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Are multiple selections allowed? |
|
121 | - * |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - public function isMultiple(): bool |
|
125 | - { |
|
126 | - return $this->_multiple; |
|
127 | - } |
|
119 | + /** |
|
120 | + * Are multiple selections allowed? |
|
121 | + * |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + public function isMultiple(): bool |
|
125 | + { |
|
126 | + return $this->_multiple; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Get the size |
|
131 | - * |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function getSize(): int |
|
135 | - { |
|
136 | - return $this->_size; |
|
137 | - } |
|
129 | + /** |
|
130 | + * Get the size |
|
131 | + * |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function getSize(): int |
|
135 | + { |
|
136 | + return $this->_size; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Get an array of pre-selected values |
|
141 | - * |
|
142 | - * @param bool $encode To sanitizer the text? |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function getValue($encode = false): array |
|
146 | - { |
|
147 | - if (!$encode) { |
|
148 | - return $this->_value; |
|
149 | - } |
|
150 | - $value = []; |
|
151 | - foreach ($this->_value as $val) { |
|
152 | - $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
153 | - } |
|
139 | + /** |
|
140 | + * Get an array of pre-selected values |
|
141 | + * |
|
142 | + * @param bool $encode To sanitizer the text? |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function getValue($encode = false): array |
|
146 | + { |
|
147 | + if (!$encode) { |
|
148 | + return $this->_value; |
|
149 | + } |
|
150 | + $value = []; |
|
151 | + foreach ($this->_value as $val) { |
|
152 | + $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
153 | + } |
|
154 | 154 | |
155 | - return $value; |
|
156 | - } |
|
155 | + return $value; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Set pre-selected values |
|
160 | - * |
|
161 | - * @param mixed $value |
|
162 | - */ |
|
163 | - public function setValue($value): void |
|
164 | - { |
|
165 | - if (\is_array($value)) { |
|
166 | - foreach ($value as $v) { |
|
167 | - $this->_value[] = (int)$v; |
|
168 | - } |
|
158 | + /** |
|
159 | + * Set pre-selected values |
|
160 | + * |
|
161 | + * @param mixed $value |
|
162 | + */ |
|
163 | + public function setValue($value): void |
|
164 | + { |
|
165 | + if (\is_array($value)) { |
|
166 | + foreach ($value as $v) { |
|
167 | + $this->_value[] = (int)$v; |
|
168 | + } |
|
169 | 169 | // $this->_value[] = array_values($value); |
170 | - } elseif (isset($value)) { |
|
171 | - $this->_value[] = $value; |
|
172 | - } |
|
173 | - } |
|
170 | + } elseif (isset($value)) { |
|
171 | + $this->_value[] = $value; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Add an option |
|
177 | - * |
|
178 | - * @param string $value "value" attribute |
|
179 | - * @param string $name "name" attribute |
|
180 | - */ |
|
181 | - public function addOption($value, $name = ''): void |
|
182 | - { |
|
183 | - if ('' != $name) { |
|
184 | - $this->_options[$value] = $name; |
|
185 | - } else { |
|
186 | - $this->_options[$value] = $value; |
|
187 | - } |
|
188 | - } |
|
175 | + /** |
|
176 | + * Add an option |
|
177 | + * |
|
178 | + * @param string $value "value" attribute |
|
179 | + * @param string $name "name" attribute |
|
180 | + */ |
|
181 | + public function addOption($value, $name = ''): void |
|
182 | + { |
|
183 | + if ('' != $name) { |
|
184 | + $this->_options[$value] = $name; |
|
185 | + } else { |
|
186 | + $this->_options[$value] = $value; |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Add multiple options |
|
192 | - * |
|
193 | - * @param array $options Associative array of value->name pairs |
|
194 | - */ |
|
195 | - public function addOptionArray($options): void |
|
196 | - { |
|
197 | - if (\is_array($options)) { |
|
198 | - foreach ($options as $k => $v) { |
|
199 | - $this->addOption($k, $v); |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
190 | + /** |
|
191 | + * Add multiple options |
|
192 | + * |
|
193 | + * @param array $options Associative array of value->name pairs |
|
194 | + */ |
|
195 | + public function addOptionArray($options): void |
|
196 | + { |
|
197 | + if (\is_array($options)) { |
|
198 | + foreach ($options as $k => $v) { |
|
199 | + $this->addOption($k, $v); |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get an array with all the options |
|
206 | - * |
|
207 | - * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
208 | - * |
|
209 | - * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
210 | - * @return array Associative array of value->name pairs |
|
211 | - */ |
|
212 | - public function getOptions($encode = false): array |
|
213 | - { |
|
214 | - if (!$encode) { |
|
215 | - return $this->_options; |
|
216 | - } |
|
217 | - $value = []; |
|
218 | - foreach ($this->_options as $val => $name) { |
|
219 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
220 | - } |
|
204 | + /** |
|
205 | + * Get an array with all the options |
|
206 | + * |
|
207 | + * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
208 | + * |
|
209 | + * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
210 | + * @return array Associative array of value->name pairs |
|
211 | + */ |
|
212 | + public function getOptions($encode = false): array |
|
213 | + { |
|
214 | + if (!$encode) { |
|
215 | + return $this->_options; |
|
216 | + } |
|
217 | + $value = []; |
|
218 | + foreach ($this->_options as $val => $name) { |
|
219 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
220 | + } |
|
221 | 221 | |
222 | - return $value; |
|
223 | - } |
|
222 | + return $value; |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * Prepare HTML for output |
|
227 | - * |
|
228 | - * @return string HTML |
|
229 | - */ |
|
230 | - public function render(): string |
|
231 | - { |
|
232 | - $ele_name = $this->getName(); |
|
233 | - $ele_title = $this->getTitle(); |
|
234 | - $ele_value = $this->getValue(); |
|
235 | - $ele_options = $this->getOptions(); |
|
236 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
237 | - if ($this->isMultiple()) { |
|
238 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
239 | - } else { |
|
240 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
241 | - } |
|
242 | - foreach ($ele_options as $value => $name) { |
|
243 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
244 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
245 | - $ret .= ' selected'; |
|
246 | - } |
|
247 | - $ret .= '>' . $name . '</option>'; |
|
248 | - } |
|
249 | - $ret .= '</select>'; |
|
225 | + /** |
|
226 | + * Prepare HTML for output |
|
227 | + * |
|
228 | + * @return string HTML |
|
229 | + */ |
|
230 | + public function render(): string |
|
231 | + { |
|
232 | + $ele_name = $this->getName(); |
|
233 | + $ele_title = $this->getTitle(); |
|
234 | + $ele_value = $this->getValue(); |
|
235 | + $ele_options = $this->getOptions(); |
|
236 | + $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
237 | + if ($this->isMultiple()) { |
|
238 | + $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
239 | + } else { |
|
240 | + $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
241 | + } |
|
242 | + foreach ($ele_options as $value => $name) { |
|
243 | + $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
244 | + if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
245 | + $ret .= ' selected'; |
|
246 | + } |
|
247 | + $ret .= '>' . $name . '</option>'; |
|
248 | + } |
|
249 | + $ret .= '</select>'; |
|
250 | 250 | |
251 | - return $ret; |
|
252 | - } |
|
251 | + return $ret; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * Render custom javascript validation code |
|
256 | - * |
|
257 | - * @seealso XoopsForm::renderValidationJS |
|
258 | - */ |
|
259 | - public function renderValidationJS() |
|
260 | - { |
|
261 | - // render custom validation code if any |
|
262 | - if (!empty($this->customValidationCode)) { |
|
263 | - return \implode("\n", $this->customValidationCode); |
|
264 | - // generate validation code if required |
|
265 | - } |
|
254 | + /** |
|
255 | + * Render custom javascript validation code |
|
256 | + * |
|
257 | + * @seealso XoopsForm::renderValidationJS |
|
258 | + */ |
|
259 | + public function renderValidationJS() |
|
260 | + { |
|
261 | + // render custom validation code if any |
|
262 | + if (!empty($this->customValidationCode)) { |
|
263 | + return \implode("\n", $this->customValidationCode); |
|
264 | + // generate validation code if required |
|
265 | + } |
|
266 | 266 | |
267 | - if ($this->isRequired()) { |
|
268 | - $eltname = $this->getName(); |
|
269 | - $eltcaption = $this->getCaption(); |
|
270 | - $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
271 | - $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
267 | + if ($this->isRequired()) { |
|
268 | + $eltname = $this->getName(); |
|
269 | + $eltcaption = $this->getCaption(); |
|
270 | + $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
271 | + $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
272 | 272 | |
273 | - return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
274 | - . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
275 | - . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
276 | - } |
|
273 | + return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
274 | + . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
275 | + . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
276 | + } |
|
277 | 277 | |
278 | - return ''; |
|
279 | - } |
|
278 | + return ''; |
|
279 | + } |
|
280 | 280 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $this->setCaption($caption); |
97 | 97 | $this->setName($name); |
98 | 98 | $this->_multiple = $multiple; |
99 | - $this->_size = (int)$size; |
|
99 | + $this->_size = (int) $size; |
|
100 | 100 | if (isset($value)) { |
101 | 101 | $this->setValue($value); |
102 | 102 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | if (\is_array($value)) { |
168 | 168 | foreach ($value as $v) { |
169 | - $this->_value[] = (int)$v; |
|
169 | + $this->_value[] = (int) $v; |
|
170 | 170 | } |
171 | 171 | // $this->_value[] = array_values($value); |
172 | 172 | } elseif (isset($value)) { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function addOption($value, $name = ''): void |
184 | 184 | { |
185 | - if ('' != $name) { |
|
185 | + if (''!=$name) { |
|
186 | 186 | $this->_options[$value] = $name; |
187 | 187 | } else { |
188 | 188 | $this->_options[$value] = $value; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | $value = []; |
220 | 220 | foreach ($this->_options as $val => $name) { |
221 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
221 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $value; |
@@ -235,18 +235,18 @@ discard block |
||
235 | 235 | $ele_title = $this->getTitle(); |
236 | 236 | $ele_value = $this->getValue(); |
237 | 237 | $ele_options = $this->getOptions(); |
238 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
238 | + $ret = '<select size="'.$this->getSize().'"'.$this->getExtra(); |
|
239 | 239 | if ($this->isMultiple()) { |
240 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
240 | + $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">'; |
|
241 | 241 | } else { |
242 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
242 | + $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">'; |
|
243 | 243 | } |
244 | 244 | foreach ($ele_options as $value => $name) { |
245 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
246 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
245 | + $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"'; |
|
246 | + if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) { |
|
247 | 247 | $ret .= ' selected'; |
248 | 248 | } |
249 | - $ret .= '>' . $name . '</option>'; |
|
249 | + $ret .= '>'.$name.'</option>'; |
|
250 | 250 | } |
251 | 251 | $ret .= '</select>'; |
252 | 252 |
@@ -47,287 +47,287 @@ |
||
47 | 47 | */ |
48 | 48 | class SelectCategoryForm extends XoopsFormElement |
49 | 49 | { |
50 | - /** |
|
51 | - * Options |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $_options = []; |
|
56 | - /** |
|
57 | - * Allow multiple selections? |
|
58 | - * |
|
59 | - * @var bool |
|
60 | - */ |
|
61 | - public $_multiple = false; |
|
62 | - /** |
|
63 | - * Number of rows. "1" makes a dropdown list. |
|
64 | - * |
|
65 | - * @var int |
|
66 | - */ |
|
67 | - public $_size; |
|
68 | - /** |
|
69 | - * Pre-selcted values |
|
70 | - * |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - public $_value = []; |
|
50 | + /** |
|
51 | + * Options |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $_options = []; |
|
56 | + /** |
|
57 | + * Allow multiple selections? |
|
58 | + * |
|
59 | + * @var bool |
|
60 | + */ |
|
61 | + public $_multiple = false; |
|
62 | + /** |
|
63 | + * Number of rows. "1" makes a dropdown list. |
|
64 | + * |
|
65 | + * @var int |
|
66 | + */ |
|
67 | + public $_size; |
|
68 | + /** |
|
69 | + * Pre-selcted values |
|
70 | + * |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + public $_value = []; |
|
74 | 74 | |
75 | - /** |
|
76 | - * Constructor |
|
77 | - * |
|
78 | - * @param string $caption Caption |
|
79 | - * @param string $name "name" attribute |
|
80 | - * @param mixed $value Pre-selected value (or array of them). |
|
81 | - * @param int $size Number of rows. "1" makes a drop-down-list |
|
82 | - * @param bool $multiple Allow multiple selections? |
|
83 | - * @param int $ownid |
|
84 | - */ |
|
85 | - public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0) |
|
86 | - { |
|
87 | - global $_form_object_options; |
|
88 | - \xoops_loadLanguage('modinfo', 'songlist'); |
|
75 | + /** |
|
76 | + * Constructor |
|
77 | + * |
|
78 | + * @param string $caption Caption |
|
79 | + * @param string $name "name" attribute |
|
80 | + * @param mixed $value Pre-selected value (or array of them). |
|
81 | + * @param int $size Number of rows. "1" makes a drop-down-list |
|
82 | + * @param bool $multiple Allow multiple selections? |
|
83 | + * @param int $ownid |
|
84 | + */ |
|
85 | + public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0) |
|
86 | + { |
|
87 | + global $_form_object_options; |
|
88 | + \xoops_loadLanguage('modinfo', 'songlist'); |
|
89 | 89 | |
90 | - $this->setCaption($caption); |
|
91 | - $this->setName($name); |
|
92 | - $this->_multiple = $multiple; |
|
93 | - $this->_size = (int)$size; |
|
94 | - if (isset($value)) { |
|
95 | - $this->setValue($value); |
|
96 | - } |
|
97 | - $this->addOption('0', \_MI_SONGLIST_ALL); |
|
98 | - if (!isset($_form_object_options['category'])) { |
|
99 | - $_form_object_options['category'] = $this->getCategory(0); |
|
100 | - } |
|
101 | - // if (Request::hasVar('category', 'form_object_options')) { |
|
102 | - if (isset($_form_object_options['category'])) { |
|
103 | - $this->populateList($_form_object_options['category'], $ownid); |
|
104 | - } |
|
105 | - } |
|
90 | + $this->setCaption($caption); |
|
91 | + $this->setName($name); |
|
92 | + $this->_multiple = $multiple; |
|
93 | + $this->_size = (int)$size; |
|
94 | + if (isset($value)) { |
|
95 | + $this->setValue($value); |
|
96 | + } |
|
97 | + $this->addOption('0', \_MI_SONGLIST_ALL); |
|
98 | + if (!isset($_form_object_options['category'])) { |
|
99 | + $_form_object_options['category'] = $this->getCategory(0); |
|
100 | + } |
|
101 | + // if (Request::hasVar('category', 'form_object_options')) { |
|
102 | + if (isset($_form_object_options['category'])) { |
|
103 | + $this->populateList($_form_object_options['category'], $ownid); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param $vars |
|
109 | - * @param int $ownid |
|
110 | - */ |
|
111 | - public function populateList($vars, $ownid = 0): void |
|
112 | - { |
|
113 | - foreach ($vars as $previd => $cats) { |
|
114 | - if ($previd != $ownid || 0 == $ownid) { |
|
115 | - foreach ($cats as $catid => $title) { |
|
116 | - if ($catid != $ownid || 0 == $ownid) { |
|
117 | - $this->addOption($catid, $title['item']); |
|
118 | - if (isset($title['sub'])) { |
|
119 | - $this->populateList($title['sub'], $ownid); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
107 | + /** |
|
108 | + * @param $vars |
|
109 | + * @param int $ownid |
|
110 | + */ |
|
111 | + public function populateList($vars, $ownid = 0): void |
|
112 | + { |
|
113 | + foreach ($vars as $previd => $cats) { |
|
114 | + if ($previd != $ownid || 0 == $ownid) { |
|
115 | + foreach ($cats as $catid => $title) { |
|
116 | + if ($catid != $ownid || 0 == $ownid) { |
|
117 | + $this->addOption($catid, $title['item']); |
|
118 | + if (isset($title['sub'])) { |
|
119 | + $this->populateList($title['sub'], $ownid); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param $ownid |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public function getCategory($ownid): array |
|
132 | - { |
|
133 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
134 | - $criteria = new \Criteria('pid', '0'); |
|
135 | - $criteria->setSort('name'); |
|
136 | - $criteria->setOrder('ASC'); |
|
137 | - $categories = $categoryHandler->getObjects($criteria, true); |
|
138 | - $langs_array = $this->treeMenu([], $categories, -1, $ownid); |
|
127 | + /** |
|
128 | + * @param $ownid |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public function getCategory($ownid): array |
|
132 | + { |
|
133 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
134 | + $criteria = new \Criteria('pid', '0'); |
|
135 | + $criteria->setSort('name'); |
|
136 | + $criteria->setOrder('ASC'); |
|
137 | + $categories = $categoryHandler->getObjects($criteria, true); |
|
138 | + $langs_array = $this->treeMenu([], $categories, -1, $ownid); |
|
139 | 139 | |
140 | - return $langs_array; |
|
141 | - } |
|
140 | + return $langs_array; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @param $langs_array |
|
145 | - * @param $categories |
|
146 | - * @param $level |
|
147 | - * @param $ownid |
|
148 | - * @param int $previd |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function treeMenu($langs_array, $categories, $level, $ownid, $previd = 0): array |
|
152 | - { |
|
153 | - ++$level; |
|
154 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
155 | - foreach ($categories as $catid => $category) { |
|
156 | - if ($catid != $ownid) { |
|
157 | - $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name'); |
|
158 | - $criteria = new \Criteria('pid', $catid); |
|
159 | - $criteria->setSort('name'); |
|
160 | - $criteria->setOrder('ASC'); |
|
161 | - $categoriesb = $categoryHandler->getObjects($criteria, true); |
|
162 | - if ($categoriesb) { |
|
163 | - $langs_array[$previd][$catid]['sub'] = $this->treeMenu($langs_array, $categoriesb, $level, $ownid, $catid); |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - $level--; |
|
143 | + /** |
|
144 | + * @param $langs_array |
|
145 | + * @param $categories |
|
146 | + * @param $level |
|
147 | + * @param $ownid |
|
148 | + * @param int $previd |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function treeMenu($langs_array, $categories, $level, $ownid, $previd = 0): array |
|
152 | + { |
|
153 | + ++$level; |
|
154 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
155 | + foreach ($categories as $catid => $category) { |
|
156 | + if ($catid != $ownid) { |
|
157 | + $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name'); |
|
158 | + $criteria = new \Criteria('pid', $catid); |
|
159 | + $criteria->setSort('name'); |
|
160 | + $criteria->setOrder('ASC'); |
|
161 | + $categoriesb = $categoryHandler->getObjects($criteria, true); |
|
162 | + if ($categoriesb) { |
|
163 | + $langs_array[$previd][$catid]['sub'] = $this->treeMenu($langs_array, $categoriesb, $level, $ownid, $catid); |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + $level--; |
|
168 | 168 | |
169 | - return $langs_array; |
|
170 | - } |
|
169 | + return $langs_array; |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Are multiple selections allowed? |
|
174 | - * |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public function isMultiple(): bool |
|
178 | - { |
|
179 | - return $this->_multiple; |
|
180 | - } |
|
172 | + /** |
|
173 | + * Are multiple selections allowed? |
|
174 | + * |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public function isMultiple(): bool |
|
178 | + { |
|
179 | + return $this->_multiple; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Get the size |
|
184 | - * |
|
185 | - * @return int |
|
186 | - */ |
|
187 | - public function getSize(): int |
|
188 | - { |
|
189 | - return $this->_size; |
|
190 | - } |
|
182 | + /** |
|
183 | + * Get the size |
|
184 | + * |
|
185 | + * @return int |
|
186 | + */ |
|
187 | + public function getSize(): int |
|
188 | + { |
|
189 | + return $this->_size; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Get an array of pre-selected values |
|
194 | - * |
|
195 | - * @param bool $encode To sanitizer the text? |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function getValue($encode = false): array |
|
199 | - { |
|
200 | - if (!$encode) { |
|
201 | - return $this->_value; |
|
202 | - } |
|
203 | - $value = []; |
|
204 | - foreach ($this->_value as $val) { |
|
205 | - $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
206 | - } |
|
192 | + /** |
|
193 | + * Get an array of pre-selected values |
|
194 | + * |
|
195 | + * @param bool $encode To sanitizer the text? |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function getValue($encode = false): array |
|
199 | + { |
|
200 | + if (!$encode) { |
|
201 | + return $this->_value; |
|
202 | + } |
|
203 | + $value = []; |
|
204 | + foreach ($this->_value as $val) { |
|
205 | + $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
206 | + } |
|
207 | 207 | |
208 | - return $value; |
|
209 | - } |
|
208 | + return $value; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Set pre-selected values |
|
213 | - * |
|
214 | - * @param mixed $value |
|
215 | - */ |
|
216 | - public function setValue($value): void |
|
217 | - { |
|
218 | - if (\is_array($value)) { |
|
219 | - foreach ($value as $v) { |
|
220 | - $this->_value[] = (int)$v; |
|
221 | - } |
|
211 | + /** |
|
212 | + * Set pre-selected values |
|
213 | + * |
|
214 | + * @param mixed $value |
|
215 | + */ |
|
216 | + public function setValue($value): void |
|
217 | + { |
|
218 | + if (\is_array($value)) { |
|
219 | + foreach ($value as $v) { |
|
220 | + $this->_value[] = (int)$v; |
|
221 | + } |
|
222 | 222 | // $this->_value[] = array_values($value); |
223 | - } elseif (isset($value)) { |
|
224 | - $this->_value[] = $value; |
|
225 | - } |
|
226 | - } |
|
223 | + } elseif (isset($value)) { |
|
224 | + $this->_value[] = $value; |
|
225 | + } |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Add an option |
|
230 | - * |
|
231 | - * @param string $value "value" attribute |
|
232 | - * @param string $name "name" attribute |
|
233 | - */ |
|
234 | - public function addOption($value, $name = ''): void |
|
235 | - { |
|
236 | - if ('' != $name) { |
|
237 | - $this->_options[$value] = $name; |
|
238 | - } else { |
|
239 | - $this->_options[$value] = $value; |
|
240 | - } |
|
241 | - } |
|
228 | + /** |
|
229 | + * Add an option |
|
230 | + * |
|
231 | + * @param string $value "value" attribute |
|
232 | + * @param string $name "name" attribute |
|
233 | + */ |
|
234 | + public function addOption($value, $name = ''): void |
|
235 | + { |
|
236 | + if ('' != $name) { |
|
237 | + $this->_options[$value] = $name; |
|
238 | + } else { |
|
239 | + $this->_options[$value] = $value; |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Add multiple options |
|
245 | - * |
|
246 | - * @param array $options Associative array of value->name pairs |
|
247 | - */ |
|
248 | - public function addOptionArray($options): void |
|
249 | - { |
|
250 | - if (\is_array($options)) { |
|
251 | - foreach ($options as $k => $v) { |
|
252 | - $this->addOption($k, $v); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
243 | + /** |
|
244 | + * Add multiple options |
|
245 | + * |
|
246 | + * @param array $options Associative array of value->name pairs |
|
247 | + */ |
|
248 | + public function addOptionArray($options): void |
|
249 | + { |
|
250 | + if (\is_array($options)) { |
|
251 | + foreach ($options as $k => $v) { |
|
252 | + $this->addOption($k, $v); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Get an array with all the options |
|
259 | - * |
|
260 | - * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
261 | - * |
|
262 | - * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
263 | - * @return array Associative array of value->name pairs |
|
264 | - */ |
|
265 | - public function getOptions($encode = false): array |
|
266 | - { |
|
267 | - if (!$encode) { |
|
268 | - return $this->_options; |
|
269 | - } |
|
270 | - $value = []; |
|
271 | - foreach ($this->_options as $val => $name) { |
|
272 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
273 | - } |
|
257 | + /** |
|
258 | + * Get an array with all the options |
|
259 | + * |
|
260 | + * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
261 | + * |
|
262 | + * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
263 | + * @return array Associative array of value->name pairs |
|
264 | + */ |
|
265 | + public function getOptions($encode = false): array |
|
266 | + { |
|
267 | + if (!$encode) { |
|
268 | + return $this->_options; |
|
269 | + } |
|
270 | + $value = []; |
|
271 | + foreach ($this->_options as $val => $name) { |
|
272 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
273 | + } |
|
274 | 274 | |
275 | - return $value; |
|
276 | - } |
|
275 | + return $value; |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Prepare HTML for output |
|
280 | - * |
|
281 | - * @return string HTML |
|
282 | - */ |
|
283 | - public function render(): string |
|
284 | - { |
|
285 | - $ele_name = $this->getName(); |
|
286 | - $ele_title = $this->getTitle(); |
|
287 | - $ele_value = $this->getValue(); |
|
288 | - $ele_options = $this->getOptions(); |
|
289 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
290 | - if ($this->isMultiple()) { |
|
291 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
292 | - } else { |
|
293 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
294 | - } |
|
295 | - foreach ($ele_options as $value => $name) { |
|
296 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
297 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
298 | - $ret .= ' selected'; |
|
299 | - } |
|
300 | - $ret .= '>' . $name . '</option>'; |
|
301 | - } |
|
302 | - $ret .= '</select>'; |
|
278 | + /** |
|
279 | + * Prepare HTML for output |
|
280 | + * |
|
281 | + * @return string HTML |
|
282 | + */ |
|
283 | + public function render(): string |
|
284 | + { |
|
285 | + $ele_name = $this->getName(); |
|
286 | + $ele_title = $this->getTitle(); |
|
287 | + $ele_value = $this->getValue(); |
|
288 | + $ele_options = $this->getOptions(); |
|
289 | + $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
290 | + if ($this->isMultiple()) { |
|
291 | + $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
292 | + } else { |
|
293 | + $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
294 | + } |
|
295 | + foreach ($ele_options as $value => $name) { |
|
296 | + $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
297 | + if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
298 | + $ret .= ' selected'; |
|
299 | + } |
|
300 | + $ret .= '>' . $name . '</option>'; |
|
301 | + } |
|
302 | + $ret .= '</select>'; |
|
303 | 303 | |
304 | - return $ret; |
|
305 | - } |
|
304 | + return $ret; |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * Render custom javascript validation code |
|
309 | - * |
|
310 | - * @seealso XoopsForm::renderValidationJS |
|
311 | - */ |
|
312 | - public function renderValidationJS() |
|
313 | - { |
|
314 | - // render custom validation code if any |
|
315 | - if (!empty($this->customValidationCode)) { |
|
316 | - return \implode("\n", $this->customValidationCode); |
|
317 | - // generate validation code if required |
|
318 | - } |
|
307 | + /** |
|
308 | + * Render custom javascript validation code |
|
309 | + * |
|
310 | + * @seealso XoopsForm::renderValidationJS |
|
311 | + */ |
|
312 | + public function renderValidationJS() |
|
313 | + { |
|
314 | + // render custom validation code if any |
|
315 | + if (!empty($this->customValidationCode)) { |
|
316 | + return \implode("\n", $this->customValidationCode); |
|
317 | + // generate validation code if required |
|
318 | + } |
|
319 | 319 | |
320 | - if ($this->isRequired()) { |
|
321 | - $eltname = $this->getName(); |
|
322 | - $eltcaption = $this->getCaption(); |
|
323 | - $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
324 | - $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
320 | + if ($this->isRequired()) { |
|
321 | + $eltname = $this->getName(); |
|
322 | + $eltcaption = $this->getCaption(); |
|
323 | + $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
324 | + $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
325 | 325 | |
326 | - return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
327 | - . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
328 | - . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
329 | - } |
|
326 | + return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
327 | + . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
328 | + . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
329 | + } |
|
330 | 330 | |
331 | - return ''; |
|
332 | - } |
|
331 | + return ''; |
|
332 | + } |
|
333 | 333 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->setCaption($caption); |
91 | 91 | $this->setName($name); |
92 | 92 | $this->_multiple = $multiple; |
93 | - $this->_size = (int)$size; |
|
93 | + $this->_size = (int) $size; |
|
94 | 94 | if (isset($value)) { |
95 | 95 | $this->setValue($value); |
96 | 96 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | public function populateList($vars, $ownid = 0): void |
112 | 112 | { |
113 | 113 | foreach ($vars as $previd => $cats) { |
114 | - if ($previd != $ownid || 0 == $ownid) { |
|
114 | + if ($previd!=$ownid || 0==$ownid) { |
|
115 | 115 | foreach ($cats as $catid => $title) { |
116 | - if ($catid != $ownid || 0 == $ownid) { |
|
116 | + if ($catid!=$ownid || 0==$ownid) { |
|
117 | 117 | $this->addOption($catid, $title['item']); |
118 | 118 | if (isset($title['sub'])) { |
119 | 119 | $this->populateList($title['sub'], $ownid); |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | ++$level; |
154 | 154 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
155 | 155 | foreach ($categories as $catid => $category) { |
156 | - if ($catid != $ownid) { |
|
157 | - $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name'); |
|
156 | + if ($catid!=$ownid) { |
|
157 | + $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level).$category->getVar('name'); |
|
158 | 158 | $criteria = new \Criteria('pid', $catid); |
159 | 159 | $criteria->setSort('name'); |
160 | 160 | $criteria->setOrder('ASC'); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | if (\is_array($value)) { |
219 | 219 | foreach ($value as $v) { |
220 | - $this->_value[] = (int)$v; |
|
220 | + $this->_value[] = (int) $v; |
|
221 | 221 | } |
222 | 222 | // $this->_value[] = array_values($value); |
223 | 223 | } elseif (isset($value)) { |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function addOption($value, $name = ''): void |
235 | 235 | { |
236 | - if ('' != $name) { |
|
236 | + if (''!=$name) { |
|
237 | 237 | $this->_options[$value] = $name; |
238 | 238 | } else { |
239 | 239 | $this->_options[$value] = $value; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | $value = []; |
271 | 271 | foreach ($this->_options as $val => $name) { |
272 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
272 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return $value; |
@@ -286,18 +286,18 @@ discard block |
||
286 | 286 | $ele_title = $this->getTitle(); |
287 | 287 | $ele_value = $this->getValue(); |
288 | 288 | $ele_options = $this->getOptions(); |
289 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
289 | + $ret = '<select size="'.$this->getSize().'"'.$this->getExtra(); |
|
290 | 290 | if ($this->isMultiple()) { |
291 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
291 | + $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">'; |
|
292 | 292 | } else { |
293 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
293 | + $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">'; |
|
294 | 294 | } |
295 | 295 | foreach ($ele_options as $value => $name) { |
296 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
297 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
296 | + $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"'; |
|
297 | + if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) { |
|
298 | 298 | $ret .= ' selected'; |
299 | 299 | } |
300 | - $ret .= '>' . $name . '</option>'; |
|
300 | + $ret .= '>'.$name.'</option>'; |
|
301 | 301 | } |
302 | 302 | $ret .= '</select>'; |
303 | 303 |
@@ -53,229 +53,229 @@ |
||
53 | 53 | */ |
54 | 54 | class SelectVoiceForm extends XoopsFormElement |
55 | 55 | { |
56 | - /** |
|
57 | - * Options |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - public $_options = []; |
|
62 | - /** |
|
63 | - * Allow multiple selections? |
|
64 | - * |
|
65 | - * @var bool |
|
66 | - */ |
|
67 | - public $_multiple = false; |
|
68 | - /** |
|
69 | - * Number of rows. "1" makes a dropdown list. |
|
70 | - * |
|
71 | - * @var int |
|
72 | - */ |
|
73 | - public $_size; |
|
74 | - /** |
|
75 | - * Pre-selcted values |
|
76 | - * |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - public $_value = []; |
|
56 | + /** |
|
57 | + * Options |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + public $_options = []; |
|
62 | + /** |
|
63 | + * Allow multiple selections? |
|
64 | + * |
|
65 | + * @var bool |
|
66 | + */ |
|
67 | + public $_multiple = false; |
|
68 | + /** |
|
69 | + * Number of rows. "1" makes a dropdown list. |
|
70 | + * |
|
71 | + * @var int |
|
72 | + */ |
|
73 | + public $_size; |
|
74 | + /** |
|
75 | + * Pre-selcted values |
|
76 | + * |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + public $_value = []; |
|
80 | 80 | |
81 | - /** |
|
82 | - * Constructor |
|
83 | - * |
|
84 | - * @param string $caption Caption |
|
85 | - * @param string $name "name" attribute |
|
86 | - * @param mixed $value Pre-selected value (or array of them). |
|
87 | - * @param int $size Number or rows. "1" makes a drop-down-list |
|
88 | - * @param bool $multiple Allow multiple selections? |
|
89 | - */ |
|
90 | - public function __construct($caption, $name, $value = null, $size = 1, $multiple = false) |
|
91 | - { |
|
92 | - global $_form_object_options; |
|
93 | - \xoops_loadLanguage('modinfo', 'songlist'); |
|
81 | + /** |
|
82 | + * Constructor |
|
83 | + * |
|
84 | + * @param string $caption Caption |
|
85 | + * @param string $name "name" attribute |
|
86 | + * @param mixed $value Pre-selected value (or array of them). |
|
87 | + * @param int $size Number or rows. "1" makes a drop-down-list |
|
88 | + * @param bool $multiple Allow multiple selections? |
|
89 | + */ |
|
90 | + public function __construct($caption, $name, $value = null, $size = 1, $multiple = false) |
|
91 | + { |
|
92 | + global $_form_object_options; |
|
93 | + \xoops_loadLanguage('modinfo', 'songlist'); |
|
94 | 94 | |
95 | - $this->setCaption($caption); |
|
96 | - $this->setName($name); |
|
97 | - $this->_multiple = $multiple; |
|
98 | - $this->_size = (int)$size; |
|
99 | - if (isset($value)) { |
|
100 | - $this->setValue($value); |
|
101 | - } |
|
102 | - $this->addOption('0', \_MI_SONGLIST_ALL); |
|
103 | - if (!isset($_form_object_options['voice'])) { |
|
104 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
105 | - $criteria = new Criteria(''); |
|
106 | - $criteria->setSort('name'); |
|
107 | - $criteria->setOrder('ASC'); |
|
108 | - foreach ($voiceHandler->getObjects($criteria, true) as $id => $obj) { |
|
109 | - $_form_object_options['voice'][$id] = $obj->getVar('name'); |
|
110 | - } |
|
111 | - } |
|
112 | - // if (Request::hasVar('voice', 'form_object_options')) { |
|
113 | - if (isset($_form_object_options['voice'])) { |
|
114 | - foreach ($_form_object_options['voice'] as $id => $value) { |
|
115 | - $this->addOption($id, $value); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
95 | + $this->setCaption($caption); |
|
96 | + $this->setName($name); |
|
97 | + $this->_multiple = $multiple; |
|
98 | + $this->_size = (int)$size; |
|
99 | + if (isset($value)) { |
|
100 | + $this->setValue($value); |
|
101 | + } |
|
102 | + $this->addOption('0', \_MI_SONGLIST_ALL); |
|
103 | + if (!isset($_form_object_options['voice'])) { |
|
104 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
105 | + $criteria = new Criteria(''); |
|
106 | + $criteria->setSort('name'); |
|
107 | + $criteria->setOrder('ASC'); |
|
108 | + foreach ($voiceHandler->getObjects($criteria, true) as $id => $obj) { |
|
109 | + $_form_object_options['voice'][$id] = $obj->getVar('name'); |
|
110 | + } |
|
111 | + } |
|
112 | + // if (Request::hasVar('voice', 'form_object_options')) { |
|
113 | + if (isset($_form_object_options['voice'])) { |
|
114 | + foreach ($_form_object_options['voice'] as $id => $value) { |
|
115 | + $this->addOption($id, $value); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Are multiple selections allowed? |
|
122 | - * |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - public function isMultiple(): bool |
|
126 | - { |
|
127 | - return $this->_multiple; |
|
128 | - } |
|
120 | + /** |
|
121 | + * Are multiple selections allowed? |
|
122 | + * |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + public function isMultiple(): bool |
|
126 | + { |
|
127 | + return $this->_multiple; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Get the size |
|
132 | - * |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function getSize(): int |
|
136 | - { |
|
137 | - return $this->_size; |
|
138 | - } |
|
130 | + /** |
|
131 | + * Get the size |
|
132 | + * |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function getSize(): int |
|
136 | + { |
|
137 | + return $this->_size; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Get an array of pre-selected values |
|
142 | - * |
|
143 | - * @param bool $encode To sanitizer the text? |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - public function getValue($encode = false): array |
|
147 | - { |
|
148 | - if (!$encode) { |
|
149 | - return $this->_value; |
|
150 | - } |
|
151 | - $value = []; |
|
152 | - foreach ($this->_value as $val) { |
|
153 | - $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
154 | - } |
|
140 | + /** |
|
141 | + * Get an array of pre-selected values |
|
142 | + * |
|
143 | + * @param bool $encode To sanitizer the text? |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + public function getValue($encode = false): array |
|
147 | + { |
|
148 | + if (!$encode) { |
|
149 | + return $this->_value; |
|
150 | + } |
|
151 | + $value = []; |
|
152 | + foreach ($this->_value as $val) { |
|
153 | + $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val; |
|
154 | + } |
|
155 | 155 | |
156 | - return $value; |
|
157 | - } |
|
156 | + return $value; |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Set pre-selected values |
|
161 | - * |
|
162 | - * @param mixed $value |
|
163 | - */ |
|
164 | - public function setValue($value): void |
|
165 | - { |
|
166 | - if (\is_array($value)) { |
|
167 | - foreach ($value as $v) { |
|
168 | - $this->_value[] = (int)$v; |
|
169 | - } |
|
159 | + /** |
|
160 | + * Set pre-selected values |
|
161 | + * |
|
162 | + * @param mixed $value |
|
163 | + */ |
|
164 | + public function setValue($value): void |
|
165 | + { |
|
166 | + if (\is_array($value)) { |
|
167 | + foreach ($value as $v) { |
|
168 | + $this->_value[] = (int)$v; |
|
169 | + } |
|
170 | 170 | // $this->_value[] = array_values($value); |
171 | - } elseif (isset($value)) { |
|
172 | - $this->_value[] = $value; |
|
173 | - } |
|
174 | - } |
|
171 | + } elseif (isset($value)) { |
|
172 | + $this->_value[] = $value; |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Add an option |
|
178 | - * |
|
179 | - * @param string $value "value" attribute |
|
180 | - * @param string $name "name" attribute |
|
181 | - */ |
|
182 | - public function addOption($value, $name = ''): void |
|
183 | - { |
|
184 | - if ('' != $name) { |
|
185 | - $this->_options[$value] = $name; |
|
186 | - } else { |
|
187 | - $this->_options[$value] = $value; |
|
188 | - } |
|
189 | - } |
|
176 | + /** |
|
177 | + * Add an option |
|
178 | + * |
|
179 | + * @param string $value "value" attribute |
|
180 | + * @param string $name "name" attribute |
|
181 | + */ |
|
182 | + public function addOption($value, $name = ''): void |
|
183 | + { |
|
184 | + if ('' != $name) { |
|
185 | + $this->_options[$value] = $name; |
|
186 | + } else { |
|
187 | + $this->_options[$value] = $value; |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Add multiple options |
|
193 | - * |
|
194 | - * @param array $options Associative array of value->name pairs |
|
195 | - */ |
|
196 | - public function addOptionArray($options): void |
|
197 | - { |
|
198 | - if (\is_array($options)) { |
|
199 | - foreach ($options as $k => $v) { |
|
200 | - $this->addOption($k, $v); |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
191 | + /** |
|
192 | + * Add multiple options |
|
193 | + * |
|
194 | + * @param array $options Associative array of value->name pairs |
|
195 | + */ |
|
196 | + public function addOptionArray($options): void |
|
197 | + { |
|
198 | + if (\is_array($options)) { |
|
199 | + foreach ($options as $k => $v) { |
|
200 | + $this->addOption($k, $v); |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Get an array with all the options |
|
207 | - * |
|
208 | - * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
209 | - * |
|
210 | - * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
211 | - * @return array Associative array of value->name pairs |
|
212 | - */ |
|
213 | - public function getOptions($encode = false): array |
|
214 | - { |
|
215 | - if (!$encode) { |
|
216 | - return $this->_options; |
|
217 | - } |
|
218 | - $value = []; |
|
219 | - foreach ($this->_options as $val => $name) { |
|
220 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
221 | - } |
|
205 | + /** |
|
206 | + * Get an array with all the options |
|
207 | + * |
|
208 | + * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now. |
|
209 | + * |
|
210 | + * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name |
|
211 | + * @return array Associative array of value->name pairs |
|
212 | + */ |
|
213 | + public function getOptions($encode = false): array |
|
214 | + { |
|
215 | + if (!$encode) { |
|
216 | + return $this->_options; |
|
217 | + } |
|
218 | + $value = []; |
|
219 | + foreach ($this->_options as $val => $name) { |
|
220 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
221 | + } |
|
222 | 222 | |
223 | - return $value; |
|
224 | - } |
|
223 | + return $value; |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Prepare HTML for output |
|
228 | - * |
|
229 | - * @return string HTML |
|
230 | - */ |
|
231 | - public function render(): string |
|
232 | - { |
|
233 | - $ele_name = $this->getName(); |
|
234 | - $ele_title = $this->getTitle(); |
|
235 | - $ele_value = $this->getValue(); |
|
236 | - $ele_options = $this->getOptions(); |
|
237 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
238 | - if ($this->isMultiple()) { |
|
239 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
240 | - } else { |
|
241 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
242 | - } |
|
243 | - foreach ($ele_options as $value => $name) { |
|
244 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
245 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
246 | - $ret .= ' selected'; |
|
247 | - } |
|
248 | - $ret .= '>' . $name . '</option>'; |
|
249 | - } |
|
250 | - $ret .= '</select>'; |
|
226 | + /** |
|
227 | + * Prepare HTML for output |
|
228 | + * |
|
229 | + * @return string HTML |
|
230 | + */ |
|
231 | + public function render(): string |
|
232 | + { |
|
233 | + $ele_name = $this->getName(); |
|
234 | + $ele_title = $this->getTitle(); |
|
235 | + $ele_value = $this->getValue(); |
|
236 | + $ele_options = $this->getOptions(); |
|
237 | + $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
238 | + if ($this->isMultiple()) { |
|
239 | + $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
240 | + } else { |
|
241 | + $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
242 | + } |
|
243 | + foreach ($ele_options as $value => $name) { |
|
244 | + $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
245 | + if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
246 | + $ret .= ' selected'; |
|
247 | + } |
|
248 | + $ret .= '>' . $name . '</option>'; |
|
249 | + } |
|
250 | + $ret .= '</select>'; |
|
251 | 251 | |
252 | - return $ret; |
|
253 | - } |
|
252 | + return $ret; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Render custom javascript validation code |
|
257 | - * |
|
258 | - * @seealso XoopsForm::renderValidationJS |
|
259 | - */ |
|
260 | - public function renderValidationJS() |
|
261 | - { |
|
262 | - // render custom validation code if any |
|
263 | - if (!empty($this->customValidationCode)) { |
|
264 | - return \implode("\n", $this->customValidationCode); |
|
265 | - // generate validation code if required |
|
266 | - } |
|
255 | + /** |
|
256 | + * Render custom javascript validation code |
|
257 | + * |
|
258 | + * @seealso XoopsForm::renderValidationJS |
|
259 | + */ |
|
260 | + public function renderValidationJS() |
|
261 | + { |
|
262 | + // render custom validation code if any |
|
263 | + if (!empty($this->customValidationCode)) { |
|
264 | + return \implode("\n", $this->customValidationCode); |
|
265 | + // generate validation code if required |
|
266 | + } |
|
267 | 267 | |
268 | - if ($this->isRequired()) { |
|
269 | - $eltname = $this->getName(); |
|
270 | - $eltcaption = $this->getCaption(); |
|
271 | - $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
272 | - $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
268 | + if ($this->isRequired()) { |
|
269 | + $eltname = $this->getName(); |
|
270 | + $eltcaption = $this->getCaption(); |
|
271 | + $eltmsg = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption); |
|
272 | + $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
|
273 | 273 | |
274 | - return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
275 | - . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
276 | - . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
277 | - } |
|
274 | + return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" |
|
275 | + . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }' |
|
276 | + . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
|
277 | + } |
|
278 | 278 | |
279 | - return ''; |
|
280 | - } |
|
279 | + return ''; |
|
280 | + } |
|
281 | 281 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $this->setCaption($caption); |
97 | 97 | $this->setName($name); |
98 | 98 | $this->_multiple = $multiple; |
99 | - $this->_size = (int)$size; |
|
99 | + $this->_size = (int) $size; |
|
100 | 100 | if (isset($value)) { |
101 | 101 | $this->setValue($value); |
102 | 102 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | if (\is_array($value)) { |
168 | 168 | foreach ($value as $v) { |
169 | - $this->_value[] = (int)$v; |
|
169 | + $this->_value[] = (int) $v; |
|
170 | 170 | } |
171 | 171 | // $this->_value[] = array_values($value); |
172 | 172 | } elseif (isset($value)) { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function addOption($value, $name = ''): void |
184 | 184 | { |
185 | - if ('' != $name) { |
|
185 | + if (''!=$name) { |
|
186 | 186 | $this->_options[$value] = $name; |
187 | 187 | } else { |
188 | 188 | $this->_options[$value] = $value; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | $value = []; |
220 | 220 | foreach ($this->_options as $val => $name) { |
221 | - $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
221 | + $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $value; |
@@ -235,18 +235,18 @@ discard block |
||
235 | 235 | $ele_title = $this->getTitle(); |
236 | 236 | $ele_value = $this->getValue(); |
237 | 237 | $ele_options = $this->getOptions(); |
238 | - $ret = '<select size="' . $this->getSize() . '"' . $this->getExtra(); |
|
238 | + $ret = '<select size="'.$this->getSize().'"'.$this->getExtra(); |
|
239 | 239 | if ($this->isMultiple()) { |
240 | - $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">'; |
|
240 | + $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">'; |
|
241 | 241 | } else { |
242 | - $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">'; |
|
242 | + $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">'; |
|
243 | 243 | } |
244 | 244 | foreach ($ele_options as $value => $name) { |
245 | - $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"'; |
|
246 | - if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) { |
|
245 | + $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"'; |
|
246 | + if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) { |
|
247 | 247 | $ret .= ' selected'; |
248 | 248 | } |
249 | - $ret .= '>' . $name . '</option>'; |
|
249 | + $ret .= '>'.$name.'</option>'; |
|
250 | 250 | } |
251 | 251 | $ret .= '</select>'; |
252 | 252 |
@@ -7,28 +7,28 @@ |
||
7 | 7 | */ |
8 | 8 | class Extras extends \XoopsObject |
9 | 9 | { |
10 | - public $handler; |
|
10 | + public $handler; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Extras constructor. |
|
14 | - * @param $fields |
|
15 | - */ |
|
16 | - public function __construct($fields) |
|
17 | - { |
|
18 | - $this->initVar('sid', \XOBJ_DTYPE_INT, null, true); |
|
19 | - $this->init($fields); |
|
20 | - } |
|
12 | + /** |
|
13 | + * Extras constructor. |
|
14 | + * @param $fields |
|
15 | + */ |
|
16 | + public function __construct($fields) |
|
17 | + { |
|
18 | + $this->initVar('sid', \XOBJ_DTYPE_INT, null, true); |
|
19 | + $this->init($fields); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Initiate variables |
|
24 | - * @param array $fields field information array of {@link \XoopsObjectsField} objects |
|
25 | - */ |
|
26 | - public function init($fields): void |
|
27 | - { |
|
28 | - if ($fields && \is_array($fields)) { |
|
29 | - foreach (\array_keys($fields) as $key) { |
|
30 | - $this->initVar($key, $fields[$key]->getVar('field_valuetype'), $fields[$key]->getVar('field_default', 'n'), $fields[$key]->getVar('field_required'), $fields[$key]->getVar('field_maxlength')); |
|
31 | - } |
|
32 | - } |
|
33 | - } |
|
22 | + /** |
|
23 | + * Initiate variables |
|
24 | + * @param array $fields field information array of {@link \XoopsObjectsField} objects |
|
25 | + */ |
|
26 | + public function init($fields): void |
|
27 | + { |
|
28 | + if ($fields && \is_array($fields)) { |
|
29 | + foreach (\array_keys($fields) as $key) { |
|
30 | + $this->initVar($key, $fields[$key]->getVar('field_valuetype'), $fields[$key]->getVar('field_default', 'n'), $fields[$key]->getVar('field_required'), $fields[$key]->getVar('field_maxlength')); |
|
31 | + } |
|
32 | + } |
|
33 | + } |
|
34 | 34 | } |
@@ -11,138 +11,138 @@ |
||
11 | 11 | */ |
12 | 12 | class Artists extends \XoopsObject |
13 | 13 | { |
14 | - /** |
|
15 | - * Artists constructor. |
|
16 | - * @param null $fid |
|
17 | - */ |
|
18 | - public function __construct($fid = null) |
|
19 | - { |
|
20 | - $this->initVar('aid', \XOBJ_DTYPE_INT, 0, false); |
|
21 | - $this->initVar('cids', \XOBJ_DTYPE_ARRAY, [], false); |
|
22 | - $this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false); |
|
23 | - $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
24 | - $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
|
25 | - $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
|
26 | - $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
|
27 | - $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
|
28 | - $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
29 | - $this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
|
30 | - $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @param bool $as_array |
|
35 | - * @return array|string |
|
36 | - */ |
|
37 | - public function getForm($as_array = false) |
|
38 | - { |
|
39 | - return FormController::getFormArtists($this, $as_array); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param bool $extra |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function toArray($extra = false): array |
|
47 | - { |
|
48 | - $ret = parent::toArray(); |
|
49 | - $form = $this->getForm(true); |
|
50 | - foreach ($form as $key => $element) { |
|
51 | - $ret['form'][$key] = $element->render(); |
|
52 | - } |
|
53 | - foreach (['created', 'updated'] as $key) { |
|
54 | - if ($this->getVar($key) > 0) { |
|
55 | - $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
|
56 | - $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
61 | - $ret['url'] = $this->getURL(true); |
|
62 | - |
|
63 | - \xoops_loadLanguage('enum', 'songlist'); |
|
64 | - if (!empty($ret['singer'])) { |
|
65 | - $ret['singer'] = \constant($ret['singer']); |
|
66 | - } |
|
67 | - |
|
68 | - if (!$extra) { |
|
69 | - return $ret; |
|
70 | - } |
|
71 | - |
|
72 | - if (0 != \count($this->getVar('cids'))) { |
|
73 | - $categoriesHandler = Helper::getInstance()->getHandler('Category'); |
|
74 | - foreach ($this->getVar('cids') as $aid) { |
|
75 | - $category = $categoriesHandler->get($aid); |
|
76 | - if (\is_object($category)) { |
|
77 | - $ret['categories_array'][$aid] = $category->toArray(false); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - if (\is_array($this->getVar('aids')) && 0 != \count($this->getVar('aids'))) { |
|
83 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
84 | - foreach ($this->getVar('aids') as $aid) { |
|
85 | - $artist = $artistsHandler->get($aid); |
|
86 | - if (\is_object($artist)) { |
|
87 | - $ret['artists_array'][$aid] = $artist->toArray(false); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - if (0 != \count($this->getVar('sids'))) { |
|
93 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
94 | - $criteria = new \Criteria('aids', '%"' . $this->getVar('aid') . '"%', 'LIKE'); |
|
95 | - $criteria->setSort('songid'); |
|
96 | - $criteria->setOrder('ASC'); |
|
97 | - foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
|
98 | - if (\is_object($song)) { |
|
99 | - $ret['songs_array'][$sid] = $song->toArray(false); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - return $ret; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function getURL(): string |
|
111 | - { |
|
112 | - global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
|
113 | - if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
114 | - if (0 != $id) { |
|
115 | - $artistHandler = Helper::getInstance()->getHandler('Artists'); |
|
116 | - $artist = $artistHandler->get($id); |
|
117 | - if (\is_object($artist) && !$artist->isNew()) { |
|
118 | - return XOOPS_URL |
|
119 | - . '/' |
|
120 | - . $GLOBALS['songlistModuleConfig']['baseofurl'] |
|
121 | - . '/artists/' |
|
122 | - . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name'))) |
|
123 | - . '/' |
|
124 | - . $start |
|
125 | - . '-' |
|
126 | - . $id |
|
127 | - . '-' |
|
128 | - . $op |
|
129 | - . '-' |
|
130 | - . $fct |
|
131 | - . '-' |
|
132 | - . $gid |
|
133 | - . '-' |
|
134 | - . $cid |
|
135 | - . '/' |
|
136 | - . \urlencode($value) |
|
137 | - . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
138 | - } |
|
139 | - |
|
140 | - return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
141 | - } |
|
142 | - |
|
143 | - return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
144 | - } |
|
145 | - |
|
146 | - return XOOPS_URL . '/modules/songlist/artists.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start; |
|
147 | - } |
|
14 | + /** |
|
15 | + * Artists constructor. |
|
16 | + * @param null $fid |
|
17 | + */ |
|
18 | + public function __construct($fid = null) |
|
19 | + { |
|
20 | + $this->initVar('aid', \XOBJ_DTYPE_INT, 0, false); |
|
21 | + $this->initVar('cids', \XOBJ_DTYPE_ARRAY, [], false); |
|
22 | + $this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false); |
|
23 | + $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
24 | + $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
|
25 | + $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
|
26 | + $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
|
27 | + $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
|
28 | + $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
29 | + $this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
|
30 | + $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @param bool $as_array |
|
35 | + * @return array|string |
|
36 | + */ |
|
37 | + public function getForm($as_array = false) |
|
38 | + { |
|
39 | + return FormController::getFormArtists($this, $as_array); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param bool $extra |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function toArray($extra = false): array |
|
47 | + { |
|
48 | + $ret = parent::toArray(); |
|
49 | + $form = $this->getForm(true); |
|
50 | + foreach ($form as $key => $element) { |
|
51 | + $ret['form'][$key] = $element->render(); |
|
52 | + } |
|
53 | + foreach (['created', 'updated'] as $key) { |
|
54 | + if ($this->getVar($key) > 0) { |
|
55 | + $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
|
56 | + $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
61 | + $ret['url'] = $this->getURL(true); |
|
62 | + |
|
63 | + \xoops_loadLanguage('enum', 'songlist'); |
|
64 | + if (!empty($ret['singer'])) { |
|
65 | + $ret['singer'] = \constant($ret['singer']); |
|
66 | + } |
|
67 | + |
|
68 | + if (!$extra) { |
|
69 | + return $ret; |
|
70 | + } |
|
71 | + |
|
72 | + if (0 != \count($this->getVar('cids'))) { |
|
73 | + $categoriesHandler = Helper::getInstance()->getHandler('Category'); |
|
74 | + foreach ($this->getVar('cids') as $aid) { |
|
75 | + $category = $categoriesHandler->get($aid); |
|
76 | + if (\is_object($category)) { |
|
77 | + $ret['categories_array'][$aid] = $category->toArray(false); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + if (\is_array($this->getVar('aids')) && 0 != \count($this->getVar('aids'))) { |
|
83 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
84 | + foreach ($this->getVar('aids') as $aid) { |
|
85 | + $artist = $artistsHandler->get($aid); |
|
86 | + if (\is_object($artist)) { |
|
87 | + $ret['artists_array'][$aid] = $artist->toArray(false); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + if (0 != \count($this->getVar('sids'))) { |
|
93 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
94 | + $criteria = new \Criteria('aids', '%"' . $this->getVar('aid') . '"%', 'LIKE'); |
|
95 | + $criteria->setSort('songid'); |
|
96 | + $criteria->setOrder('ASC'); |
|
97 | + foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
|
98 | + if (\is_object($song)) { |
|
99 | + $ret['songs_array'][$sid] = $song->toArray(false); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + return $ret; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function getURL(): string |
|
111 | + { |
|
112 | + global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
|
113 | + if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
114 | + if (0 != $id) { |
|
115 | + $artistHandler = Helper::getInstance()->getHandler('Artists'); |
|
116 | + $artist = $artistHandler->get($id); |
|
117 | + if (\is_object($artist) && !$artist->isNew()) { |
|
118 | + return XOOPS_URL |
|
119 | + . '/' |
|
120 | + . $GLOBALS['songlistModuleConfig']['baseofurl'] |
|
121 | + . '/artists/' |
|
122 | + . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name'))) |
|
123 | + . '/' |
|
124 | + . $start |
|
125 | + . '-' |
|
126 | + . $id |
|
127 | + . '-' |
|
128 | + . $op |
|
129 | + . '-' |
|
130 | + . $fct |
|
131 | + . '-' |
|
132 | + . $gid |
|
133 | + . '-' |
|
134 | + . $cid |
|
135 | + . '/' |
|
136 | + . \urlencode($value) |
|
137 | + . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
138 | + } |
|
139 | + |
|
140 | + return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
141 | + } |
|
142 | + |
|
143 | + return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
144 | + } |
|
145 | + |
|
146 | + return XOOPS_URL . '/modules/songlist/artists.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start; |
|
147 | + } |
|
148 | 148 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace XoopsModules\Songlist; |
4 | 4 | |
5 | -require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
|
5 | +require_once \dirname(__DIR__).'/include/songlist.object.php'; |
|
6 | 6 | // require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
7 | 7 | use XoopsModules\Songlist\Form\FormController; |
8 | 8 | |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | $ret['form'][$key] = $element->render(); |
52 | 52 | } |
53 | 53 | foreach (['created', 'updated'] as $key) { |
54 | - if ($this->getVar($key) > 0) { |
|
54 | + if ($this->getVar($key)>0) { |
|
55 | 55 | $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
56 | 56 | $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | - $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
60 | + $ret['rank'] = \number_format(($this->getVar('rank')>0 && $this->getVar('votes')>0 ? $this->getVar('rank')/$this->getVar('votes') : 0), 2).\_MI_SONGLIST_OFTEN; |
|
61 | 61 | $ret['url'] = $this->getURL(true); |
62 | 62 | |
63 | 63 | \xoops_loadLanguage('enum', 'songlist'); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | return $ret; |
70 | 70 | } |
71 | 71 | |
72 | - if (0 != \count($this->getVar('cids'))) { |
|
72 | + if (0!=\count($this->getVar('cids'))) { |
|
73 | 73 | $categoriesHandler = Helper::getInstance()->getHandler('Category'); |
74 | 74 | foreach ($this->getVar('cids') as $aid) { |
75 | 75 | $category = $categoriesHandler->get($aid); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - if (\is_array($this->getVar('aids')) && 0 != \count($this->getVar('aids'))) { |
|
82 | + if (\is_array($this->getVar('aids')) && 0!=\count($this->getVar('aids'))) { |
|
83 | 83 | $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
84 | 84 | foreach ($this->getVar('aids') as $aid) { |
85 | 85 | $artist = $artistsHandler->get($aid); |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - if (0 != \count($this->getVar('sids'))) { |
|
92 | + if (0!=\count($this->getVar('sids'))) { |
|
93 | 93 | $songsHandler = Helper::getInstance()->getHandler('Songs'); |
94 | - $criteria = new \Criteria('aids', '%"' . $this->getVar('aid') . '"%', 'LIKE'); |
|
94 | + $criteria = new \Criteria('aids', '%"'.$this->getVar('aid').'"%', 'LIKE'); |
|
95 | 95 | $criteria->setSort('songid'); |
96 | 96 | $criteria->setOrder('ASC'); |
97 | 97 | foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | { |
112 | 112 | global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
113 | 113 | if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
114 | - if (0 != $id) { |
|
114 | + if (0!=$id) { |
|
115 | 115 | $artistHandler = Helper::getInstance()->getHandler('Artists'); |
116 | 116 | $artist = $artistHandler->get($id); |
117 | 117 | if (\is_object($artist) && !$artist->isNew()) { |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | . $GLOBALS['songlistModuleConfig']['endofurl']; |
138 | 138 | } |
139 | 139 | |
140 | - return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
140 | + return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/artists/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'-'.$vcid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
|
141 | 141 | } |
142 | 142 | |
143 | - return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
143 | + return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/artists/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'-'.$vcid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
|
144 | 144 | } |
145 | 145 | |
146 | - return XOOPS_URL . '/modules/songlist/artists.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start; |
|
146 | + return XOOPS_URL.'/modules/songlist/artists.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start; |
|
147 | 147 | } |
148 | 148 | } |
@@ -17,98 +17,98 @@ |
||
17 | 17 | */ |
18 | 18 | class Utf8mapHandler extends XoopsPersistableObjectHandler |
19 | 19 | { |
20 | - /** |
|
21 | - * Utf8mapHandler constructor. |
|
22 | - * @param \XoopsDatabase $db |
|
23 | - */ |
|
24 | - public function __construct(XoopsDatabase $db) |
|
25 | - { |
|
26 | - parent::__construct($db, 'songlist_utf8map', Utf8map::class, 'utfid', 'from'); |
|
27 | - } |
|
20 | + /** |
|
21 | + * Utf8mapHandler constructor. |
|
22 | + * @param \XoopsDatabase $db |
|
23 | + */ |
|
24 | + public function __construct(XoopsDatabase $db) |
|
25 | + { |
|
26 | + parent::__construct($db, 'songlist_utf8map', Utf8map::class, 'utfid', 'from'); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function filterFields(): array |
|
33 | - { |
|
34 | - return ['utfid', 'from', 'to', 'created', 'updated']; |
|
35 | - } |
|
29 | + /** |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function filterFields(): array |
|
33 | + { |
|
34 | + return ['utfid', 'from', 'to', 'created', 'updated']; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param $filter |
|
39 | - * @return \CriteriaCompo |
|
40 | - */ |
|
41 | - public function getFilterCriteria($filter): CriteriaCompo |
|
42 | - { |
|
43 | - $parts = \explode('|', $filter); |
|
44 | - $criteria = new CriteriaCompo(); |
|
45 | - foreach ($parts as $part) { |
|
46 | - $var = \explode(',', $part); |
|
47 | - if (!empty($var[1]) && !\is_numeric($var[0])) { |
|
48 | - $object = $this->create(); |
|
49 | - if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
50 | - || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
51 | - $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
52 | - } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
|
53 | - $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
54 | - } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
55 | - $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
56 | - } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
57 | - $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
58 | - } |
|
59 | - } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
|
60 | - $criteria->add(new Criteria($var[0], $var[1])); |
|
61 | - } |
|
62 | - } |
|
37 | + /** |
|
38 | + * @param $filter |
|
39 | + * @return \CriteriaCompo |
|
40 | + */ |
|
41 | + public function getFilterCriteria($filter): CriteriaCompo |
|
42 | + { |
|
43 | + $parts = \explode('|', $filter); |
|
44 | + $criteria = new CriteriaCompo(); |
|
45 | + foreach ($parts as $part) { |
|
46 | + $var = \explode(',', $part); |
|
47 | + if (!empty($var[1]) && !\is_numeric($var[0])) { |
|
48 | + $object = $this->create(); |
|
49 | + if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
50 | + || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
51 | + $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
52 | + } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
|
53 | + $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
54 | + } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
55 | + $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
56 | + } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
57 | + $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
58 | + } |
|
59 | + } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
|
60 | + $criteria->add(new Criteria($var[0], $var[1])); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - return $criteria; |
|
65 | - } |
|
64 | + return $criteria; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param $filter |
|
69 | - * @param $field |
|
70 | - * @param string $sort |
|
71 | - * @param string $op |
|
72 | - * @param string $fct |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string |
|
76 | - { |
|
77 | - $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct); |
|
78 | - if (\is_object($ele)) { |
|
79 | - return $ele->render(); |
|
80 | - } |
|
67 | + /** |
|
68 | + * @param $filter |
|
69 | + * @param $field |
|
70 | + * @param string $sort |
|
71 | + * @param string $op |
|
72 | + * @param string $fct |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string |
|
76 | + { |
|
77 | + $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct); |
|
78 | + if (\is_object($ele)) { |
|
79 | + return $ele->render(); |
|
80 | + } |
|
81 | 81 | |
82 | - return ' '; |
|
83 | - } |
|
82 | + return ' '; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param bool $force |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - public function insert(XoopsObject $obj, $force = true) |
|
90 | - { |
|
91 | - if ($obj->isNew()) { |
|
92 | - $obj->setVar('created', \time()); |
|
93 | - } else { |
|
94 | - $obj->setVar('updated', \time()); |
|
95 | - } |
|
85 | + /** |
|
86 | + * @param bool $force |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + public function insert(XoopsObject $obj, $force = true) |
|
90 | + { |
|
91 | + if ($obj->isNew()) { |
|
92 | + $obj->setVar('created', \time()); |
|
93 | + } else { |
|
94 | + $obj->setVar('updated', \time()); |
|
95 | + } |
|
96 | 96 | |
97 | - return parent::insert($obj, $force); |
|
98 | - } |
|
97 | + return parent::insert($obj, $force); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param string $phrase |
|
102 | - * @param null $criteria |
|
103 | - * @return string|string[] |
|
104 | - */ |
|
105 | - public function convert($phrase = '', $criteria = null) |
|
106 | - { |
|
107 | - foreach ($this->getObjects($criteria, true) as $utfid => $utf8) { |
|
108 | - $phrase = \str_replace(mb_strtolower($utf8->getVar('from')), \mb_strtolower($utf8->getVar('to')), $phrase); |
|
109 | - $phrase = \str_replace(mb_strtoupper($utf8->getVar('from')), \mb_strtoupper($utf8->getVar('to')), $phrase); |
|
110 | - } |
|
100 | + /** |
|
101 | + * @param string $phrase |
|
102 | + * @param null $criteria |
|
103 | + * @return string|string[] |
|
104 | + */ |
|
105 | + public function convert($phrase = '', $criteria = null) |
|
106 | + { |
|
107 | + foreach ($this->getObjects($criteria, true) as $utfid => $utf8) { |
|
108 | + $phrase = \str_replace(mb_strtolower($utf8->getVar('from')), \mb_strtolower($utf8->getVar('to')), $phrase); |
|
109 | + $phrase = \str_replace(mb_strtoupper($utf8->getVar('from')), \mb_strtoupper($utf8->getVar('to')), $phrase); |
|
110 | + } |
|
111 | 111 | |
112 | - return $phrase; |
|
113 | - } |
|
112 | + return $phrase; |
|
113 | + } |
|
114 | 114 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use XoopsObject; |
9 | 9 | use XoopsPersistableObjectHandler; |
10 | 10 | |
11 | -require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
|
11 | +require_once \dirname(__DIR__).'/include/songlist.object.php'; |
|
12 | 12 | // require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
13 | 13 | use XoopsModules\Songlist\Form\FormController; |
14 | 14 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | $var = \explode(',', $part); |
47 | 47 | if (!empty($var[1]) && !\is_numeric($var[0])) { |
48 | 48 | $object = $this->create(); |
49 | - if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
50 | - || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
51 | - $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
49 | + if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type'] |
|
50 | + || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) { |
|
51 | + $criteria->add(new Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE'))); |
|
52 | 52 | } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
53 | - $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
54 | - } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
55 | - $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
56 | - } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
57 | - $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
53 | + $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '='))); |
|
54 | + } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) { |
|
55 | + $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '='))); |
|
56 | + } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) { |
|
57 | + $criteria->add(new Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE'))); |
|
58 | 58 | } |
59 | 59 | } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
60 | 60 | $criteria->add(new Criteria($var[0], $var[1])); |
@@ -11,83 +11,83 @@ |
||
11 | 11 | */ |
12 | 12 | class Genre extends \XoopsObject |
13 | 13 | { |
14 | - /** |
|
15 | - * Genre constructor. |
|
16 | - * @param null $fid |
|
17 | - */ |
|
18 | - public function __construct($fid = null) |
|
19 | - { |
|
20 | - $this->initVar('gid', \XOBJ_DTYPE_INT, 0, false); |
|
21 | - $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
22 | - $this->initVar('artists', \XOBJ_DTYPE_INT, 0, false); |
|
23 | - $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
|
24 | - $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
|
25 | - $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
|
26 | - $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
|
27 | - $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
28 | - $this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
|
29 | - $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
|
30 | - } |
|
14 | + /** |
|
15 | + * Genre constructor. |
|
16 | + * @param null $fid |
|
17 | + */ |
|
18 | + public function __construct($fid = null) |
|
19 | + { |
|
20 | + $this->initVar('gid', \XOBJ_DTYPE_INT, 0, false); |
|
21 | + $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
22 | + $this->initVar('artists', \XOBJ_DTYPE_INT, 0, false); |
|
23 | + $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
|
24 | + $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
|
25 | + $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
|
26 | + $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
|
27 | + $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
28 | + $this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
|
29 | + $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param bool $as_array |
|
34 | - * @return array|string |
|
35 | - */ |
|
36 | - public function getForm($as_array = false) |
|
37 | - { |
|
38 | - return FormController::getFormGenre($this, $as_array); |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param bool $as_array |
|
34 | + * @return array|string |
|
35 | + */ |
|
36 | + public function getForm($as_array = false) |
|
37 | + { |
|
38 | + return FormController::getFormGenre($this, $as_array); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function toArray(): array |
|
45 | - { |
|
46 | - $ret = parent::toArray(); |
|
47 | - $form = $this->getForm(true); |
|
48 | - foreach ($form as $key => $element) { |
|
49 | - $ret['form'][$key] = $element->render(); |
|
50 | - } |
|
51 | - foreach (['created', 'updated'] as $key) { |
|
52 | - if ($this->getVar($key) > 0) { |
|
53 | - $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
|
54 | - $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
|
55 | - } |
|
56 | - } |
|
57 | - $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
41 | + /** |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function toArray(): array |
|
45 | + { |
|
46 | + $ret = parent::toArray(); |
|
47 | + $form = $this->getForm(true); |
|
48 | + foreach ($form as $key => $element) { |
|
49 | + $ret['form'][$key] = $element->render(); |
|
50 | + } |
|
51 | + foreach (['created', 'updated'] as $key) { |
|
52 | + if ($this->getVar($key) > 0) { |
|
53 | + $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
|
54 | + $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
|
55 | + } |
|
56 | + } |
|
57 | + $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
58 | 58 | |
59 | - return $ret; |
|
60 | - } |
|
59 | + return $ret; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getURL(): string |
|
66 | - { |
|
67 | - global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit; |
|
68 | - if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
69 | - return XOOPS_URL |
|
70 | - . '/' |
|
71 | - . $GLOBALS['songlistModuleConfig']['baseurl'] |
|
72 | - . '/' |
|
73 | - . $file |
|
74 | - . '/' |
|
75 | - . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name'))) |
|
76 | - . '/' |
|
77 | - . $op |
|
78 | - . '-' |
|
79 | - . $fct |
|
80 | - . '-' |
|
81 | - . $this->getVar('gid') |
|
82 | - . '-' |
|
83 | - . \urlencode($value) |
|
84 | - . '-' |
|
85 | - . $gid |
|
86 | - . '-' |
|
87 | - . $cid |
|
88 | - . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
89 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getURL(): string |
|
66 | + { |
|
67 | + global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit; |
|
68 | + if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
69 | + return XOOPS_URL |
|
70 | + . '/' |
|
71 | + . $GLOBALS['songlistModuleConfig']['baseurl'] |
|
72 | + . '/' |
|
73 | + . $file |
|
74 | + . '/' |
|
75 | + . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name'))) |
|
76 | + . '/' |
|
77 | + . $op |
|
78 | + . '-' |
|
79 | + . $fct |
|
80 | + . '-' |
|
81 | + . $this->getVar('gid') |
|
82 | + . '-' |
|
83 | + . \urlencode($value) |
|
84 | + . '-' |
|
85 | + . $gid |
|
86 | + . '-' |
|
87 | + . $cid |
|
88 | + . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
89 | + } |
|
90 | 90 | |
91 | - return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid; |
|
92 | - } |
|
91 | + return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid; |
|
92 | + } |
|
93 | 93 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace XoopsModules\Songlist; |
4 | 4 | |
5 | -require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
|
5 | +require_once \dirname(__DIR__).'/include/songlist.object.php'; |
|
6 | 6 | // require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
7 | 7 | use XoopsModules\Songlist\Form\FormController; |
8 | 8 | |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | $ret['form'][$key] = $element->render(); |
50 | 50 | } |
51 | 51 | foreach (['created', 'updated'] as $key) { |
52 | - if ($this->getVar($key) > 0) { |
|
52 | + if ($this->getVar($key)>0) { |
|
53 | 53 | $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
54 | 54 | $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
55 | 55 | } |
56 | 56 | } |
57 | - $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
57 | + $ret['rank'] = \number_format(($this->getVar('rank')>0 && $this->getVar('votes')>0 ? $this->getVar('rank')/$this->getVar('votes') : 0), 2).\_MI_SONGLIST_OFTEN; |
|
58 | 58 | |
59 | 59 | return $ret; |
60 | 60 | } |
@@ -88,6 +88,6 @@ discard block |
||
88 | 88 | . $GLOBALS['songlistModuleConfig']['endofurl']; |
89 | 89 | } |
90 | 90 | |
91 | - return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid; |
|
91 | + return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$this->getVar('gid').'&value='.\urlencode($value ?? '').'&gid='.$gid.'&cid='.$cid; |
|
92 | 92 | } |
93 | 93 | } |
@@ -11,213 +11,213 @@ |
||
11 | 11 | */ |
12 | 12 | class ExtrasHandler extends XoopsPersistableObjectHandler |
13 | 13 | { |
14 | - /** |
|
15 | - * holds reference to {@link ObjectsFieldHandler} object |
|
16 | - */ |
|
17 | - public $_fHandler; |
|
18 | - /** |
|
19 | - * Array of {@link XoopsObjectsField} objects |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - public $_fields = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * ExtrasHandler constructor. |
|
26 | - * @param \XoopsDatabase $db |
|
27 | - */ |
|
28 | - public function __construct(XoopsDatabase $db) |
|
29 | - { |
|
30 | - parent::__construct($db, 'songlist_extra', Extras::class, 'sid'); |
|
31 | - $this->_fHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Field'); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * create a new {@link Extras} |
|
36 | - * |
|
37 | - * @param bool $isNew Flag the new objects as "new"? |
|
38 | - * |
|
39 | - * @return object {@link Extras} |
|
40 | - */ |
|
41 | - public function &create($isNew = true): object |
|
42 | - { |
|
43 | - $obj = new $this->className($this->loadFields()); |
|
44 | - $obj->handler = $this; |
|
45 | - $obj->setNew(); |
|
46 | - |
|
47 | - return $obj; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Get a {@link Extras} |
|
52 | - * |
|
53 | - * @param null $id |
|
54 | - * @param null $fields |
|
55 | - * @return object <a href='psi_element://Extras'>Extras</a> |
|
56 | - */ |
|
57 | - public function get($id = null, $fields = null): object //get($uid, $createOnFailure = true) |
|
58 | - { |
|
59 | - if (null === $fields) { |
|
60 | - $fields = true; |
|
61 | - } |
|
62 | - $obj = parent::get($id); |
|
63 | - if (!\is_object($obj) && $fields) { |
|
64 | - $obj = $this->create(); |
|
65 | - } |
|
66 | - |
|
67 | - return $obj; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Create new {@link ObjectsField} object |
|
72 | - * |
|
73 | - * @param bool $isNew |
|
74 | - * |
|
75 | - * @return object |
|
76 | - */ |
|
77 | - public function &createField($isNew = true): object |
|
78 | - { |
|
79 | - $return = $this->_fHandler->create($isNew); |
|
80 | - |
|
81 | - return $return; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Load field information |
|
86 | - * |
|
87 | - * @return array|false |
|
88 | - */ |
|
89 | - public function loadFields() |
|
90 | - { |
|
91 | - if (0 == \count($this->_fields)) { |
|
92 | - $this->_fields = $this->_fHandler->loadFields(); |
|
93 | - } |
|
94 | - |
|
95 | - return (0 == $this->_fields || empty($this->_fields) ? false : $this->_fields); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function getPostVars(): array |
|
102 | - { |
|
103 | - return ['sid', 'cid', 'gid', 'aids', 'abid', 'songid', 'title', 'lyrics', 'hits', 'rank', 'votes', 'tags', 'created', 'updated']; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param $criteria |
|
108 | - * @param bool $id_as_key |
|
109 | - * @param bool $as_object |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getFields($criteria, $id_as_key = true, $as_object = true): array |
|
113 | - { |
|
114 | - return $this->_fHandler->getObjects($criteria, $id_as_key, $as_object); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Insert a field in the database |
|
119 | - * |
|
120 | - * @param XoopsObject $field |
|
121 | - * @param bool $force |
|
122 | - * @return mixed|void |
|
123 | - */ |
|
124 | - public function insertField($field, $force = false) |
|
125 | - { |
|
126 | - return $this->_fHandler->insert($field, $force); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Delete a field from the database |
|
131 | - * |
|
132 | - * @param XoopsObject $field |
|
133 | - * @param bool $force |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function deleteField($field, $force = false) |
|
137 | - { |
|
138 | - return $this->_fHandler->delete($field, $force); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Save a new field in the database |
|
143 | - * |
|
144 | - * @param array $vars array of variables, taken from $module->loadInfo('Extras')['field'] |
|
145 | - * @param int $weight |
|
146 | - * @return string |
|
147 | - * @internal param int $categoryid ID of the category to add it to |
|
148 | - * @internal param int $type valuetype of the field |
|
149 | - * @internal param int $moduleid ID of the module, this field belongs to |
|
150 | - */ |
|
151 | - public function saveField($vars, $weight = 0): string |
|
152 | - { |
|
153 | - $field = $this->createField(); |
|
154 | - $field->setVar('field_name', $vars['name']); |
|
155 | - $field->setVar('field_valuetype', $vars['valuetype']); |
|
156 | - $field->setVar('field_type', $vars['type']); |
|
157 | - $field->setVar('field_weight', $weight); |
|
158 | - if (isset($vars['title'])) { |
|
159 | - $field->setVar('field_title', $vars['title']); |
|
160 | - } |
|
161 | - if (isset($vars['description'])) { |
|
162 | - $field->setVar('field_description', $vars['description']); |
|
163 | - } |
|
164 | - if (isset($vars['required'])) { |
|
165 | - $field->setVar('field_required', $vars['required']); //0 = no, 1 = yes |
|
166 | - } |
|
167 | - if (isset($vars['maxlength'])) { |
|
168 | - $field->setVar('field_maxlength', $vars['maxlength']); |
|
169 | - } |
|
170 | - if (isset($vars['default'])) { |
|
171 | - $field->setVar('field_default', $vars['default']); |
|
172 | - } |
|
173 | - if (isset($vars['notnull'])) { |
|
174 | - $field->setVar('field_notnull', $vars['notnull']); |
|
175 | - } |
|
176 | - if (isset($vars['show'])) { |
|
177 | - $field->setVar('field_show', $vars['show']); |
|
178 | - } |
|
179 | - if (isset($vars['edit'])) { |
|
180 | - $field->setVar('field_edit', $vars['edit']); |
|
181 | - } |
|
182 | - if (isset($vars['config'])) { |
|
183 | - $field->setVar('field_config', $vars['config']); |
|
184 | - } |
|
185 | - if (isset($vars['options'])) { |
|
186 | - $field->setVar('field_options', $vars['options']); |
|
187 | - } else { |
|
188 | - $field->setVar('field_options', []); |
|
189 | - } |
|
190 | - if ($this->insertField($field)) { |
|
191 | - $msg = ' Field <b>' . $vars['name'] . '</b> added to the database'; |
|
192 | - } else { |
|
193 | - $msg = ' <span style="color:#ff0000;">ERROR: Could not insert field <b>' . $vars['name'] . '</b> into the database. ' . \implode(' ', $field->getErrors()) . $this->db->error() . '</span>'; |
|
194 | - } |
|
195 | - unset($field); |
|
196 | - |
|
197 | - return $msg; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * insert a new object in the database |
|
202 | - * |
|
203 | - * @param \XoopsObject $obj reference to the object |
|
204 | - * @param bool $force whether to force the query execution despite security settings |
|
205 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
206 | - * |
|
207 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
208 | - */ |
|
209 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true): bool |
|
210 | - { |
|
211 | - $uservars = $this->getPostVars(); |
|
212 | - foreach ($uservars as $var) { |
|
213 | - if ('sid' != $var) { |
|
214 | - unset($obj->vars[$var]); |
|
215 | - } |
|
216 | - } |
|
217 | - if (0 == \count($obj->vars)) { |
|
218 | - return true; |
|
219 | - } |
|
220 | - |
|
221 | - return (bool)parent::insert($obj, $force, $checkObject); |
|
222 | - } |
|
14 | + /** |
|
15 | + * holds reference to {@link ObjectsFieldHandler} object |
|
16 | + */ |
|
17 | + public $_fHandler; |
|
18 | + /** |
|
19 | + * Array of {@link XoopsObjectsField} objects |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + public $_fields = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * ExtrasHandler constructor. |
|
26 | + * @param \XoopsDatabase $db |
|
27 | + */ |
|
28 | + public function __construct(XoopsDatabase $db) |
|
29 | + { |
|
30 | + parent::__construct($db, 'songlist_extra', Extras::class, 'sid'); |
|
31 | + $this->_fHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Field'); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * create a new {@link Extras} |
|
36 | + * |
|
37 | + * @param bool $isNew Flag the new objects as "new"? |
|
38 | + * |
|
39 | + * @return object {@link Extras} |
|
40 | + */ |
|
41 | + public function &create($isNew = true): object |
|
42 | + { |
|
43 | + $obj = new $this->className($this->loadFields()); |
|
44 | + $obj->handler = $this; |
|
45 | + $obj->setNew(); |
|
46 | + |
|
47 | + return $obj; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Get a {@link Extras} |
|
52 | + * |
|
53 | + * @param null $id |
|
54 | + * @param null $fields |
|
55 | + * @return object <a href='psi_element://Extras'>Extras</a> |
|
56 | + */ |
|
57 | + public function get($id = null, $fields = null): object //get($uid, $createOnFailure = true) |
|
58 | + { |
|
59 | + if (null === $fields) { |
|
60 | + $fields = true; |
|
61 | + } |
|
62 | + $obj = parent::get($id); |
|
63 | + if (!\is_object($obj) && $fields) { |
|
64 | + $obj = $this->create(); |
|
65 | + } |
|
66 | + |
|
67 | + return $obj; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Create new {@link ObjectsField} object |
|
72 | + * |
|
73 | + * @param bool $isNew |
|
74 | + * |
|
75 | + * @return object |
|
76 | + */ |
|
77 | + public function &createField($isNew = true): object |
|
78 | + { |
|
79 | + $return = $this->_fHandler->create($isNew); |
|
80 | + |
|
81 | + return $return; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Load field information |
|
86 | + * |
|
87 | + * @return array|false |
|
88 | + */ |
|
89 | + public function loadFields() |
|
90 | + { |
|
91 | + if (0 == \count($this->_fields)) { |
|
92 | + $this->_fields = $this->_fHandler->loadFields(); |
|
93 | + } |
|
94 | + |
|
95 | + return (0 == $this->_fields || empty($this->_fields) ? false : $this->_fields); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function getPostVars(): array |
|
102 | + { |
|
103 | + return ['sid', 'cid', 'gid', 'aids', 'abid', 'songid', 'title', 'lyrics', 'hits', 'rank', 'votes', 'tags', 'created', 'updated']; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param $criteria |
|
108 | + * @param bool $id_as_key |
|
109 | + * @param bool $as_object |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getFields($criteria, $id_as_key = true, $as_object = true): array |
|
113 | + { |
|
114 | + return $this->_fHandler->getObjects($criteria, $id_as_key, $as_object); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Insert a field in the database |
|
119 | + * |
|
120 | + * @param XoopsObject $field |
|
121 | + * @param bool $force |
|
122 | + * @return mixed|void |
|
123 | + */ |
|
124 | + public function insertField($field, $force = false) |
|
125 | + { |
|
126 | + return $this->_fHandler->insert($field, $force); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Delete a field from the database |
|
131 | + * |
|
132 | + * @param XoopsObject $field |
|
133 | + * @param bool $force |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function deleteField($field, $force = false) |
|
137 | + { |
|
138 | + return $this->_fHandler->delete($field, $force); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Save a new field in the database |
|
143 | + * |
|
144 | + * @param array $vars array of variables, taken from $module->loadInfo('Extras')['field'] |
|
145 | + * @param int $weight |
|
146 | + * @return string |
|
147 | + * @internal param int $categoryid ID of the category to add it to |
|
148 | + * @internal param int $type valuetype of the field |
|
149 | + * @internal param int $moduleid ID of the module, this field belongs to |
|
150 | + */ |
|
151 | + public function saveField($vars, $weight = 0): string |
|
152 | + { |
|
153 | + $field = $this->createField(); |
|
154 | + $field->setVar('field_name', $vars['name']); |
|
155 | + $field->setVar('field_valuetype', $vars['valuetype']); |
|
156 | + $field->setVar('field_type', $vars['type']); |
|
157 | + $field->setVar('field_weight', $weight); |
|
158 | + if (isset($vars['title'])) { |
|
159 | + $field->setVar('field_title', $vars['title']); |
|
160 | + } |
|
161 | + if (isset($vars['description'])) { |
|
162 | + $field->setVar('field_description', $vars['description']); |
|
163 | + } |
|
164 | + if (isset($vars['required'])) { |
|
165 | + $field->setVar('field_required', $vars['required']); //0 = no, 1 = yes |
|
166 | + } |
|
167 | + if (isset($vars['maxlength'])) { |
|
168 | + $field->setVar('field_maxlength', $vars['maxlength']); |
|
169 | + } |
|
170 | + if (isset($vars['default'])) { |
|
171 | + $field->setVar('field_default', $vars['default']); |
|
172 | + } |
|
173 | + if (isset($vars['notnull'])) { |
|
174 | + $field->setVar('field_notnull', $vars['notnull']); |
|
175 | + } |
|
176 | + if (isset($vars['show'])) { |
|
177 | + $field->setVar('field_show', $vars['show']); |
|
178 | + } |
|
179 | + if (isset($vars['edit'])) { |
|
180 | + $field->setVar('field_edit', $vars['edit']); |
|
181 | + } |
|
182 | + if (isset($vars['config'])) { |
|
183 | + $field->setVar('field_config', $vars['config']); |
|
184 | + } |
|
185 | + if (isset($vars['options'])) { |
|
186 | + $field->setVar('field_options', $vars['options']); |
|
187 | + } else { |
|
188 | + $field->setVar('field_options', []); |
|
189 | + } |
|
190 | + if ($this->insertField($field)) { |
|
191 | + $msg = ' Field <b>' . $vars['name'] . '</b> added to the database'; |
|
192 | + } else { |
|
193 | + $msg = ' <span style="color:#ff0000;">ERROR: Could not insert field <b>' . $vars['name'] . '</b> into the database. ' . \implode(' ', $field->getErrors()) . $this->db->error() . '</span>'; |
|
194 | + } |
|
195 | + unset($field); |
|
196 | + |
|
197 | + return $msg; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * insert a new object in the database |
|
202 | + * |
|
203 | + * @param \XoopsObject $obj reference to the object |
|
204 | + * @param bool $force whether to force the query execution despite security settings |
|
205 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
206 | + * |
|
207 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
208 | + */ |
|
209 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true): bool |
|
210 | + { |
|
211 | + $uservars = $this->getPostVars(); |
|
212 | + foreach ($uservars as $var) { |
|
213 | + if ('sid' != $var) { |
|
214 | + unset($obj->vars[$var]); |
|
215 | + } |
|
216 | + } |
|
217 | + if (0 == \count($obj->vars)) { |
|
218 | + return true; |
|
219 | + } |
|
220 | + |
|
221 | + return (bool)parent::insert($obj, $force, $checkObject); |
|
222 | + } |
|
223 | 223 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function get($id = null, $fields = null): object //get($uid, $createOnFailure = true) |
58 | 58 | { |
59 | - if (null === $fields) { |
|
59 | + if (null===$fields) { |
|
60 | 60 | $fields = true; |
61 | 61 | } |
62 | 62 | $obj = parent::get($id); |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function loadFields() |
90 | 90 | { |
91 | - if (0 == \count($this->_fields)) { |
|
91 | + if (0==\count($this->_fields)) { |
|
92 | 92 | $this->_fields = $this->_fHandler->loadFields(); |
93 | 93 | } |
94 | 94 | |
95 | - return (0 == $this->_fields || empty($this->_fields) ? false : $this->_fields); |
|
95 | + return (0==$this->_fields || empty($this->_fields) ? false : $this->_fields); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | $field->setVar('field_options', []); |
189 | 189 | } |
190 | 190 | if ($this->insertField($field)) { |
191 | - $msg = ' Field <b>' . $vars['name'] . '</b> added to the database'; |
|
191 | + $msg = ' Field <b>'.$vars['name'].'</b> added to the database'; |
|
192 | 192 | } else { |
193 | - $msg = ' <span style="color:#ff0000;">ERROR: Could not insert field <b>' . $vars['name'] . '</b> into the database. ' . \implode(' ', $field->getErrors()) . $this->db->error() . '</span>'; |
|
193 | + $msg = ' <span style="color:#ff0000;">ERROR: Could not insert field <b>'.$vars['name'].'</b> into the database. '.\implode(' ', $field->getErrors()).$this->db->error().'</span>'; |
|
194 | 194 | } |
195 | 195 | unset($field); |
196 | 196 | |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | { |
211 | 211 | $uservars = $this->getPostVars(); |
212 | 212 | foreach ($uservars as $var) { |
213 | - if ('sid' != $var) { |
|
213 | + if ('sid'!=$var) { |
|
214 | 214 | unset($obj->vars[$var]); |
215 | 215 | } |
216 | 216 | } |
217 | - if (0 == \count($obj->vars)) { |
|
217 | + if (0==\count($obj->vars)) { |
|
218 | 218 | return true; |
219 | 219 | } |
220 | 220 | |
221 | - return (bool)parent::insert($obj, $force, $checkObject); |
|
221 | + return (bool) parent::insert($obj, $force, $checkObject); |
|
222 | 222 | } |
223 | 223 | } |
@@ -7,165 +7,165 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class CategoryHandler extends \XoopsPersistableObjectHandler |
9 | 9 | { |
10 | - /** |
|
11 | - * CategoryHandler constructor. |
|
12 | - * @param \XoopsDatabase $db |
|
13 | - */ |
|
14 | - public function __construct(\XoopsDatabase $db) |
|
15 | - { |
|
16 | - parent::__construct($db, 'songlist_category', Category::class, 'cid', 'name'); |
|
17 | - } |
|
18 | - |
|
19 | - /** |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function filterFields(): array |
|
23 | - { |
|
24 | - return ['cid', 'pid', 'weight', 'name', 'image', 'path', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated']; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * @param $filter |
|
29 | - * @return \CriteriaCompo |
|
30 | - */ |
|
31 | - public function getFilterCriteria($filter): \CriteriaCompo |
|
32 | - { |
|
33 | - $parts = \explode('|', $filter); |
|
34 | - $criteria = new \CriteriaCompo(); |
|
35 | - foreach ($parts as $part) { |
|
36 | - $var = \explode(',', $part); |
|
37 | - if (!empty($var[1]) && !\is_numeric($var[0])) { |
|
38 | - $object = $this->create(); |
|
39 | - if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
40 | - || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
41 | - $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
42 | - } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
|
43 | - $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
44 | - } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
45 | - $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
46 | - } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
47 | - $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
48 | - } |
|
49 | - } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
|
50 | - $criteria->add(new \Criteria($var[0], $var[1])); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return $criteria; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param $filter |
|
59 | - * @param $field |
|
60 | - * @param string $sort |
|
61 | - * @param string $op |
|
62 | - * @param string $fct |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string |
|
66 | - { |
|
67 | - $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct); |
|
68 | - if (\is_object($ele)) { |
|
69 | - return $ele->render(); |
|
70 | - } |
|
71 | - |
|
72 | - return ' '; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param int $pid |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function GetCatAndSubCat($pid = 0) |
|
80 | - { |
|
81 | - $categories = $this->getObjects(new \Criteria('pid', $pid), true); |
|
82 | - $langs_array = $this->TreeIDs([], $categories, -1); |
|
83 | - |
|
84 | - return $langs_array; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param $langs_array |
|
89 | - * @param $categories |
|
90 | - * @param $level |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - private function TreeIDs($langs_array, $categories, $level) |
|
94 | - { |
|
95 | - foreach ($categories as $catid => $category) { |
|
96 | - $langs_array[$catid] = $catid; |
|
97 | - $categoriesb = $this->getObjects(new \Criteria('pid', $catid), true); |
|
98 | - if ($categoriesb) { |
|
99 | - $langs_array = $this->TreeIDs($langs_array, $categoriesb, $level); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return $langs_array; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param bool $force |
|
108 | - * @return bool|mixed |
|
109 | - */ |
|
110 | - public function insert(\XoopsObject $obj, $force = true) |
|
111 | - { |
|
112 | - if ($obj->isNew()) { |
|
113 | - $obj->setVar('created', \time()); |
|
114 | - } else { |
|
115 | - $obj->setVar('updated', \time()); |
|
116 | - } |
|
117 | - if ('' == $obj->getVar('name')) { |
|
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - return parent::insert($obj, $force); |
|
122 | - } |
|
123 | - |
|
124 | - public $_objects = ['object' => [], 'array' => []]; |
|
125 | - |
|
126 | - /** |
|
127 | - * @param null $id |
|
128 | - * @param null $fields |
|
129 | - * @return \XoopsObject |
|
130 | - */ |
|
131 | - public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*') |
|
132 | - { |
|
133 | - $fields = $fields ?: '*'; |
|
134 | - if (!isset($this->_objects['object'][$id])) { |
|
135 | - $this->_objects['object'][$id] = parent::get($id, $fields); |
|
136 | - if (!isset($GLOBALS['songlistAdmin'])) { |
|
137 | - $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $id; |
|
138 | - $GLOBALS['xoopsDB']->queryF($sql); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - return $this->_objects['object'][$id]; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param \XoopsObject $object |
|
147 | - * @param bool $force |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function delete(\XoopsObject $object, $force = true): bool |
|
151 | - { |
|
152 | - parent::delete($object, $force); |
|
153 | - $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `cid` = 0 WHERE `cid` = ' . $object->getVar('cid'); |
|
154 | - |
|
155 | - return $GLOBALS['xoopsDB']->queryF($sql); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param \CriteriaElement|\CriteriaCompo $criteria |
|
160 | - * @param bool $id_as_key |
|
161 | - * @param bool $as_object |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array |
|
165 | - { |
|
166 | - $ret = parent::getObjects($criteria, $id_as_key, $as_object); |
|
167 | - |
|
168 | - /*if (!isset($GLOBALS['songlistAdmin'])) { |
|
10 | + /** |
|
11 | + * CategoryHandler constructor. |
|
12 | + * @param \XoopsDatabase $db |
|
13 | + */ |
|
14 | + public function __construct(\XoopsDatabase $db) |
|
15 | + { |
|
16 | + parent::__construct($db, 'songlist_category', Category::class, 'cid', 'name'); |
|
17 | + } |
|
18 | + |
|
19 | + /** |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function filterFields(): array |
|
23 | + { |
|
24 | + return ['cid', 'pid', 'weight', 'name', 'image', 'path', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated']; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * @param $filter |
|
29 | + * @return \CriteriaCompo |
|
30 | + */ |
|
31 | + public function getFilterCriteria($filter): \CriteriaCompo |
|
32 | + { |
|
33 | + $parts = \explode('|', $filter); |
|
34 | + $criteria = new \CriteriaCompo(); |
|
35 | + foreach ($parts as $part) { |
|
36 | + $var = \explode(',', $part); |
|
37 | + if (!empty($var[1]) && !\is_numeric($var[0])) { |
|
38 | + $object = $this->create(); |
|
39 | + if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
40 | + || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
41 | + $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
42 | + } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
|
43 | + $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
44 | + } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
45 | + $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
46 | + } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
47 | + $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
48 | + } |
|
49 | + } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
|
50 | + $criteria->add(new \Criteria($var[0], $var[1])); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return $criteria; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param $filter |
|
59 | + * @param $field |
|
60 | + * @param string $sort |
|
61 | + * @param string $op |
|
62 | + * @param string $fct |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string |
|
66 | + { |
|
67 | + $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct); |
|
68 | + if (\is_object($ele)) { |
|
69 | + return $ele->render(); |
|
70 | + } |
|
71 | + |
|
72 | + return ' '; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param int $pid |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function GetCatAndSubCat($pid = 0) |
|
80 | + { |
|
81 | + $categories = $this->getObjects(new \Criteria('pid', $pid), true); |
|
82 | + $langs_array = $this->TreeIDs([], $categories, -1); |
|
83 | + |
|
84 | + return $langs_array; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param $langs_array |
|
89 | + * @param $categories |
|
90 | + * @param $level |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + private function TreeIDs($langs_array, $categories, $level) |
|
94 | + { |
|
95 | + foreach ($categories as $catid => $category) { |
|
96 | + $langs_array[$catid] = $catid; |
|
97 | + $categoriesb = $this->getObjects(new \Criteria('pid', $catid), true); |
|
98 | + if ($categoriesb) { |
|
99 | + $langs_array = $this->TreeIDs($langs_array, $categoriesb, $level); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return $langs_array; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param bool $force |
|
108 | + * @return bool|mixed |
|
109 | + */ |
|
110 | + public function insert(\XoopsObject $obj, $force = true) |
|
111 | + { |
|
112 | + if ($obj->isNew()) { |
|
113 | + $obj->setVar('created', \time()); |
|
114 | + } else { |
|
115 | + $obj->setVar('updated', \time()); |
|
116 | + } |
|
117 | + if ('' == $obj->getVar('name')) { |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + return parent::insert($obj, $force); |
|
122 | + } |
|
123 | + |
|
124 | + public $_objects = ['object' => [], 'array' => []]; |
|
125 | + |
|
126 | + /** |
|
127 | + * @param null $id |
|
128 | + * @param null $fields |
|
129 | + * @return \XoopsObject |
|
130 | + */ |
|
131 | + public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*') |
|
132 | + { |
|
133 | + $fields = $fields ?: '*'; |
|
134 | + if (!isset($this->_objects['object'][$id])) { |
|
135 | + $this->_objects['object'][$id] = parent::get($id, $fields); |
|
136 | + if (!isset($GLOBALS['songlistAdmin'])) { |
|
137 | + $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $id; |
|
138 | + $GLOBALS['xoopsDB']->queryF($sql); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + return $this->_objects['object'][$id]; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param \XoopsObject $object |
|
147 | + * @param bool $force |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function delete(\XoopsObject $object, $force = true): bool |
|
151 | + { |
|
152 | + parent::delete($object, $force); |
|
153 | + $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `cid` = 0 WHERE `cid` = ' . $object->getVar('cid'); |
|
154 | + |
|
155 | + return $GLOBALS['xoopsDB']->queryF($sql); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param \CriteriaElement|\CriteriaCompo $criteria |
|
160 | + * @param bool $id_as_key |
|
161 | + * @param bool $as_object |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array |
|
165 | + { |
|
166 | + $ret = parent::getObjects($criteria, $id_as_key, $as_object); |
|
167 | + |
|
168 | + /*if (!isset($GLOBALS['songlistAdmin'])) { |
|
169 | 169 | $id = []; |
170 | 170 | foreach($ret as $data) { |
171 | 171 | if ($as_object==true) { |
@@ -186,25 +186,25 @@ discard block |
||
186 | 186 | $GLOBALS['xoopsDB']->queryF($sql); |
187 | 187 | }*/ |
188 | 188 | |
189 | - return $ret; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param int $limit |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function getTop($limit = 1): array |
|
197 | - { |
|
198 | - $sql = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit; |
|
199 | - $results = $GLOBALS['xoopsDB']->queryF($sql); |
|
200 | - $ret = []; |
|
201 | - $i = 0; |
|
202 | - while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) { |
|
203 | - $ret[$i] = $this->create(); |
|
204 | - $ret[$i]->assignVars($row); |
|
205 | - ++$i; |
|
206 | - } |
|
207 | - |
|
208 | - return $ret; |
|
209 | - } |
|
189 | + return $ret; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param int $limit |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function getTop($limit = 1): array |
|
197 | + { |
|
198 | + $sql = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit; |
|
199 | + $results = $GLOBALS['xoopsDB']->queryF($sql); |
|
200 | + $ret = []; |
|
201 | + $i = 0; |
|
202 | + while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) { |
|
203 | + $ret[$i] = $this->create(); |
|
204 | + $ret[$i]->assignVars($row); |
|
205 | + ++$i; |
|
206 | + } |
|
207 | + |
|
208 | + return $ret; |
|
209 | + } |
|
210 | 210 | } |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | $var = \explode(',', $part); |
37 | 37 | if (!empty($var[1]) && !\is_numeric($var[0])) { |
38 | 38 | $object = $this->create(); |
39 | - if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
40 | - || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
41 | - $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
39 | + if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type'] |
|
40 | + || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) { |
|
41 | + $criteria->add(new \Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE'))); |
|
42 | 42 | } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
43 | - $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
44 | - } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
45 | - $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
46 | - } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
47 | - $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
43 | + $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '='))); |
|
44 | + } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) { |
|
45 | + $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '='))); |
|
46 | + } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) { |
|
47 | + $criteria->add(new \Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE'))); |
|
48 | 48 | } |
49 | 49 | } elseif (!empty($var[1]) && \is_numeric($var[0])) { |
50 | 50 | $criteria->add(new \Criteria($var[0], $var[1])); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } else { |
115 | 115 | $obj->setVar('updated', \time()); |
116 | 116 | } |
117 | - if ('' == $obj->getVar('name')) { |
|
117 | + if (''==$obj->getVar('name')) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | if (!isset($this->_objects['object'][$id])) { |
135 | 135 | $this->_objects['object'][$id] = parent::get($id, $fields); |
136 | 136 | if (!isset($GLOBALS['songlistAdmin'])) { |
137 | - $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $id; |
|
137 | + $sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$id; |
|
138 | 138 | $GLOBALS['xoopsDB']->queryF($sql); |
139 | 139 | } |
140 | 140 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | public function delete(\XoopsObject $object, $force = true): bool |
151 | 151 | { |
152 | 152 | parent::delete($object, $force); |
153 | - $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `cid` = 0 WHERE `cid` = ' . $object->getVar('cid'); |
|
153 | + $sql = 'UPDATE '.$GLOBALS['xoopsDB']->prefix('songlist_songs').' SET `cid` = 0 WHERE `cid` = '.$object->getVar('cid'); |
|
154 | 154 | |
155 | 155 | return $GLOBALS['xoopsDB']->queryF($sql); |
156 | 156 | } |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function getTop($limit = 1): array |
197 | 197 | { |
198 | - $sql = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit; |
|
198 | + $sql = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit; |
|
199 | 199 | $results = $GLOBALS['xoopsDB']->queryF($sql); |
200 | 200 | $ret = []; |
201 | 201 | $i = 0; |
202 | - while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) { |
|
202 | + while (false!==($row = $GLOBALS['xoopsDB']->fetchArray($results))) { |
|
203 | 203 | $ret[$i] = $this->create(); |
204 | 204 | $ret[$i]->assignVars($row); |
205 | 205 | ++$i; |