FormController::getFormVoice()   F
last analyzed

Complexity

Conditions 22
Paths 256

Size

Total Lines 70
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 22
eloc 48
c 1
b 0
f 0
nc 256
nop 2
dl 0
loc 70
rs 2.6333

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Songlist\Form;
4
5
6
use Xmf\Request;
7
use XoopsModules\Songlist;
8
//use XoopsModules\Songlist\Form\SelectAlbumForm;
9
//use XoopsModules\Songlist\Form\SelectArtistForm;
10
//use XoopsModules\Songlist\Form\SelectCategoryForm;
11
//use XoopsModules\Songlist\Form\SelectGenreForm;
12
//use XoopsModules\Songlist\Form\SelectVoiceForm;
13
use XoopsModules\Songlist\Helper;
14
15
xoops_loadLanguage('user');
16
17
class FormController
18
{
19
    /**
20
     * Get {@link XoopsThemeForm} for adding/editing fields
21
     *
22
     * @param object $field  {@link ProfileField} object to get edit form for
23
     * @param mixed  $action URL to submit to - or false for $_SERVER['SCRIPT_NAME']
24
     *
25
     * @return object
26
     */
27
    public static function getFieldForm($field, $action = false)
28
    {
29
        if (false === $action) {
30
            $action = $_SERVER['SCRIPT_NAME'];
31
        }
32
33
        $helper = Helper::getInstance();
34
        $helper->loadLanguage('forms');
35
36
        $title = $field->isNew() ? sprintf(_FRM_SONGLIST_FIELDS_ADD, _FRM_SONGLIST_FIELDS_FIELD) : sprintf(_FRM_SONGLIST_FIELDS_EDIT, _FRM_SONGLIST_FIELDS_FIELD);
37
38
        xoops_load('XoopsFormLoader');
39
40
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
41
42
        $form->addElement(new \XoopsFormText(_FRM_SONGLIST_FIELDS_TITLE, 'field_title', 35, 255, $field->getVar('field_title', 'e')));
43
        $form->addElement(new \XoopsFormTextArea(_FRM_SONGLIST_FIELDS_DESCRIPTION, 'field_description', $field->getVar('field_description', 'e')));
44
45
        if ($field->isNew()) {
46
            $fieldcid = [1 => 0];
47
        } else {
48
            $fieldcid = $field->getVar('cids');
49
        }
50
        $categoryHandler = Helper::getInstance()
51
                                 ->getHandler('Category');
52
        $cat_select      = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_CATEGORY, 'cids', $fieldcid, 7, true);
53
        $cat_select->addOption(0, _FRM_SONGLIST_FIELDS_DEFAULT);
54
        foreach ($categoryHandler->getObjects(null, true) as $cid => $category) {
55
            $cat_select->addOption($cid, $category->getVar('name'));
56
        }
57
        $form->addElement($cat_select);
58
        $form->addElement(new \XoopsFormText(_FRM_SONGLIST_FIELDS_WEIGHT, 'field_weight', 10, 10, $field->getVar('field_weight', 'e')));
59
        if ($field->getVar('field_config') || $field->isNew()) {
60
            if ($field->isNew()) {
61
                $form->addElement(new \XoopsFormText(_FRM_SONGLIST_FIELDS_NAME, 'field_name', 35, 255, $field->getVar('field_name', 'e')));
62
            } else {
63
                $form->addElement(new \XoopsFormLabel(_FRM_SONGLIST_FIELDS_NAME, $field->getVar('field_name')));
64
                $form->addElement(new \XoopsFormHidden('id', $field->getVar('field_id')));
65
            }
66
67
            //autotext and theme left out of this one as fields of that type should never be changed (valid assumption, I think)
68
            $fieldtypes = [
69
                'checkbox'     => _FRM_SONGLIST_FIELDS_CHECKBOX,
70
                'date'         => _FRM_SONGLIST_FIELDS_DATE,
71
                'datetime'     => _FRM_SONGLIST_FIELDS_DATETIME,
72
                'longdate'     => _FRM_SONGLIST_FIELDS_LONGDATE,
73
                'group'        => _FRM_SONGLIST_FIELDS_GROUP,
74
                'group_multi'  => _FRM_SONGLIST_FIELDS_GROUPMULTI,
75
                'language'     => _FRM_SONGLIST_FIELDS_LANGUAGE,
76
                'radio'        => _FRM_SONGLIST_FIELDS_RADIO,
77
                'select'       => _FRM_SONGLIST_FIELDS_SELECT,
78
                'select_multi' => _FRM_SONGLIST_FIELDS_SELECTMULTI,
79
                'textarea'     => _FRM_SONGLIST_FIELDS_TEXTAREA,
80
                'dhtml'        => _FRM_SONGLIST_FIELDS_DHTMLTEXTAREA,
81
                'textbox'      => _FRM_SONGLIST_FIELDS_TEXTBOX,
82
                'timezone'     => _FRM_SONGLIST_FIELDS_TIMEZONE,
83
                'yesno'        => _FRM_SONGLIST_FIELDS_YESNO,
84
            ];
85
86
            $element_select = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_TYPE, 'field_type', $field->getVar('field_type', 'e'));
87
            $element_select->addOptionArray($fieldtypes);
88
89
            $form->addElement($element_select);
90
91
            switch ($field->getVar('field_type')) {
92
                case 'textbox':
93
                    $valuetypes = [
94
                        XOBJ_DTYPE_ARRAY   => _FRM_SONGLIST_FIELDS_ARRAY,
95
                        XOBJ_DTYPE_EMAIL   => _FRM_SONGLIST_FIELDS_EMAIL,
96
                        XOBJ_DTYPE_INT     => _FRM_SONGLIST_FIELDS_INT,
97
                        XOBJ_DTYPE_FLOAT   => _FRM_SONGLIST_FIELDS_FLOAT,
98
                        XOBJ_DTYPE_DECIMAL => _FRM_SONGLIST_FIELDS_DECIMAL,
99
                        XOBJ_DTYPE_TXTAREA => _FRM_SONGLIST_FIELDS_TXTAREA,
100
                        XOBJ_DTYPE_TXTBOX  => _FRM_SONGLIST_FIELDS_TXTBOX,
101
                        XOBJ_DTYPE_URL     => _FRM_SONGLIST_FIELDS_URL,
102
                        XOBJ_DTYPE_OTHER   => _FRM_SONGLIST_FIELDS_OTHER,
103
                    ];
104
105
                    $type_select = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_VALUETYPE, 'field_valuetype', $field->getVar('field_valuetype', 'e'));
106
                    $type_select->addOptionArray($valuetypes);
107
                    $form->addElement($type_select);
108
                    break;
109
                case 'select':
110
                case 'radio':
111
                    $valuetypes = [
112
                        XOBJ_DTYPE_ARRAY   => _FRM_SONGLIST_FIELDS_ARRAY,
113
                        XOBJ_DTYPE_EMAIL   => _FRM_SONGLIST_FIELDS_EMAIL,
114
                        XOBJ_DTYPE_INT     => _FRM_SONGLIST_FIELDS_INT,
115
                        XOBJ_DTYPE_FLOAT   => _FRM_SONGLIST_FIELDS_FLOAT,
116
                        XOBJ_DTYPE_DECIMAL => _FRM_SONGLIST_FIELDS_DECIMAL,
117
                        XOBJ_DTYPE_TXTAREA => _FRM_SONGLIST_FIELDS_TXTAREA,
118
                        XOBJ_DTYPE_TXTBOX  => _FRM_SONGLIST_FIELDS_TXTBOX,
119
                        XOBJ_DTYPE_URL     => _FRM_SONGLIST_FIELDS_URL,
120
                        XOBJ_DTYPE_OTHER   => _FRM_SONGLIST_FIELDS_OTHER,
121
                    ];
122
123
                    $type_select = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_VALUETYPE, 'field_valuetype', $field->getVar('field_valuetype', 'e'));
124
                    $type_select->addOptionArray($valuetypes);
125
                    $form->addElement($type_select);
126
                    break;
127
            }
128
129
            //$form->addElement(new \XoopsFormRadioYN(_FRM_SONGLIST_FIELDS_NOTNULL, 'field_notnull', $field->getVar('field_notnull', 'e') ));
130
131
            if ('select' === $field->getVar('field_type') || 'select_multi' === $field->getVar('field_type') || 'radio' === $field->getVar('field_type') || 'checkbox' === $field->getVar('field_type')) {
132
                $options = $field->getVar('field_options');
133
                if (count($options) > 0) {
134
                    $remove_options          = new \XoopsFormCheckBox(_FRM_SONGLIST_FIELDS_REMOVEOPTIONS, 'removeOptions');
135
                    $remove_options->columns = 3;
136
                    asort($options);
137
                    foreach (array_keys($options) as $key) {
138
                        $options[$key] .= "[{$key}]";
139
                    }
140
                    $remove_options->addOptionArray($options);
141
                    $form->addElement($remove_options);
142
                }
143
144
                $option_text = "<table  cellspacing='1'><tr><td width='20%'>" . _FRM_SONGLIST_FIELDS_KEY . '</td><td>' . _FRM_SONGLIST_FIELDS_VALUE . '</td></tr>';
145
                for ($i = 0; $i < 3; ++$i) {
146
                    $option_text .= "<tr><td><input type='text' name='addOption[{$i}][key]' id='addOption[{$i}][key]' size='15'></td><td><input type='text' name='addOption[{$i}][value]' id='addOption[{$i}][value]' size='35'></td></tr>";
147
                    $option_text .= "<tr height='3px'><td colspan='2'> </td></tr>";
148
                }
149
                $option_text .= '</table>';
150
                $form->addElement(new \XoopsFormLabel(_FRM_SONGLIST_FIELDS_ADDOPTION, $option_text));
151
            }
152
        }
153
154
        if ($field->getVar('field_edit')) {
155
            switch ($field->getVar('field_type')) {
156
                case 'textbox':
157
                case 'textarea':
158
                case 'dhtml':
159
                    $form->addElement(new \XoopsFormText(_FRM_SONGLIST_FIELDS_MAXLENGTH, 'field_maxlength', 35, 35, $field->getVar('field_maxlength', 'e')));
160
                    $form->addElement(new \XoopsFormTextArea(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
161
                    break;
162
                case 'checkbox':
163
                case 'select_multi':
164
                    $def_value = null !== $field->getVar('field_default', 'e') ? unserialize(($field->getVar('field_default', 'n')) ?? '') : null;
165
                    $element   = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $def_value, 8, true);
166
                    $options   = $field->getVar('field_options');
167
                    asort($options);
168
                    // If options do not include an empty element, then add a blank option to prevent any default selection
169
                    if (!array_key_exists('', $options)) {
170
                        $element->addOption('', _NONE);
171
                    }
172
                    $element->addOptionArray($options);
173
                    $form->addElement($element);
174
                    break;
175
                case 'select':
176
                case 'radio':
177
                    $def_value = null !== $field->getVar('field_default', 'e') ? $field->getVar('field_default') : null;
178
                    $element   = new \XoopsFormSelect(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $def_value);
179
                    $options   = $field->getVar('field_options');
180
                    asort($options);
181
                    // If options do not include an empty element, then add a blank option to prevent any default selection
182
                    if (!array_key_exists('', $options)) {
183
                        $element->addOption('', _NONE);
184
                    }
185
                    $element->addOptionArray($options);
186
                    $form->addElement($element);
187
                    break;
188
                case 'date':
189
                    $form->addElement(new \XoopsFormTextDateSelect(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', 15, $field->getVar('field_default', 'e')));
190
                    break;
191
                case 'longdate':
192
                    $form->addElement(new \XoopsFormTextDateSelect(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', 15, strtotime($field->getVar('field_default', 'e'))));
193
                    break;
194
                case 'datetime':
195
                    $form->addElement(new \XoopsFormDateTime(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', 15, $field->getVar('field_default', 'e')));
196
                    break;
197
                case 'yesno':
198
                    $form->addElement(new \XoopsFormRadioYN(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
199
                    break;
200
                case 'timezone':
201
                    $form->addElement(new \XoopsFormSelectTimezone(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
202
                    break;
203
                case 'language':
204
                    $form->addElement(new \XoopsFormSelectLang(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
205
                    break;
206
                case 'group':
207
                    $form->addElement(new \XoopsFormSelectGroup(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', true, $field->getVar('field_default', 'e')));
208
                    break;
209
                case 'group_multi':
210
                    $form->addElement(new \XoopsFormSelectGroup(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', true, $field->getVar('field_default', 'e'), 5, true));
211
                    break;
212
                case 'theme':
213
                    $form->addElement(new \XoopsFormSelectTheme(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
214
                    break;
215
                case 'autotext':
216
                    $form->addElement(new \XoopsFormTextArea(_FRM_SONGLIST_FIELDS_DEFAULT, 'field_default', $field->getVar('field_default', 'e')));
217
                    break;
218
            }
219
        }
220
221
        /** @var \XoopsGroupPermHandler $grouppermHandler */
222
        $grouppermHandler = xoops_getHandler('groupperm');
223
        $searchable_types = [
224
            'textbox',
225
            'select',
226
            'radio',
227
            'yesno',
228
            'date',
229
            'datetime',
230
            'timezone',
231
            'language',
232
        ];
233
        if (in_array($field->getVar('field_type'), $searchable_types, true)) {
234
            $search_groups = $grouppermHandler->getGroupIds('songlist_search', $field->getVar('field_id'), $GLOBALS['songlistModule']->getVar('mid'));
235
            $form->addElement(new \XoopsFormSelectGroup(_FRM_SONGLIST_FIELDS_PROF_SEARCH, 'songlist_search', true, $search_groups, 5, true));
236
        }
237
        if ($field->getVar('field_edit') || $field->isNew()) {
238
            if ($field->isNew()) {
239
                $editable_groups = [];
240
            } else {
241
                //Load groups
242
                $editable_groups = $grouppermHandler->getGroupIds('songlist_edit', $field->getVar('field_id'), $GLOBALS['songlistModule']->getVar('mid'));
243
            }
244
            $form->addElement(new \XoopsFormSelectGroup(_FRM_SONGLIST_FIELDS_PROF_EDITABLE, 'songlist_edit', false, $editable_groups, 5, true));
245
//            $form->addElement($steps_select);
246
        }
247
        $form->addElement(new \XoopsFormHidden('op', 'save'));
248
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
249
250
        return $form;
251
    }
252
253
    /**
254
     * Get {@link XoopsThemeForm} for editing a user
255
     *
256
     * @param bool $action
257
     * @return object
258
     * @internal param object $user <a href='psi_element://XoopsUser'>XoopsUser</a> to edit to edit
259
     */
260
    public static function getUserSearchForm($action = false)
261
    {
262
        xoops_loadLanguage('forms', 'songlist');
263
264
        if (!$action) {
265
            $action = $_SERVER['SCRIPT_NAME'];
266
        }
267
        if (empty($GLOBALS['xoopsConfigUser'])) {
268
            /** @var \XoopsConfigHandler $configHandler */
269
            $configHandler              = xoops_getHandler('config');
270
            $GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
271
        }
272
273
        $helper = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
274
275
        $title = _FRM_SONGLIST_FIELDS_SEARCH;
276
277
        $form = new \XoopsThemeForm($title, 'search', $action, 'post', true);
278
279
        $songlistHandler = Helper::getInstance()
280
                                 ->getHandler('Profile', 'objects');
0 ignored issues
show
Unused Code introduced by
The call to XoopsModules\Songlist\Helper::getHandler() has too many arguments starting with 'objects'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

280
                                 ->/** @scrutinizer ignore-call */ getHandler('Profile', 'objects');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
281
        // Get fields
282
        $fields = $songlistHandler->loadFields();
283
284
        /** @var \XoopsGroupPermHandler $grouppermHandler */
285
        $grouppermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Unused Code introduced by
The assignment to $grouppermHandler is dead and can be removed.
Loading history...
286
        /** @var \XoopsConfigHandler $configHandler */
287
        $configHandler = xoops_getHandler('config');
0 ignored issues
show
Unused Code introduced by
The assignment to $configHandler is dead and can be removed.
Loading history...
288
        $groups        = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS];
289
        /** @var \XoopsModuleHandler $moduleHandler */
290
        $moduleHandler = xoops_getHandler('module');
291
        $xoModule      = $moduleHandler->getByDirname('objects');
292
        $modid         = $xoModule->getVar('mid');
293
294
        // Get ids of fields that can be edited
295
        /** @var \XoopsGroupPermHandler $grouppermHandler */
296
        $grouppermHandler = xoops_getHandler('groupperm');
297
298
        $editable_fields = $grouppermHandler->getItemIds('songlist_search', $groups, $modid);
299
300
        $catHandler = Helper::getInstance()
301
                            ->getHandler('Category');
302
303
        $selcat = new \XoopsFormSelect('Form', 'cid', !empty($_REQUEST['cid']) ? Request::getInt('cid', 0, 'REQUEST') : 0, 1, false, false, false, true);
0 ignored issues
show
Unused Code introduced by
The call to XoopsFormSelect::__construct() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

303
        $selcat = /** @scrutinizer ignore-call */ new \XoopsFormSelect('Form', 'cid', !empty($_REQUEST['cid']) ? Request::getInt('cid', 0, 'REQUEST') : 0, 1, false, false, false, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
304
        $selcat->setExtra(' onChange="window.location=\'' . XOOPS_URL . '/modules/objects/search.php?op=search&fct=form&cid=\'+document.search.cid.options[document.search.cid.selectedIndex].value"');
305
306
        $form->addElement($selcat, true);
307
308
        $categories = [];
309
310
        $criteria       = new \CriteriaCompo(new \Criteria('cid', !empty($_REQUEST['cid']) ? Request::getInt('cid', 0, 'REQUEST') : '0'), 'OR');
311
        $all_categories = $catHandler->getObjects($criteria, true, false);
312
        $count_fields   = count($fields);
313
314
        foreach (array_keys($fields) as $i) {
315
            if (in_array($fields[$i]->getVar('field_id'), $editable_fields, true)) {
316
                // Set default value for user fields if available
317
                $fieldinfo['element']  = $fields[$i]->getSearchElement();
318
                $fieldinfo['required'] = false;
319
320
                foreach ($fields[$i]->getVar('cids') as $catidid => $cid) {
321
                    if (array_key_exists($cid, $all_categories)) {
322
                        $key              = $all_categories[$cid]['cat_weight'] * $count_fields + $cid;
323
                        $elements[$key][] = $fieldinfo;
324
                        $weights[$key][]  = $fields[$i]->getVar('field_weight');
325
                        $categories[$key] = $all_categories[$cid];
326
                    } elseif (in_array(0, $fields[$i]->getVar('cids'), true)) {
327
                        $key              = $all_categories[$cid]['cat_weight'] * $count_fields + $cid;
328
                        $elements[$key][] = $fieldinfo;
329
                        $weights[$key][]  = $fields[$i]->getVar('field_weight');
330
                        $categories[$key] = $all_categories[$cid];
331
                    }
332
                }
333
            }
334
        }
335
336
        ksort($elements);
337
        foreach (array_keys($elements) as $k) {
338
            array_multisort($weights[$k], SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
0 ignored issues
show
Bug introduced by
XoopsModules\Songlist\Form\SORT_ASC cannot be passed to array_multisort() as the parameter $rest expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

338
            array_multisort($weights[$k], /** @scrutinizer ignore-type */ SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
Loading history...
Bug introduced by
array_keys($elements[$k]) cannot be passed to array_multisort() as the parameter $rest expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

338
            array_multisort($weights[$k], SORT_ASC, /** @scrutinizer ignore-type */ array_keys($elements[$k]), SORT_ASC, $elements[$k]);
Loading history...
Comprehensibility Best Practice introduced by
The variable $weights does not seem to be defined for all execution paths leading up to this point.
Loading history...
339
            $title = isset($categories[$k]) ? $categories[$k]['cat_title'] : _FRM_SONGLIST_FORM_DEFAULT;
340
            $desc  = isset($categories[$k]) ? $categories[$k]['cat_description'] : '';
341
            $form->addElement(new \XoopsFormLabel("<h3>{$title}</h3>", $desc), false);
342
            foreach (array_keys($elements[$k]) as $i) {
343
                $form->addElement($elements[$k][$i]['element'], $elements[$k][$i]['required']);
344
            }
345
        }
346
347
        $form->addElement(new \XoopsFormHidden('fct', 'objects'));
348
        $form->addElement(new \XoopsFormHidden('op', 'search'));
349
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
350
351
        return $form;
352
    }
353
354
    /**
355
     * @param bool $as_array
356
     * @return string
357
     */
358
    public static function  getFormImport($as_array = false): string
359
    {
360
        xoops_loadLanguage('forms', 'songlist');
361
362
        $sform = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_IMPORT, 'import', $_SERVER['SCRIPT_NAME'], 'post', true);
363
        $sform->setExtra("enctype='multipart/form-data'");
364
365
        $ele['op']      = new \XoopsFormHidden('op', 'import');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ele was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ele = array(); before regardless.
Loading history...
366
        $ele['fct']     = new \XoopsFormHidden('fct', 'upload');
367
        $ele['xmlfile'] = new \XoopsFormFile((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_UPLOAD_XML : ''), 'xmlfile', 1024 * 1024 * 1024 * 32);
368
        $ele['xmlfile']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_UPLOAD_XML_DESC : ''));
369
        $ele['file'] = new \XoopsFormSelect((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_EXISTING_XML : ''), 'file');
370
        $ele['file']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_EXISTING_XML_DESC : ''));
371
        $ele['file']->addOption('', '*********');
372
        xoops_load('XoopsLists');
373
        foreach (\XoopsLists::getFileListAsArray($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $file) {
374
            if ('xml' === mb_substr($file, mb_strlen($file) - 3, 3)) {
375
                $ele['file']->addOption($file, $file);
376
            }
377
        }
378
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
379
380
        $required = [];
381
382
        foreach ($ele as $id => $obj) {
383
            if (in_array($id, $required, true)) {
384
                $sform->addElement($obj, true);
385
            } else {
386
                $sform->addElement($obj, false);
387
            }
388
        }
389
390
        return $sform->render();
391
    }
392
393
    /**
394
     * @param      $file
395
     * @param bool $as_array
396
     * @return string
397
     */
398
    public static function  getFormImportb($file, $as_array = false): string
399
    {
400
        xoops_loadLanguage('forms', 'songlist');
401
402
        $sform = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_ELEMENTS, 'elements', $_SERVER['SCRIPT_NAME'], 'post', true);
403
404
        $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $file));
405
        $mb       = floor($filesize / 1024 / 1024);
406
        if ($mb > 32) {
407
            set_ini('memory_limit', ($mb + 128) . 'M');
0 ignored issues
show
Bug introduced by
The function set_ini was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

407
            /** @scrutinizer ignore-call */ 
408
            set_ini('memory_limit', ($mb + 128) . 'M');
Loading history...
408
        }
409
        set_time_limit(3600);
410
411
        $i = 0;
412
        foreach (file($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])) as $data) {
413
            ++$i;
414
            if ($i < 20) {
415
                $line .= htmlspecialchars($data, ENT_QUOTES | ENT_HTML5) . ($i < 19 ? "\n" : '');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $line seems to be never defined.
Loading history...
416
            }
417
        }
418
419
        $ele['op']      = new \XoopsFormHidden('op', 'import');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ele was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ele = array(); before regardless.
Loading history...
420
        $ele['fct']     = new \XoopsFormHidden('fct', 'import');
421
        $ele['example'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_EXAMPLE : ''), '<pre>' . $line . '</pre>');
422
        $ele['example']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_EXAMPLE_DESC : ''));
423
        $ele['collection'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_COLLECTION : ''), 'collection', 32, 128, 'collection');
424
        $ele['collection']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_COLLECTION_DESC : ''));
425
        $ele['record'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_RECORD : ''), 'record', 32, 128, 'record');
426
        $ele['record']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_RECORD_DESC : ''));
427
        $ele['genre'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_GENRES : ''), 'genre', 32, 128, 'genre');
428
        $ele['genre']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_GENRES_DESC : ''));
429
        $ele['voice'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_VOICE : ''), 'voice', 32, 128, 'voice');
430
        $ele['voice']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_VOICE_DESC : ''));
431
        $ele['category'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_CATEGORY : ''), 'category', 32, 128, 'category');
432
        $ele['category']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_CATEGORY_DESC : ''));
433
        $ele['artist'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_ARTIST : ''), 'artist', 32, 128, 'artist');
434
        $ele['artist']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_ARTIST_DESC : ''));
435
        $ele['album'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_ALBUM : ''), 'album', 32, 128, 'album');
436
        $ele['album']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_ALBUM_DESC : ''));
437
        $ele['songid'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_SONGID : ''), 'songid', 32, 128, 'songid');
438
        $ele['songid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_SONGID_DESC : ''));
439
        $ele['traxid'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TRAXID : ''), 'traxid', 32, 128, 'trackno');
440
        $ele['traxid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TRAXID_DESC : ''));
441
        $ele['title'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TITLE : ''), 'title', 32, 128, 'title');
442
        $ele['title']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TITLE_DESC : ''));
443
        $ele['lyrics'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_LYRICS : ''), 'lyrics', 32, 128, 'lyric');
444
        $ele['lyrics']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_LYRICS_DESC : ''));
445
        $ele['tags'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TAGS : ''), 'tags', 32, 128, 'tags');
446
        $ele['tags']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_TAGS_DESC : ''));
447
        $ele['mp3'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_MP3 : ''), 'mp3', 32, 128, 'mp3');
448
        $ele['mp3']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ELEMENT_MP3_DESC : ''));
449
        $extrasHandler = Helper::getInstance()
450
                               ->getHandler('Extras');
451
        $fields        = $extrasHandler->getFields(null);
452
        foreach ($fields as $field) {
453
            $ele[$field->getVar('field_name')] = new \XoopsFormText((!$as_array ? $field->getVar('field_title') : ''), $field->getVar('field_name'), 32, 128, $field->getVar('field_name'));
454
            $ele[$field->getVar('field_name')]->setDescription((!$as_array ? $field->getVar('field_description') : ''));
455
        }
456
        $ele['limiting'] = new \XoopsFormRadioYN((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_LIMITING : ''), 'limiting');
457
        $ele['limiting']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_LIMITING_DESC : ''));
458
        $ele['records'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_RECORDS : ''), 'records', 10, 10, '250');
459
        $ele['records']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_RECORDS_DESC : ''));
460
        $ele['wait'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_WAIT : ''), 'wait', 10, 10, '40');
461
        $ele['wait']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_IMPORT_WAIT_DESC : ''));
462
463
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
464
465
        $required = [];
466
467
        foreach ($ele as $id => $obj) {
468
            if (in_array($id, $required, true)) {
469
                $sform->addElement($obj, true);
470
            } else {
471
                $sform->addElement($obj, false);
472
            }
473
        }
474
475
        return $sform->render();
476
    }
477
478
    /**
479
     * @param      $object
480
     * @param bool $as_array
481
     * @return array|string
482
     */
483
    public static function  getFormGenre($object, $as_array = false)
484
    {
485
        if (!is_object($object)) {
486
            $handler = Helper::getInstance()
487
                             ->getHandler('Genre');
488
            $object  = $handler->create();
489
        }
490
491
        xoops_loadLanguage('forms', 'songlist');
492
        $ele = [];
493
494
        if ($object->isNew()) {
495
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_GENRE, 'genre', $_SERVER['SCRIPT_NAME'], 'post', true);
496
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
497
        } else {
498
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_GENRE, 'genre', $_SERVER['SCRIPT_NAME'], 'post', true);
499
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
500
        }
501
502
        $sform->setExtra("enctype='multipart/form-data'");
503
504
        $id = $object->getVar('gid');
505
        if (empty($id)) {
506
            $id = '0';
507
        }
508
509
        $ele['op']  = new \XoopsFormHidden('op', 'genre');
510
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
511
        if ($as_array) {
512
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
513
        } else {
514
            $ele['id'] = new \XoopsFormHidden('id', $id);
515
        }
516
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
517
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
518
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
519
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
520
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
521
522
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_GENRE_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, $object->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

522
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_GENRE_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('name'));
Loading history...
523
        $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_GENRE_NAME_DESC : ''));
524
        $ele['albums']  = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_ALBUMS : ''), $object->getVar('albums'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('albums') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

524
        $ele['albums']  = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_ALBUMS : ''), /** @scrutinizer ignore-type */ $object->getVar('albums'));
Loading history...
525
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_ARTISTS : ''), $object->getVar('artists'));
526
        $ele['songs']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_SONGS : ''), $object->getVar('songs'));
527
        $ele['hits']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_HITS : ''), $object->getVar('hits'));
528
        $ele['rank']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
529
        if ($object->getVar('created') > 0) {
530
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
531
        }
532
        if ($object->getVar('updated') > 0) {
533
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_GENRE_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
534
        }
535
536
        if ($as_array) {
537
            return $ele;
538
        }
539
540
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
541
542
        $required = ['name'];
543
544
        foreach ($ele as $id => $obj) {
545
            if (in_array($id, $required, true)) {
546
                $sform->addElement($obj, true);
547
            } else {
548
                $sform->addElement($obj, false);
549
            }
550
        }
551
552
        return $sform->render();
553
    }
554
555
    /**
556
     * @param      $object
557
     * @param bool $as_array
558
     * @return array|string
559
     */
560
    public static function  getFormVoice($object, $as_array = false)
561
    {
562
        if (!is_object($object)) {
563
            $handler = Helper::getInstance()
564
                             ->getHandler('Voice');
565
            $object  = $handler->create();
566
        }
567
568
        xoops_loadLanguage('forms', 'songlist');
569
        $ele = [];
570
571
        if ($object->isNew()) {
572
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_VOICE, 'voice', $_SERVER['SCRIPT_NAME'], 'post', true);
573
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
574
        } else {
575
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_VOICE, 'voice', $_SERVER['SCRIPT_NAME'], 'post', true);
576
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
577
        }
578
579
        $sform->setExtra("enctype='multipart/form-data'");
580
581
        $id = $object->getVar('vcid');
582
        if (empty($id)) {
583
            $id = '0';
584
        }
585
586
        $ele['op']  = new \XoopsFormHidden('op', 'voice');
587
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
588
        if ($as_array) {
589
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
590
        } else {
591
            $ele['id'] = new \XoopsFormHidden('id', $id);
592
        }
593
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
594
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
595
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
596
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
597
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
598
599
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_VOICE_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, $object->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

599
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_VOICE_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('name'));
Loading history...
600
        $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_VOICE_NAME_DESC : ''));
601
        $ele['albums']  = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_ALBUMS : ''), $object->getVar('albums'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('albums') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

601
        $ele['albums']  = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_ALBUMS : ''), /** @scrutinizer ignore-type */ $object->getVar('albums'));
Loading history...
602
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_ARTISTS : ''), $object->getVar('artists'));
603
        $ele['songs']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_SONGS : ''), $object->getVar('songs'));
604
        $ele['hits']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_HITS : ''), $object->getVar('hits'));
605
        $ele['rank']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
606
        if ($object->getVar('created') > 0) {
607
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
608
        }
609
        if ($object->getVar('updated') > 0) {
610
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOICE_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
611
        }
612
613
        if ($as_array) {
614
            return $ele;
615
        }
616
617
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
618
619
        $required = ['name'];
620
621
        foreach ($ele as $id => $obj) {
622
            if (in_array($id, $required, true)) {
623
                $sform->addElement($obj, true);
624
            } else {
625
                $sform->addElement($obj, false);
626
            }
627
        }
628
629
        return $sform->render();
630
    }
631
632
    /**
633
     * @param      $object
634
     * @param bool $as_array
635
     * @return array|string
636
     */
637
    public static function  getFormAlbums($object, $as_array = false)
638
    {
639
        if (!is_object($object)) {
640
            $handler = Helper::getInstance()
641
                             ->getHandler('Albums');
642
            $object  = $handler->create();
643
        }
644
645
        xoops_loadLanguage('forms', 'songlist');
646
        $ele = [];
647
648
        if ($object->isNew()) {
649
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_ALBUMS, 'albums', $_SERVER['SCRIPT_NAME'], 'post', true);
650
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
651
        } else {
652
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_ALBUMS, 'albums', $_SERVER['SCRIPT_NAME'], 'post', true);
653
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
654
        }
655
656
        $sform->setExtra("enctype='multipart/form-data'");
657
658
        $id = $object->getVar('abid');
659
        if (empty($id)) {
660
            $id = '0';
661
        }
662
663
        $ele['op']  = new \XoopsFormHidden('op', 'albums');
664
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
665
        if ($as_array) {
666
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
667
        } else {
668
            $ele['id'] = new \XoopsFormHidden('id', $id);
669
        }
670
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
671
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
672
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
673
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
674
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
675
676
        $ele['cid'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_CATEGORY : ''), $id . '[cid]', $object->getVar('cid'), 1, false, false, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type integer expected by parameter $ownid of XoopsModules\Songlist\Fo...goryForm::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

676
        $ele['cid'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_CATEGORY : ''), $id . '[cid]', $object->getVar('cid'), 1, false, /** @scrutinizer ignore-type */ false, false);
Loading history...
Unused Code introduced by
The call to XoopsModules\Songlist\Fo...goryForm::__construct() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

676
        $ele['cid'] = /** @scrutinizer ignore-call */ new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_CATEGORY : ''), $id . '[cid]', $object->getVar('cid'), 1, false, false, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
677
        $ele['cid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_CATEGORY_DESC : ''));
678
        $ele['title'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_TITLE : ''), $id . '[title]', (!$as_array ? 55 : 21), 128, $object->getVar('title'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('title') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

678
        $ele['title'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_TITLE : ''), $id . '[title]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('title'));
Loading history...
679
        $ele['title']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_TITLE_DESC : ''));
680
        $ele['image'] = new \XoopsFormFile((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_UPLOAD_POSTER : ''), 'image', $GLOBALS['songlistModuleConfig']['filesize_upload']);
681
        $ele['image']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_UPLOAD_POSTER_DESC : ''));
682
        if ('' != $object->getVar('image') && file_exists($GLOBALS['xoops']->path($object->getVar('path') . $object->getVar('image')))) {
683
            $ele['image_preview'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_POSTER : ''), '<img src="' . $object->getImage('image') . '" width="340px">');
0 ignored issues
show
Bug introduced by
The method getImage() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModules\Songlist\Category or XoopsModules\Songlist\Albums. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

683
            $ele['image_preview'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_POSTER : ''), '<img src="' . $object->/** @scrutinizer ignore-call */ getImage('image') . '" width="340px">');
Loading history...
684
            $ele['image_preview']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_POSTER_DESC : ''));
685
        }
686
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_ARTISTS : ''), $object->getVar('artists'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('artists') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

686
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_ARTISTS : ''), /** @scrutinizer ignore-type */ $object->getVar('artists'));
Loading history...
687
        $ele['songs']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_SONGS : ''), $object->getVar('songs'));
688
        $ele['hits']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_HITS : ''), $object->getVar('hits'));
689
        $ele['rank']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
690
        if ($object->getVar('created') > 0) {
691
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
692
        }
693
        if ($object->getVar('updated') > 0) {
694
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ALBUMS_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
695
        }
696
697
        if ($as_array) {
698
            return $ele;
699
        }
700
701
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
702
703
        $required = ['name', 'id', 'source'];
704
705
        foreach ($ele as $id => $obj) {
706
            if (in_array($id, $required, true)) {
707
                $sform->addElement($obj, true);
708
            } else {
709
                $sform->addElement($obj, false);
710
            }
711
        }
712
713
        return $sform->render();
714
    }
715
716
    /**
717
     * @param Songlist\Artists $object
718
     * @param bool             $as_array
719
     * @return array|string
720
     */
721
    public static function  getFormArtists($object, $as_array = false)
722
    {
723
        if (!is_object($object)) {
724
            $handler = Helper::getInstance()
725
                             ->getHandler('Artists');
726
            $object  = $handler->create();
727
        }
728
729
        xoops_loadLanguage('forms', 'songlist');
730
        $ele = [];
731
732
        if ($object->isNew()) {
733
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_ARTISTS, 'artists', $_SERVER['SCRIPT_NAME'], 'post', true);
734
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
735
        } else {
736
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_ARTISTS, 'artists', $_SERVER['SCRIPT_NAME'], 'post', true);
737
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
738
        }
739
740
        $id = $object->getVar('aid');
741
        if (empty($id)) {
742
            $id = '0';
743
        }
744
745
        $ele['op']  = new \XoopsFormHidden('op', 'artists');
746
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
747
        if ($as_array) {
748
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
749
        } else {
750
            $ele['id'] = new \XoopsFormHidden('id', $id);
751
        }
752
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
753
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
754
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
755
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
756
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
757
758
        $ele['cids'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_CATEGORY : ''), $id . '[cids]', $object->getVar('cids'), 7, true, false, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type integer expected by parameter $ownid of XoopsModules\Songlist\Fo...goryForm::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

758
        $ele['cids'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_CATEGORY : ''), $id . '[cids]', $object->getVar('cids'), 7, true, /** @scrutinizer ignore-type */ false, false);
Loading history...
Unused Code introduced by
The call to XoopsModules\Songlist\Fo...goryForm::__construct() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

758
        $ele['cids'] = /** @scrutinizer ignore-call */ new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_CATEGORY : ''), $id . '[cids]', $object->getVar('cids'), 7, true, false, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
759
        $ele['cids']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_CATEGORY_DESC : ''));
760
        //$ele['singer'] = new \XoopsModules\Songlist\Form\SelectSingerForm(($as_array==false?_FRM_SONGLIST_FORM_ARTISTS_SINGER:''), $id.'[singer]', $object->getVar('singer'), 1, false, false, false);
761
        //$ele['singer']->setDescription(($as_array==false?_FRM_SONGLIST_FORM_ARTISTS_SINGER_DESC:''));
762
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, $object->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

762
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('name'));
Loading history...
763
        $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_NAME_DESC : ''));
764
        $ele['albums'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_ALBUMS : ''), $object->getVar('albums'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('albums') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

764
        $ele['albums'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_ALBUMS : ''), /** @scrutinizer ignore-type */ $object->getVar('albums'));
Loading history...
765
        $ele['songs']  = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_SONGS : ''), $object->getVar('songs'));
766
        $ele['hits']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_HITS : ''), $object->getVar('hits'));
767
        $ele['rank']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
768
        if ($object->getVar('created') > 0) {
769
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
770
        }
771
        if ($object->getVar('updated') > 0) {
772
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_ARTISTS_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
773
        }
774
775
        if ($as_array) {
776
            return $ele;
777
        }
778
779
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
780
781
        $required = ['name', 'mimetype', 'support'];
782
783
        foreach ($ele as $id => $obj) {
784
            if (in_array($id, $required, true)) {
785
                $sform->addElement($obj, true);
786
            } else {
787
                $sform->addElement($obj, false);
788
            }
789
        }
790
791
        return $sform->render();
792
    }
793
794
    /**
795
     * @param      $object
796
     * @param bool $as_array
797
     * @return array|string
798
     */
799
    public static function  getFormCategory($object, $as_array = false)
800
    {
801
        if (!is_object($object)) {
802
            $handler = Helper::getInstance()
803
                             ->getHandler('Category');
804
            $object  = $handler->create();
805
        }
806
807
        xoops_loadLanguage('forms', 'songlist');
808
        $ele = [];
809
810
        if ($object->isNew()) {
811
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_CATEGORY, 'category', $_SERVER['SCRIPT_NAME'], 'post', true);
812
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
813
        } else {
814
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_CATEGORY, 'category', $_SERVER['SCRIPT_NAME'], 'post', true);
815
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
816
        }
817
818
        $sform->setExtra("enctype='multipart/form-data'");
819
820
        $id = $object->getVar('cid');
821
        if (empty($id)) {
822
            $id = '0';
823
        }
824
825
        $ele['op']  = new \XoopsFormHidden('op', 'category');
826
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
827
        if ($as_array) {
828
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
829
        } else {
830
            $ele['id'] = new \XoopsFormHidden('id', $id);
831
        }
832
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
833
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
834
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
835
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
836
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
837
838
        $ele['pid'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_PARENT : ''), $id . '[pid]', $object->getVar('pid'), 1, false, $object->getVar('cid'));
839
        $ele['pid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_PARENT_DESC : ''));
840
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, $object->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

840
        $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('name'));
Loading history...
841
        $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_NAME_DESC : ''));
842
        $description_configs           = [];
843
        $description_configs['name']   = $id . '[description]';
844
        $description_configs['value']  = $object->getVar('description');
845
        $description_configs['rows']   = 35;
846
        $description_configs['cols']   = 60;
847
        $description_configs['width']  = '100%';
848
        $description_configs['height'] = '400px';
849
        $ele['description']            = new \XoopsFormEditor(_FRM_SONGLIST_FORM_CATEGORY_DESCRIPTION, $GLOBALS['songlistModuleConfig']['editor'], $description_configs);
850
        $ele['description']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_DESCRIPTION_DESC : ''));
851
        $ele['image'] = new \XoopsFormFile((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_UPLOAD_POSTER : ''), 'image', $GLOBALS['songlistModuleConfig']['filesize_upload']);
852
        $ele['image']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_UPLOAD_POSTER_DESC : ''));
853
        if ('' != $object->getVar('image') && file_exists($GLOBALS['xoops']->path($object->getVar('path') . $object->getVar('image')))) {
854
            $ele['image_preview'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_POSTER : ''), '<img src="' . $object->getImage('image') . '" width="340px">');
855
            $ele['image_preview']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_POSTER_DESC : ''));
856
        }
857
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_ARTISTS : ''), $object->getVar('artists'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('artists') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

857
        $ele['artists'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_ARTISTS : ''), /** @scrutinizer ignore-type */ $object->getVar('artists'));
Loading history...
858
        $ele['songs']   = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_SONGS : ''), $object->getVar('songs'));
859
        $ele['hits']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_HITS : ''), $object->getVar('hits'));
860
        $ele['rank']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
861
        if ($object->getVar('created') > 0) {
862
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
863
        }
864
        if ($object->getVar('updated') > 0) {
865
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_CATEGORY_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
866
        }
867
868
        if ($as_array) {
869
            return $ele;
870
        }
871
872
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
873
874
        $required = ['name', 'id', 'source'];
875
876
        foreach ($ele as $id => $obj) {
877
            if (in_array($id, $required, true)) {
878
                $sform->addElement($obj, true);
879
            } else {
880
                $sform->addElement($obj, false);
881
            }
882
        }
883
884
        return $sform->render();
885
    }
886
887
    /**
888
     * @param      $object
889
     * @param bool $as_array
890
     * @return array|string
891
     */
892
    public static function  getFormUtf8map($object, $as_array = false)
893
    {
894
        if (!is_object($object)) {
895
            $handler = Helper::getInstance()
896
                             ->getHandler('Utf8map');
897
            $object  = $handler->create();
898
        }
899
900
        xoops_loadLanguage('forms', 'songlist');
901
        $ele = [];
902
903
        if ($object->isNew()) {
904
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_UTF8MAP, 'utf8map', $_SERVER['SCRIPT_NAME'], 'post', true);
905
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
906
        } else {
907
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_UTF8MAP, 'utf8map', $_SERVER['SCRIPT_NAME'], 'post', true);
908
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
909
        }
910
911
        $sform->setExtra("enctype='multipart/form-data'");
912
913
        $id = $object->getVar('utfid');
914
        if (empty($id)) {
915
            $id = '0';
916
        }
917
918
        $ele['op']  = new \XoopsFormHidden('op', 'utf8map');
919
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
920
        if ($as_array) {
921
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
922
        } else {
923
            $ele['id'] = new \XoopsFormHidden('id', $id);
924
        }
925
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
926
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
927
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
928
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
929
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
930
931
        $ele['from'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_FROM : ''), $id . '[from]', (!$as_array ? 6 : 4), 2, $object->getVar('from'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('from') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

931
        $ele['from'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_FROM : ''), $id . '[from]', (!$as_array ? 6 : 4), 2, /** @scrutinizer ignore-type */ $object->getVar('from'));
Loading history...
932
        $ele['from']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_FROM_DESC : ''));
933
        $ele['to'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_TO : ''), $id . '[to]', (!$as_array ? 6 : 4), 2, $object->getVar('to'));
934
        $ele['to']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_TO_DESC : ''));
935
936
        if ($object->getVar('created') > 0) {
937
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
938
        }
939
        if ($object->getVar('updated') > 0) {
940
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_UTF8MAP_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
941
        }
942
943
        if ($as_array) {
944
            return $ele;
945
        }
946
947
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
948
949
        $required = ['from', 'to'];
950
951
        foreach ($ele as $id => $obj) {
952
            if (in_array($id, $required, true)) {
953
                $sform->addElement($obj, true);
954
            } else {
955
                $sform->addElement($obj, false);
956
            }
957
        }
958
959
        return $sform->render();
960
    }
961
962
    /**
963
     * @param      $object
964
     * @param bool $as_array
965
     * @return array|string
966
     */
967
    public static function  getFormRequests($object, $as_array = false)
968
    {
969
        if (!is_object($object)) {
970
            $handler = Helper::getInstance()
971
                             ->getHandler('Requests');
972
            $object  = $handler->create();
973
        }
974
975
        xoops_loadLanguage('forms', 'songlist');
976
        $ele = [];
977
978
        if ($object->isNew()) {
979
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_REQUESTS, 'requests', $_SERVER['SCRIPT_NAME'], 'post', true);
980
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
981
        } else {
982
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_REQUESTS, 'requests', $_SERVER['SCRIPT_NAME'], 'post', true);
983
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
984
        }
985
986
        $sform->setExtra("enctype='multipart/form-data'");
987
988
        $id = $object->getVar('rid');
989
        if (empty($id)) {
990
            $id = '0';
991
        }
992
993
        $ele['op']  = new \XoopsFormHidden('op', 'requests');
994
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
995
        if ($as_array) {
996
            $ele['id'] = new \XoopsFormHidden('id', $id);
997
        } else {
998
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
999
        }
1000
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
1001
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
1002
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
1003
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
1004
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
1005
1006
        $ele['artist'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_ARTIST : ''), $id . '[artist]', (!$as_array ? 55 : 21), 128, $object->getVar('artist'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('artist') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1006
        $ele['artist'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_ARTIST : ''), $id . '[artist]', (!$as_array ? 55 : 21), 128, /** @scrutinizer ignore-type */ $object->getVar('artist'));
Loading history...
1007
        $ele['artist']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_ARTIST_DESC : ''));
1008
        $ele['album'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_ALBUM : ''), $id . '[album]', (!$as_array ? 55 : 21), 128, $object->getVar('album'));
1009
        $ele['album']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_ALBUM_DESC : ''));
1010
        $ele['title'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_TITLE : ''), $id . '[title]', (!$as_array ? 55 : 21), 128, $object->getVar('title'));
1011
        $ele['title']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_TITLE_DESC : ''));
1012
        $ele['lyrics'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_LYRICS : ''), $id . '[lyrics]', (!$as_array ? 55 : 21), 128, $object->getVar('lyrics'));
1013
        $ele['lyrics']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_LYRICS_DESC : ''));
1014
1015
        if (is_object($GLOBALS['xoopsUser'])) {
1016
            $ele['uid']  = new \XoopsFormHidden('uid', $GLOBALS['xoopsUser']->getVar('uid'));
1017
            $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, ($object->isNew() ? $GLOBALS['xoopsUser']->getVar('name') : $object->getVar('name')));
1018
            $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_NAME_DESC : ''));
1019
            $ele['email'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_EMAIL : ''), $id . '[email]', (!$as_array ? 55 : 21), 128, ($object->isNew() ? $GLOBALS['xoopsUser']->getVar('email') : $object->getVar('email')));
1020
            $ele['email']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_EMAIL_DESC : ''));
1021
        } else {
1022
            $ele['uid']  = new \XoopsFormHidden('uid', 0);
1023
            $ele['name'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_NAME : ''), $id . '[name]', (!$as_array ? 55 : 21), 128, ($object->isNew() ? '' : $object->getVar('name')));
1024
            $ele['name']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_NAME_DESC : ''));
1025
            $ele['email'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_EMAIL : ''), $id . '[email]', (!$as_array ? 55 : 21), 128, ($object->isNew() ? '' : $object->getVar('email')));
1026
            $ele['email']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_EMAIL_DESC : ''));
1027
        }
1028
        if ($object->getVar('created') > 0) {
1029
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
1030
        }
1031
        if ($object->getVar('updated') > 0) {
1032
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_REQUESTS_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
1033
        }
1034
1035
        if ($as_array) {
1036
            return $ele;
1037
        }
1038
1039
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
1040
1041
        $required = ['name', 'email'];
1042
1043
        foreach ($ele as $id => $obj) {
1044
            if (in_array($id, $required, true)) {
1045
                $sform->addElement($obj, true);
1046
            } else {
1047
                $sform->addElement($obj, false);
1048
            }
1049
        }
1050
1051
        return $sform->render();
1052
    }
1053
1054
    /**
1055
     * @param      $object
1056
     * @param bool $as_array
1057
     * @return array|string
1058
     */
1059
    public static function  getFormSongs($object, $as_array = false)
1060
    {
1061
        if (!is_object($object)) {
1062
            $handler = Helper::getInstance()
1063
                             ->getHandler('Songs');
1064
            $object  = $handler->create();
1065
        }
1066
1067
        xoops_loadLanguage('forms', 'songlist');
1068
        $ele = [];
1069
1070
        if ($object->isNew()) {
1071
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_SONGS, 'songs', $_SERVER['SCRIPT_NAME'], 'post', true);
1072
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
1073
        } else {
1074
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_SONGS, 'songs', $_SERVER['SCRIPT_NAME'], 'post', true);
1075
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
1076
        }
1077
1078
        $sform->setExtra("enctype='multipart/form-data'");
1079
1080
        $id = $object->getVar('sid');
1081
        if (empty($id)) {
1082
            $id = '0';
1083
        }
1084
1085
        $ele['op']  = new \XoopsFormHidden('op', 'songs');
1086
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
1087
        if ($as_array) {
1088
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
1089
        } else {
1090
            $ele['id'] = new \XoopsFormHidden('id', $id);
1091
        }
1092
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
1093
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
1094
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
1095
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
1096
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
1097
1098
        $ele['cid'] = new SelectCategoryForm((!$as_array ? _FRM_SONGLIST_FORM_SONGS_CATEGORY : ''), $id . '[cid]', ($_REQUEST['cid'] ?? $object->getVar('cid')), 1, false);
1099
        $ele['cid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_CATEGORY_DESC : ''));
1100
        if ($GLOBALS['songlistModuleConfig']['genre']) {
1101
            $ele['gids'] = new SelectGenreForm((!$as_array ? _FRM_SONGLIST_FORM_SONGS_GENRE : ''), $id . '[gids]', ($_REQUEST['gids'] ?? $object->getVar('gids')), 8, true);
1102
            $ele['gids']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_GENRE_DESC : ''));
1103
        }
1104
        if ($GLOBALS['songlistModuleConfig']['voice']) {
1105
            $ele['vcid'] = new SelectVoiceForm((!$as_array ? _FRM_SONGLIST_FORM_SONGS_VOICE : ''), $id . '[vcid]', ($_REQUEST['vcid'] ?? $object->getVar('vcid')), 1, false);
1106
            $ele['vcid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_VOICE_DESC : ''));
1107
        }
1108
        if ($GLOBALS['songlistModuleConfig']['album']) {
1109
            $ele['abid'] = new SelectAlbumForm((!$as_array ? _FRM_SONGLIST_FORM_SONGS_ALBUM : ''), $id . '[abid]', $object->getVar('abid'), 1, false);
1110
            $ele['abid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_ALBUM_DESC : ''));
1111
        }
1112
        $ele['aids'] = new SelectArtistForm((!$as_array ? _FRM_SONGLIST_FORM_SONGS_ARTISTS : ''), $id . '[aids]', $object->getVar('aids'), 7, true);
1113
        $ele['aids']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_ARTISTS_DESC : ''));
1114
        $ele['songid'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_SONGS_SONGID : ''), $id . '[songid]', (!$as_array ? 25 : 15), 32, $object->getVar('songid'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('songid') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1114
        $ele['songid'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_SONGS_SONGID : ''), $id . '[songid]', (!$as_array ? 25 : 15), 32, /** @scrutinizer ignore-type */ $object->getVar('songid'));
Loading history...
1115
        $ele['songid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_SONGID_DESC : ''));
1116
        $ele['traxid'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_SONGS_TRAXID : ''), $id . '[traxid]', (!$as_array ? 25 : 15), 32, $object->getVar('traxid'));
1117
        $ele['traxid']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_TRAXID_DESC : ''));
1118
        $ele['title'] = new \XoopsFormText((!$as_array ? _FRM_SONGLIST_FORM_SONGS_TITLE : ''), $id . '[title]', (!$as_array ? 55 : 21), 128, $object->getVar('title'));
1119
        $ele['title']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_TITLE_DESC : ''));
1120
        $description_configs           = [];
1121
        $description_configs['name']   = $id . '[lyrics]';
1122
        $description_configs['value']  = $object->getVar('lyrics');
1123
        $description_configs['rows']   = 35;
1124
        $description_configs['cols']   = 60;
1125
        $description_configs['width']  = '100%';
1126
        $description_configs['height'] = '400px';
1127
        $ele['lyrics']                 = new \XoopsFormEditor(_FRM_SONGLIST_FORM_SONGS_LYRICS, $GLOBALS['songlistModuleConfig']['editor'], $description_configs);
1128
        $ele['lyrics']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_LYRICS_DESC : ''));
1129
        $ele['mp3'] = new \XoopsFormFile((!$as_array ? _FRM_SONGLIST_FORM_SONGS_MP3 : ''), 'mp3' . $id, $GLOBALS['songlistModuleConfig']['mp3_filesize']);
1130
        $ele['mp3']->setDescription((!$as_array ? _FRM_SONGLIST_FORM_SONGS_MP3_DESC : ''));
1131
        $categoryHandler = Helper::getInstance()
1132
                                 ->getHandler('Category');
1133
        $criteria        = new \CriteriaCompo(new \Criteria('cid', !empty($_REQUEST['cid']) ? Request::getInt('cid', 0, 'REQUEST') : $object->getVar('cid')));
0 ignored issues
show
Bug introduced by
It seems like ! empty($_REQUEST['cid']... $object->getVar('cid') can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1133
        $criteria        = new \CriteriaCompo(new \Criteria('cid', /** @scrutinizer ignore-type */ !empty($_REQUEST['cid']) ? Request::getInt('cid', 0, 'REQUEST') : $object->getVar('cid')));
Loading history...
1134
        $all_categories  = $categoryHandler->getObjects($criteria, true, false);
1135
1136
        // Dynamic fields
1137
        $extrasHandler = Helper::getInstance()
1138
                               ->getHandler('Extras');
1139
        /** @var \XoopsGroupPermHandler $grouppermHandler */
1140
        $grouppermHandler = xoops_getHandler('groupperm');
1141
        /** @var \XoopsModuleHandler $moduleHandler */
1142
        $moduleHandler = xoops_getHandler('module');
1143
        $xoModule      = $moduleHandler->getByDirname('songlist');
1144
        $modid         = $xoModule->getVar('mid');
1145
1146
        if (is_object($GLOBALS['xoopsUser'])) {
1147
            $groups = $GLOBALS['xoopsUser']->getGroups();
1148
        } else {
1149
            $groups = [XOOPS_GROUP_ANONYMOUS => XOOPS_GROUP_ANONYMOUS];
1150
        }
1151
1152
        $count_fields = 0;
1153
        $fields       = $extrasHandler->loadFields();
1154
1155
        $required = [];
1156
        $elements = [];
1157
        $weights  = [];
1158
        if ($object->getVar('sid') > 0) {
1159
            $extra = $extrasHandler->get($object->getVar('sid'));
1160
        } else {
1161
            $extra = $extrasHandler->create();
1162
        }
1163
        $allnames = [];
1164
        if (is_array($fields)) {
1165
            foreach (array_keys($fields) as $i) {
1166
                if ((0 != $object->getVar('sid') && $grouppermHandler->checkRight('songlist_edit', $fields[$i]->getVar('field_id'), $groups, $modid))
1167
                    || (0 == $object->getVar('sid') && $grouppermHandler->checkRight('songlist_post', $fields[$i]->getVar('field_id'), $groups, $modid))) {
1168
                    $fieldinfo['element']  = $fields[$i]->getEditElement($object, $extra);
1169
                    $fieldinfo['required'] = $fields[$i]->getVar('field_required');
1170
                    foreach ($fields[$i]->getVar('cids') as $catidid => $cid) {
1171
                        if (!in_array($fields[$i]->getVar('field_name'), $allnames, true)) {
1172
                            $allnames[] = $fields[$i]->getVar('field_name');
1173
                            if (array_key_exists($cid, $all_categories)
1174
                                || $cid == (!empty($_REQUEST['cid'])
1175
                                    ? Request::getInt('cid', 0, 'REQUEST')
1176
                                    : $object->getVar('cid'))) {
1177
                                $key              = (isset($all_categories[$cid]) ? $all_categories[$cid]['weight'] : 0)
1178
                                                    * $count_fields + $object->getVar('cid');
1179
                                $elements[$key][] = $fieldinfo;
1180
                                $weights[$key][]  = $fields[$i]->getVar('field_weight');
1181
                            } elseif (in_array(0, $fields[$i]->getVar('cids'), true)) {
1182
                                $key              = (isset($all_categories[$cid]) ? $all_categories[$cid]['weight'] : 0) * $count_fields + $object->getVar('cid');
1183
                                $elements[$key][] = $fieldinfo;
1184
                                $weights[$key][]  = $fields[$i]->getVar('field_weight');
1185
                            }
1186
                        }
1187
                    }
1188
                }
1189
            }
1190
        }
1191
        if (is_array($elements)) {
0 ignored issues
show
introduced by
The condition is_array($elements) is always true.
Loading history...
1192
            ksort($elements);
1193
            foreach (array_keys($elements) as $k) {
1194
                array_multisort($weights[$k], SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
0 ignored issues
show
Bug introduced by
array_keys($elements[$k]) cannot be passed to array_multisort() as the parameter $rest expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1194
                array_multisort($weights[$k], SORT_ASC, /** @scrutinizer ignore-type */ array_keys($elements[$k]), SORT_ASC, $elements[$k]);
Loading history...
Bug introduced by
XoopsModules\Songlist\Form\SORT_ASC cannot be passed to array_multisort() as the parameter $rest expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1194
                array_multisort($weights[$k], /** @scrutinizer ignore-type */ SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
Loading history...
1195
                foreach (array_keys($elements[$k]) as $i) {
1196
                    $ele[$k] = $elements[$k][$i]['element'];
1197
                    if (true === $elements[$k][$i]['required']) {
1198
                        $required[$k] = $elements[$k][$i]['element']->getName();
1199
                    }
1200
                }
1201
            }
1202
        }
1203
1204
        if (class_exists(\XoopsModules\Tag\FormTag::class)) {
1205
            $ele['tags'] = new \XoopsModules\Tag\FormTag('tags', 60, 255, $object->getVar('sid'), $object->getVar('cid'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('sid') can also be of type array and array; however, parameter $value of XoopsModules\Tag\FormTag::__construct() does only seem to accept integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1205
            $ele['tags'] = new \XoopsModules\Tag\FormTag('tags', 60, 255, /** @scrutinizer ignore-type */ $object->getVar('sid'), $object->getVar('cid'));
Loading history...
1206
        } else {
1207
            $ele['tags'] = new \XoopsFormHidden('tags', $object->getVar('tags'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('tags') can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1207
            $ele['tags'] = new \XoopsFormHidden('tags', /** @scrutinizer ignore-type */ $object->getVar('tags'));
Loading history...
1208
        }
1209
1210
        $ele['hits'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_SONGS_HITS : ''), $object->getVar('hits'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('hits') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1210
        $ele['hits'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_SONGS_HITS : ''), /** @scrutinizer ignore-type */ $object->getVar('hits'));
Loading history...
1211
        $ele['rank'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_SONGS_RANK : ''), number_format(($object->getVar('rank') > 0 && $object->getVar('votes') > 0 ? $object->getVar('rank') / $object->getVar('votes') : 0), 2) . ' of 10');
1212
        if ($object->getVar('created') > 0) {
1213
            $ele['created'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_SONGS_CREATED : ''), date(_DATESTRING, $object->getVar('created')));
1214
        }
1215
        if ($object->getVar('updated') > 0) {
1216
            $ele['updated'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_SONGS_UPDATED : ''), date(_DATESTRING, $object->getVar('updated')));
1217
        }
1218
        if ($as_array) {
1219
            return $ele;
1220
        }
1221
1222
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
1223
1224
        foreach ($ele as $id => $obj) {
1225
            if (in_array($id, $required, true)) {
1226
                $sform->addElement($obj, true);
1227
            } else {
1228
                $sform->addElement($obj, false);
1229
            }
1230
        }
1231
1232
        return $sform->render();
1233
    }
1234
1235
    /**
1236
     * @param      $object
1237
     * @param bool $as_array
1238
     * @return array|string
1239
     */
1240
    public static function  getFormVotes($object, $as_array = false)
1241
    {
1242
        if (!is_object($object)) {
1243
            $handler = Helper::getInstance()
1244
                             ->getHandler('Votes');
1245
            $object  = $handler->create();
1246
        }
1247
1248
        xoops_loadLanguage('forms', 'songlist');
1249
        $ele = [];
1250
1251
        if ($object->isNew()) {
1252
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_ISNEW_CART, 'votes', $_SERVER['SCRIPT_NAME'], 'post', true);
1253
            $ele['mode'] = new \XoopsFormHidden('mode', 'new');
1254
        } else {
1255
            $sform       = new \XoopsThemeForm(_FRM_SONGLIST_FORM_EDIT_CART, 'votes', $_SERVER['SCRIPT_NAME'], 'post', true);
1256
            $ele['mode'] = new \XoopsFormHidden('mode', 'edit');
1257
        }
1258
1259
        $sform->setExtra("enctype='multipart/form-data'");
1260
1261
        $id = $object->getVar('cid');
1262
        if (empty($id)) {
1263
            $id = '0';
1264
        }
1265
1266
        $ele['op']  = new \XoopsFormHidden('op', 'votes');
1267
        $ele['fct'] = new \XoopsFormHidden('fct', 'save');
1268
        if ($as_array) {
1269
            $ele['id'] = new \XoopsFormHidden('id', $id);
1270
        } else {
1271
            $ele['id'] = new \XoopsFormHidden('id[' . $id . ']', $id);
1272
        }
1273
        $ele['sort']   = new \XoopsFormHidden('sort', $_REQUEST['sort'] ?? 'created');
1274
        $ele['order']  = new \XoopsFormHidden('order', $_REQUEST['order'] ?? 'DESC');
1275
        $ele['start']  = new \XoopsFormHidden('start', (string)Request::getInt('start', 0, 'REQUEST'));
1276
        $ele['limit']  = new \XoopsFormHidden('limit', (string)Request::getInt('limit', 0, 'REQUEST'));
1277
        $ele['filter'] = new \XoopsFormHidden('filter', $_REQUEST['filter'] ?? '1,1');
1278
1279
        $songsHandler = Helper::getInstance()
1280
                              ->getHandler('Songs');
1281
        $userHandler  = xoops_getHandler('user');
1282
        $song         = $songsHandler->get($object->getVar('sid'));
1283
        $user         = $userHandler->get($object->getVar('uid'));
1284
        if (is_object($song)) {
1285
            $ele['sid'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_SONG : ''), $song->getVar('title'));
0 ignored issues
show
Bug introduced by
It seems like $song->getVar('title') can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1285
            $ele['sid'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_SONG : ''), /** @scrutinizer ignore-type */ $song->getVar('title'));
Loading history...
1286
        } else {
1287
            $ele['sid'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_SONG : ''), $object->getVar('sid'));
1288
        }
1289
        if (is_object($user)) {
1290
            $ele['uid'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_USER : ''), $user->getVar('uname'));
1291
        } else {
1292
            $ele['uid'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_USER : ''), _GUESTS);
1293
        }
1294
        $ele['ip']      = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_IP : ''), $object->getVar('ip'));
1295
        $ele['netaddy'] = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_NETADDY : ''), $object->getVar('netaddy'));
1296
        $ele['rank']    = new \XoopsFormLabel((!$as_array ? _FRM_SONGLIST_FORM_VOTES_RANK : ''), $object->getVar('rank') . ' of 10');
1297
1298
        if ($as_array) {
1299
            return $ele;
1300
        }
1301
1302
        $ele['submit'] = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
1303
1304
        $required = [];
1305
1306
        foreach ($ele as $id => $obj) {
1307
            if (in_array($id, $required, true)) {
1308
                $sform->addElement($obj, true);
1309
            } else {
1310
                $sform->addElement($obj, false);
1311
            }
1312
        }
1313
1314
        return $sform->render();
1315
    }
1316
}
1317