Fields   B
last analyzed

Complexity

Total Complexity 44

Size/Duplication

Total Lines 493
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 302
dl 0
loc 493
rs 8.8798
c 2
b 0
f 0
wmc 44

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A __call() 0 5 2
A __construct() 0 26 1
A getFormNew() 0 20 3
A getHeaderForm() 0 32 3
A getFooterForm() 0 12 1
A getValuesFields() 0 19 1
F getFormNewLine() 0 131 19
C getFormEdit() 0 155 12

How to fix   Complexity   

Complex Class

Complex classes like Fields often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Fields, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace XoopsModules\Tdmcreate;
4
5
use XoopsModules\Tdmcreate;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
/**
18
 * tdmcreatereate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.7
24
 *
25
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
26
 *
27
 */
28
//include __DIR__.'/autoload.php';
29
30
/**
31
 * Class Fields.
32
 */
33
class Fields extends \XoopsObject
34
{
35
    /**
36
     * @public function constructor class
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        $this->initVar('field_id', XOBJ_DTYPE_INT);
43
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
44
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
45
        $this->initVar('field_order', XOBJ_DTYPE_INT);
46
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
47
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
54
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
55
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
56
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
57
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
58
        $this->initVar('field_user', XOBJ_DTYPE_INT);
59
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
60
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
61
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
62
        $this->initVar('field_block', XOBJ_DTYPE_INT);
63
        $this->initVar('field_main', XOBJ_DTYPE_INT);
64
        $this->initVar('field_search', XOBJ_DTYPE_INT);
65
        $this->initVar('field_required', XOBJ_DTYPE_INT);
66
    }
67
68
    /**
69
     * @param string $method
70
     * @param array  $args
71
     *
72
     * @return mixed
73
     */
74
    public function __call($method, $args)
75
    {
76
        $arg = isset($args[0]) ? $args[0] : null;
77
78
        return $this->getVar($method, $arg);
79
    }
80
81
    /**
82
     * @static function getInstance
83
     *
84
     * @return Fields
85
     */
86
    public static function getInstance()
87
    {
88
        static $instance = false;
89
        if (!$instance) {
90
            $instance = new self();
91
        }
92
93
        return $instance;
94
    }
95
96
    /**
97
     * @private function getHeaderForm
98
     *
99
     * @param bool $action
100
     * @param $prefix
101
     * @return Tdmcreate\Form\ThemeForm
102
     */
103
    private function getHeaderForm($prefix, $action = false)
104
    {
105
        if (false === $action) {
106
            $action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
107
        }
108
109
        $isNew = $this->isNew();
110
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
111
112
        $form = new Tdmcreate\Form\ThemeForm(null, 'form', $action, 'post', true);
0 ignored issues
show
Bug introduced by
It seems like $action can also be of type true; however, parameter $action of XoopsModules\Tdmcreate\F...hemeForm::__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

112
        $form = new Tdmcreate\Form\ThemeForm(null, 'form', /** @scrutinizer ignore-type */ $action, 'post', true);
Loading history...
113
        $form->setExtra('enctype="multipart/form-data"');
114
115
        // New Object HtmlTable
116
        $form->addElement(new Tdmcreate\Html\FormLabel(str_replace('%s', $prefix, _AM_TDMCREATE_FIELD_RECOMMENDED)));
117
        $form->addElement(new Tdmcreate\Html\FormLabel('<table style="border-spacing:5px;" class="outer width100">'));
118
        $form->addElement(new Tdmcreate\Html\FormLabel('<thead class="center">'));
119
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head"><th colspan="10">' . $title . '</th></tr>'));
120
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head width5">'));
121
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ID . '</td>'));
122
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NAME . '</td>'));
123
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ELEMENT . '</td>'));
124
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_TYPE . '</td>'));
125
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_VALUE . '</th>'));
126
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ATTRIBUTE . '</th>'));
127
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NULL . '</th>'));
128
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_DEFAULT . '</th>'));
129
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_KEY . '</th>'));
130
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_PARAMETERS . '</th>'));
131
        $form->addElement(new Tdmcreate\Html\FormLabel('</tr></thead>'));
132
        $form->addElement(new Tdmcreate\Html\FormLabel('<tbody>'));
133
134
        return $form;
135
    }
136
137
    /**
138
     * @public function getFormNew
139
     *
140
     * @param null $fieldMid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldMid is correct as it would always require null to be passed?
Loading history...
141
     * @param null $fieldTid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldTid is correct as it would always require null to be passed?
Loading history...
142
     * @param null $fieldNumb
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldNumb is correct as it would always require null to be passed?
Loading history...
143
     * @param null $fieldName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldName is correct as it would always require null to be passed?
Loading history...
144
     * @param bool $action
145
     * @return mixed
146
     */
147
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
148
    {
149
        $helper = Tdmcreate\Helper::getInstance();
150
        // Get handler tables
151
        $tableObj   = $helper->getHandler('Tables');
152
        // Header function class
153
        $fieldsForm = self::getInstance();
154
        $prefix     = $tableObj->get($fieldTid)->getVar('table_fieldname');
155
        $form       = $fieldsForm->getHeaderForm($prefix, $action);
156
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement');
157
        // Loop for fields number
158
        $class = 'even';
159
        for ($i = 1; $i <= $fieldNumb; ++$i) {
160
            $class = ('even' === $class) ? 'odd' : 'even';
161
            // Replaced creation of new line by new function - goffy
162
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
163
        }
164
165
        // Footer form
166
        return $fieldsForm->getFooterForm($form);
167
    }
168
169
    /**
170
     * @private function getFormNewLine
171
     *
172
     * @param $form
173
     * @param $class
174
     * @param $i
175
     * @param $fieldMid
176
     * @param $fieldTid
177
     * @param $fName
178
     * @param $tableAutoincrement
179
     */
180
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
181
    {
182
        $helper = Tdmcreate\Helper::getInstance();
183
        $fieldElements = $helper->getHandler('Fieldelements')->getAll();
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoUserHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

183
        $fieldElements = $helper->getHandler('Fieldelements')->/** @scrutinizer ignore-call */ getAll();
Loading history...
184
        foreach ($fieldElements as $fe) {
185
            $form->addElement(new \XoopsFormHidden('fe_defaulttype[' . $fe->getVar('fieldelement_id') . ']', $fe->getVar('fieldelement_deftype')));
186
            $form->addElement(new \XoopsFormHidden('fe_defaultvalue[' . $fe->getVar('fieldelement_id') . ']', $fe->getVar('fieldelement_defvalue')));
187
        }
188
        $form->addElement(new \XoopsFormHidden('field_id[' . $i . ']', 0));
189
        $form->addElement(new \XoopsFormHidden('field_mid', $fieldMid));
190
        $form->addElement(new \XoopsFormHidden('field_tid', $fieldTid));
191
192
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="' . $class . '">'));
193
        // Index ID
194
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $i . '</td>'));
195
        // Field Name
196
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName . '_id' : $fName . '_') : '');
197
        $fieldName     = new \XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name[' . $i . ']', 15, 255, $thisFieldName);
198
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldName->render() . '</td>'));
199
        // Field Element
200
        if ((1 == $i) && (1 == $tableAutoincrement)) {
201
            $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td>'));
202
        } else {
203
            // Field Elements
204
            $crElement = new \CriteriaCompo();
205
            $crElement->add(new \Criteria('fieldelement_tid', 0));
206
            $crTable = new \CriteriaCompo();
207
            $crTable->add(new \Criteria('fieldelement_mid', $fieldMid));
208
            $fieldElementsSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element[' . $i . ']');
209
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getFieldElementsList($crElement));
0 ignored issues
show
Bug introduced by
The method getFieldElementsList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

209
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->/** @scrutinizer ignore-call */ getFieldElementsList($crElement));
Loading history...
210
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crTable));
0 ignored issues
show
Bug introduced by
The method getList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsImageHandler or XoopsRankHandler or XoopsCommentHandler or XoopsTplsetHandler or XoopsAvatarHandler or XoopsBlockHandler or XoopsImagesetHandler or XoopsPersistableObjectHandler or XoopsImagecategoryHandler. ( Ignorable by Annotation )

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

210
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->/** @scrutinizer ignore-call */ getList($crTable));
Loading history...
211
            $fieldElementsSelect->setExtra(" onchange='presetField(". $i . ")' ");
212
            unset($crElement, $crTable);
213
            $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldElementsSelect->render() . '</td>'));
214
            unset($fieldElementsSelect);
215
        }
216
        // Field Type
217
        $value           = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
218
        $fieldTypeSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type[' . $i . ']', $value);
219
        $fieldTypeSelect->addOptionArray($helper->getHandler('Fieldtype')->getList());
220
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldTypeSelect->render() . '</td>'));
221
        // Field Value
222
        $value      = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
223
        $fieldValue = new \XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value[' . $i . ']', 10, 200, $value);
224
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldValue->render() . '</td>'));
225
        // Field Attributes
226
        $value                 = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
227
        $fieldAttributesSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute[' . $i . ']', $value);
228
        $fieldAttributesSelect->addOptionArray($helper->getHandler('Fieldattributes')->getList());
229
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldAttributesSelect->render() . '</td>'));
230
        // Field Null
231
        $value           = (1 == $i && 1 == $tableAutoincrement) ? '2' : '2';
232
        $fieldNullSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null[' . $i . ']', $value);
233
        $fieldNullSelect->addOptionArray($helper->getHandler('Fieldnull')->getList());
234
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldNullSelect->render() . '</td>'));
235
        // Field Default
236
        $fieldDefault = new \XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default[' . $i . ']', 15, 25);
237
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldDefault->render() . '</td>'));
238
        // Field Key
239
        $value          = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
240
        $fieldKeySelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key[' . $i . ']', $value);
241
        $fieldKeySelect->addOptionArray($helper->getHandler('Fieldkey')->getList());
242
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldKeySelect->render() . '</td>'));
243
        // Field Void
244
        if ((1 == $i) && (1 == $tableAutoincrement)) {
245
            $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td></tr>'));
246
        } else {
247
            // Box header row
248
            $parametersTray = new \XoopsFormElementTray('', '<br>');
249
250
            $field_parent     = 0;
251
            $checkFieldParent = new \XoopsFormCheckBox(' ', 'field_parent[' . $i . ']', $field_parent);
252
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
253
            $parametersTray->addElement($checkFieldParent);
254
255
            $field_admin     = 0;
256
            $checkFieldAdmin = new \XoopsFormCheckBox(' ', 'field_admin[' . $i . ']', $field_admin);
257
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
258
            $parametersTray->addElement($checkFieldAdmin);
259
260
            $field_inlist     = 0;
261
            $checkFieldInList = new \XoopsFormCheckBox(' ', 'field_inlist[' . $i . ']', $field_inlist);
262
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
263
            $parametersTray->addElement($checkFieldInList);
264
265
            $field_inform     = 0;
266
            $checkFieldInForm = new \XoopsFormCheckBox(' ', 'field_inform[' . $i . ']', $field_inform);
267
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
268
            $parametersTray->addElement($checkFieldInForm);
269
270
            $field_user     = 0;
271
            $checkFieldUser = new \XoopsFormCheckBox(' ', 'field_user[' . $i . ']', $field_user);
272
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
273
            $parametersTray->addElement($checkFieldUser);
274
275
            $field_thead     = 0;
276
            $checkFieldThead = new \XoopsFormCheckBox(' ', 'field_thead[' . $i . ']', $field_thead);
277
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
278
            $parametersTray->addElement($checkFieldThead);
279
280
            $field_tbody     = 0;
281
            $checkFieldTbody = new \XoopsFormCheckBox(' ', 'field_tbody[' . $i . ']', $field_tbody);
282
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
283
            $parametersTray->addElement($checkFieldTbody);
284
285
            $field_tfoot     = 0;
286
            $checkFieldTfoot = new \XoopsFormCheckBox(' ', 'field_tfoot[' . $i . ']', $field_tfoot);
287
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
288
            $parametersTray->addElement($checkFieldTfoot);
289
290
            $field_block     = 0;
291
            $checkFieldBlock = new \XoopsFormCheckBox('', 'field_block[' . $i . ']', $field_block);
292
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
293
            $parametersTray->addElement($checkFieldBlock);
294
295
            $field_search       = 0;
296
            $check_field_search = new \XoopsFormCheckBox(' ', 'field_search[' . $i . ']', $field_search);
297
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
298
            $parametersTray->addElement($check_field_search);
299
300
            $field_required     = 0;
301
            $checkFieldRequired = new \XoopsFormCheckBox(' ', 'field_required[' . $i . ']', $field_required);
302
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
303
            $parametersTray->addElement($checkFieldRequired);
304
305
            $fieldMain      = (1 == $tableAutoincrement) ? 2 : 1;
306
            $checkFieldMain = new Tdmcreate\Form\FormRadio('', 'field_main', $fieldMain);
307
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
308
            $parametersTray->addElement($checkFieldMain);
309
310
            $form->addElement(new Tdmcreate\Html\FormLabel('<td><div class="portlet"><div class="portlet-header">' . _AM_TDMCREATE_FIELD_PARAMETERS_LIST . '</div><div class="portlet-content">' . $parametersTray->render() . '</div></div></td></tr>'));
311
        }
312
    }
313
314
    /**
315
     * @public function getFormEdit
316
     *
317
     * @param null $fieldMid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldMid is correct as it would always require null to be passed?
Loading history...
318
     * @param null $fieldTid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fieldTid is correct as it would always require null to be passed?
Loading history...
319
     * @param bool $action
320
     * @return mixed
321
     */
322
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
323
    {
324
        $helper        = Tdmcreate\Helper::getInstance();
325
        $tablesHandler = $helper->getHandler('Tables');
326
        $tables        = $tablesHandler->get($fieldTid);
327
        $prefix        = $tables->getVar('table_fieldname');
328
        // Header function class
329
        $fieldsForm = self::getInstance();
330
        $form       = $fieldsForm->getHeaderForm($prefix, $action);
331
332
        $class = 'even';
333
        $tableAutoincrement = $tables->getVar('table_autoincrement');
334
        $fieldNumb          = $tables->getVar('table_nbfields');
335
        $fName              = $tables->getVar('table_fieldname');
336
337
        // Get the list of fields
338
        $cr = new \CriteriaCompo();
339
        $cr->add(new \Criteria('field_mid', $fieldMid));
340
        $cr->add(new \Criteria('field_tid', $fieldTid));
341
        $cr->setSort('field_order');
342
        $fields = $helper->getHandler('Fields')->getObjects($cr);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

342
        $fields = $helper->getHandler('Fields')->/** @scrutinizer ignore-call */ getObjects($cr);
Loading history...
343
        unset($cr);
344
        $fieldElements = $helper->getHandler('Fieldelements')->getAll();
345
        foreach ($fieldElements as $fe) {
346
            $form->addElement(new \XoopsFormHidden('fe_defaulttype[' . $fe->getVar('fieldelement_id') . ']', $fe->getVar('fieldelement_deftype')));
347
            $form->addElement(new \XoopsFormHidden('fe_defaultvalue[' . $fe->getVar('fieldelement_id') . ']', $fe->getVar('fieldelement_defvalue')));
348
        }
349
        $id = 1;
350
        foreach ($fields as $field) {
351
            $class   = ('even' === $class) ? 'odd' : 'even';
352
            $fieldId = (int)$field->getVar('field_id');
353
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
354
                $fieldsObj = $helper->getHandler('Fields')->get($fieldId);
355
                $helper->getHandler('Fields')->delete($fieldsObj, true);
0 ignored issues
show
Unused Code introduced by
The call to XoopsObjectHandler::delete() has too many arguments starting with true. ( Ignorable by Annotation )

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

355
                $helper->getHandler('Fields')->/** @scrutinizer ignore-call */ delete($fieldsObj, 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...
356
            } else {
357
                // show field with settings
358
                $form->addElement(new \XoopsFormHidden('field_id[' . $id . ']', $fieldId));
359
360
                $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="' . $class . '">'));
361
                // Index ID
362
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $id . '</td>'));
363
                // Field Name
364
                $fieldName = new \XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name[' . $id . ']', 15, 255, $field->getVar('field_name'));
365
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldName->render() . '</td>'));
366
                // Field Element
367
                if ((1 == $id) && (1 == $tableAutoincrement)) {
368
                    $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td>'));
369
                } else {
370
                    // Field Elements
371
                    $crElement = new \CriteriaCompo();
372
                    $crElement->add(new \Criteria('fieldelement_tid', 0));
373
                    $crTable = new \CriteriaCompo();
374
                    $crTable->add(new \Criteria('fieldelement_mid', $fieldMid));
375
                    $fieldElementsSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element[' . $id . ']', $field->getVar('field_element'));
376
                    $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getFieldElementsList($crElement));
377
                    $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crTable));
378
                    $fieldElementsSelect->setExtra(" onchange='presetField(". $id . ")' ");
379
                    unset($crElement, $crTable);
380
                    $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldElementsSelect->render() . '</td>'));
381
                    unset($fieldElementsSelect);
382
                }
383
                // Field Type
384
                $fieldTypeSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type[' . $id . ']', $field->getVar('field_type'));
385
                $fieldTypeSelect->addOptionArray($helper->getHandler('Fieldtype')->getList());
386
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldTypeSelect->render() . '</td>'));
387
                // Field Value
388
                $fieldValue = new \XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value[' . $id . ']', 10, 200, $field->getVar('field_value'));
389
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldValue->render() . '</td>'));
390
                // Field Attributes
391
                $fieldAttributesSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute[' . $id . ']', $field->getVar('field_attribute'));
392
                $fieldAttributesSelect->addOptionArray($helper->getHandler('Fieldattributes')->getList());
393
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldAttributesSelect->render() . '</td>'));
394
                // Field Null
395
                $fieldNullSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null[' . $id . ']', $field->getVar('field_null'));
396
                $fieldNullSelect->addOptionArray($helper->getHandler('Fieldnull')->getList());
397
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldNullSelect->render() . '</td>'));
398
                // Field Default
399
                $fieldDefault = new \XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default[' . $id . ']', 15, 25, $field->getVar('field_default'));
400
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldDefault->render() . '</td>'));
401
                // Field Key
402
                $fieldKeySelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key[' . $id . ']', $field->getVar('field_key'));
403
                $fieldKeySelect->addOptionArray($helper->getHandler('Fieldkey')->getList());
404
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldKeySelect->render() . '</td>'));
405
                // Field Void
406
                if ((1 == $id) && (1 == $tableAutoincrement)) {
407
                    $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td></tr>'));
408
                } else {
409
                    // Box header row
410
                    $parametersTray = new \XoopsFormElementTray('', '<br>');
411
412
                    $checkFieldParent = new \XoopsFormCheckBox(' ', 'field_parent[' . $id . ']', $field->getVar('field_parent'));
413
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
414
                    $parametersTray->addElement($checkFieldParent);
415
416
                    $checkFieldAdmin = new \XoopsFormCheckBox(' ', 'field_admin[' . $id . ']', $field->getVar('field_admin'));
417
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
418
                    $parametersTray->addElement($checkFieldAdmin);
419
420
                    $checkFieldInList = new \XoopsFormCheckBox(' ', 'field_inlist[' . $id . ']', $field->getVar('field_inlist'));
421
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
422
                    $parametersTray->addElement($checkFieldInList);
423
424
                    $checkFieldInForm = new \XoopsFormCheckBox(' ', 'field_inform[' . $id . ']', $field->getVar('field_inform'));
425
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
426
                    $parametersTray->addElement($checkFieldInForm);
427
428
                    $checkFieldUser = new \XoopsFormCheckBox(' ', 'field_user[' . $id . ']', $field->getVar('field_user'));
429
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
430
                    $parametersTray->addElement($checkFieldUser);
431
432
                    $checkFieldThead = new \XoopsFormCheckBox(' ', 'field_thead[' . $id . ']', $field->getVar('field_thead'));
433
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
434
                    $parametersTray->addElement($checkFieldThead);
435
436
                    $checkFieldTbody = new \XoopsFormCheckBox(' ', 'field_tbody[' . $id . ']', $field->getVar('field_tbody'));
437
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
438
                    $parametersTray->addElement($checkFieldTbody);
439
440
                    $checkFieldTfoot = new \XoopsFormCheckBox(' ', 'field_tfoot[' . $id . ']', $field->getVar('field_tfoot'));
441
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
442
                    $parametersTray->addElement($checkFieldTfoot);
443
444
                    $checkFieldBlock = new \XoopsFormCheckBox('', 'field_block[' . $id . ']', $field->getVar('field_block'));
445
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
446
                    $parametersTray->addElement($checkFieldBlock);
447
448
                    $check_field_search = new \XoopsFormCheckBox(' ', 'field_search[' . $id . ']', $field->getVar('field_search'));
449
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
450
                    $parametersTray->addElement($check_field_search);
451
452
                    $checkFieldRequired = new \XoopsFormCheckBox(' ', 'field_required[' . $id . ']', $field->getVar('field_required'));
453
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
454
                    $parametersTray->addElement($checkFieldRequired);
455
456
                    $fieldMain      = (1 == $field->getVar('field_main')) ? $id : 1;
457
                    $checkFieldMain = new Tdmcreate\Form\FormRadio('', 'field_main', $fieldMain);
458
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
459
                    $parametersTray->addElement($checkFieldMain);
460
461
                    $form->addElement(new Tdmcreate\Html\FormLabel('<td><div class="portlet"><div class="portlet-header">' . _AM_TDMCREATE_FIELD_PARAMETERS_LIST . '</div><div class="portlet-content">' . $parametersTray->render() . '</div></div></td></tr>'));
462
                }
463
            }
464
            ++$id;
465
        }
466
        // If you change number fields in tables,
467
        // adding missing fields or delete unnecessary fields
468
        // By goffy
469
        for ($i = $id; $i <= $fieldNumb; ++$i) {
470
            $class = ('even' === $class) ? 'odd' : 'even';
471
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
472
        }
473
        unset($id);
474
475
        // Footer form
476
        return $fieldsForm->getFooterForm($form);
477
    }
478
479
    /**
480
     * @private function getFooterForm
481
     *
482
     * @param $form
483
     *
484
     * @return mixed
485
     */
486
    private function getFooterForm($form)
487
    {
488
        // Send Form Data
489
        $form->addElement(new Tdmcreate\Html\FormLabel('</tbody>'));
490
        $form->addElement(new Tdmcreate\Html\FormLabel('<tfoot><tr>'));
491
        $formHidden = new \XoopsFormHidden('op', 'save');
492
        $formButton = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
493
        $form->addElement(new Tdmcreate\Html\FormLabel('<td colspan="8">' . $formHidden->render() . '</td>'));
494
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . $formButton->render() . '</td>'));
495
        $form->addElement(new Tdmcreate\Html\FormLabel('</tr></tfoot></table>'));
496
497
        return $form;
498
    }
499
500
    /**
501
     * Get Values.
502
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
503
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
504
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
505
     * @return array
506
     */
507
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
508
    {
509
        $ret             = $this->getValues($keys, $format, $maxDepth);
510
        $ret['id']       = $this->getVar('field_id');
511
        $ret['mid']      = $this->getVar('field_mid');
512
        $ret['tid']      = $this->getVar('field_tid');
513
        $ret['order']    = $this->getVar('field_order');
514
        $ret['name']     = str_replace('_', ' ', ucfirst($this->getVar('field_name')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('field_name') can also be of type array and array; however, parameter $str of ucfirst() 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

514
        $ret['name']     = str_replace('_', ' ', ucfirst(/** @scrutinizer ignore-type */ $this->getVar('field_name')));
Loading history...
515
        $ret['parent']   = $this->getVar('field_parent');
516
        $ret['inlist']   = $this->getVar('field_inlist');
517
        $ret['inform']   = $this->getVar('field_inform');
518
        $ret['admin']    = $this->getVar('field_admin');
519
        $ret['user']     = $this->getVar('field_user');
520
        $ret['block']    = $this->getVar('field_block');
521
        $ret['main']     = $this->getVar('field_main');
522
        $ret['search']   = $this->getVar('field_search');
523
        $ret['required'] = $this->getVar('field_required');
524
525
        return $ret;
526
    }
527
}
528