Completed
Pull Request — master (#144)
by Michael
03:08
created

Fields::getFormNewLine()   F

Complexity

Conditions 16
Paths 12288

Size

Total Lines 119
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 16
eloc 92
nc 12288
nop 7
dl 0
loc 119
rs 1.2945
c 1
b 0
f 0

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
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
     * @return Tdmcreate\Form\ThemeForm
101
     */
102
    private function getHeaderForm($action = false)
103
    {
104
        if (false === $action) {
105
            $action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
106
        }
107
108
        $isNew = $this->isNew();
109
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
110
111
        $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

111
        $form = new Tdmcreate\Form\ThemeForm(null, 'form', /** @scrutinizer ignore-type */ $action, 'post', true);
Loading history...
112
        $form->setExtra('enctype="multipart/form-data"');
113
114
        // New Object HtmlTable
115
        $form->addElement(new Tdmcreate\Html\FormLabel('<table cellspacing="1" class="outer width100">'));
116
        $form->addElement(new Tdmcreate\Html\FormLabel('<thead class="center">'));
117
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head"><th colspan="9">' . $title . '</th></tr>'));
118
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head width5">'));
119
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ID . '</td>'));
120
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NAME . '</td>'));
121
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_TYPE . '</td>'));
122
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_VALUE . '</th>'));
123
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ATTRIBUTE . '</th>'));
124
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NULL . '</th>'));
125
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_DEFAULT . '</th>'));
126
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_KEY . '</th>'));
127
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_PARAMETERS . '</th>'));
128
        $form->addElement(new Tdmcreate\Html\FormLabel('</tr></thead>'));
129
        $form->addElement(new Tdmcreate\Html\FormLabel('<tbody>'));
130
131
        return $form;
132
    }
133
134
    /**
135
     * @public function getFormNew
136
     *
137
     * @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...
138
     * @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...
139
     * @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...
140
     * @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...
141
     * @param bool $action
142
     * @return mixed
143
     */
144
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
145
    {
146
        $helper = Tdmcreate\Helper::getInstance();
147
        // Header function class
148
        $fieldsForm = self::getInstance();
149
        $form       = $fieldsForm->getHeaderForm($action);
150
        // Get handler tables
151
        $tableObj           = $helper->getHandler('Tables'); // Changed by goffy
152
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement'); // Added by goffy
153
        // Loop for fields number
154
        $class = 'even';
155
        for ($i = 1; $i <= $fieldNumb; ++$i) {
156
            $class = ('even' === $class) ? 'odd' : 'even';
157
            // Replaced creation of new line by new function - goffy
158
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
159
        }
160
161
        // Footer form
162
        return $fieldsForm->getFooterForm($form);
163
    }
164
165
    /**
166
     * @private function getFormNewLine
167
     *
168
     * @param $form
169
     * @param $class
170
     * @param $i
171
     * @param $fieldMid
172
     * @param $fieldTid
173
     * @param $fName
174
     * @param $tableAutoincrement
175
     */
176
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
177
    {
178
        $helper = Tdmcreate\Helper::getInstance();
179
        $form->addElement(new \XoopsFormHidden('field_id[' . $i . ']', 0));
180
        $form->addElement(new \XoopsFormHidden('field_mid', $fieldMid));
181
        $form->addElement(new \XoopsFormHidden('field_tid', $fieldTid));
182
183
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="' . $class . '">'));
184
        // Index ID
185
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $i . '</td>'));
186
        // Field Name
187
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName . '_id' : $fName . '_') : '');
188
        $fieldName     = new \XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name[' . $i . ']', 15, 255, $thisFieldName);
189
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldName->render() . '</td>'));
190
        // Field Type
191
        $value           = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
192
        $fieldTypeSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type[' . $i . ']', $value);
193
        $fieldTypeSelect->addOptionArray($helper->getHandler('Fieldtype')->getList());
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

193
        $fieldTypeSelect->addOptionArray($helper->getHandler('Fieldtype')->/** @scrutinizer ignore-call */ getList());
Loading history...
194
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldTypeSelect->render() . '</td>'));
195
        // Field Value
196
        $value      = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
197
        $fieldValue = new \XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value[' . $i . ']', 10, 200, $value);
198
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldValue->render() . '</td>'));
199
        // Field Attributes
200
        $value                 = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
201
        $fieldAttributesSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute[' . $i . ']', $value);
202
        $fieldAttributesSelect->addOptionArray($helper->getHandler('Fieldattributes')->getList());
203
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldAttributesSelect->render() . '</td>'));
204
        // Field Null
205
        $value           = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '2';
206
        $fieldNullSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null[' . $i . ']', $value);
207
        $fieldNullSelect->addOptionArray($helper->getHandler('Fieldnull')->getList());
208
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldNullSelect->render() . '</td>'));
209
        // Field Default
210
        $fieldDefault = new \XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default[' . $i . ']', 15, 25);
211
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldDefault->render() . '</td>'));
212
        // Field Key
213
        $value          = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
214
        $fieldKeySelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key[' . $i . ']', $value);
215
        $fieldKeySelect->addOptionArray($helper->getHandler('Fieldkey')->getList());
216
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldKeySelect->render() . '</td>'));
217
        // Field Void
218
        if ((1 == $i) && (1 == $tableAutoincrement)) {
219
            $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td></tr>'));
220
        } else {
221
            // Box header row
222
            $parametersTray = new \XoopsFormElementTray('', '<br>');
223
            // Field Elements
224
            $crElement = new \CriteriaCompo();
225
            $crElement->add(new \Criteria('fieldelement_tid', 0));
226
            $crTable = new \CriteriaCompo();
227
            $crTable->add(new \Criteria('fieldelement_mid', $fieldMid));
228
            $fieldElementsSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element[' . $i . ']');
229
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crElement));
230
            $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crTable));
231
            unset($crElement, $crTable);
232
            $parametersTray->addElement($fieldElementsSelect);
233
234
            $field_parent     = 0;
235
            $checkFieldParent = new \XoopsFormCheckBox(' ', 'field_parent[' . $i . ']', $field_parent);
236
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
237
            $parametersTray->addElement($checkFieldParent);
238
239
            $field_admin     = 0;
240
            $checkFieldAdmin = new \XoopsFormCheckBox(' ', 'field_admin[' . $i . ']', $field_admin);
241
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
242
            $parametersTray->addElement($checkFieldAdmin);
243
244
            $field_inlist     = 0;
245
            $checkFieldInList = new \XoopsFormCheckBox(' ', 'field_inlist[' . $i . ']', $field_inlist);
246
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
247
            $parametersTray->addElement($checkFieldInList);
248
249
            $field_inform     = 0;
250
            $checkFieldInForm = new \XoopsFormCheckBox(' ', 'field_inform[' . $i . ']', $field_inform);
251
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
252
            $parametersTray->addElement($checkFieldInForm);
253
254
            $field_user     = 0;
255
            $checkFieldUser = new \XoopsFormCheckBox(' ', 'field_user[' . $i . ']', $field_user);
256
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
257
            $parametersTray->addElement($checkFieldUser);
258
259
            $field_thead     = 0;
260
            $checkFieldThead = new \XoopsFormCheckBox(' ', 'field_thead[' . $i . ']', $field_thead);
261
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
262
            $parametersTray->addElement($checkFieldThead);
263
264
            $field_tbody     = 0;
265
            $checkFieldTbody = new \XoopsFormCheckBox(' ', 'field_tbody[' . $i . ']', $field_tbody);
266
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
267
            $parametersTray->addElement($checkFieldTbody);
268
269
            $field_tfoot     = 0;
270
            $checkFieldTfoot = new \XoopsFormCheckBox(' ', 'field_tfoot[' . $i . ']', $field_tfoot);
271
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
272
            $parametersTray->addElement($checkFieldTfoot);
273
274
            $field_block     = 0;
275
            $checkFieldBlock = new \XoopsFormCheckBox('', 'field_block[' . $i . ']', $field_block);
276
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
277
            $parametersTray->addElement($checkFieldBlock);
278
279
            $field_search       = 0;
280
            $check_field_search = new \XoopsFormCheckBox(' ', 'field_search[' . $i . ']', $field_search);
281
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
282
            $parametersTray->addElement($check_field_search);
283
284
            $field_required     = 0;
285
            $checkFieldRequired = new \XoopsFormCheckBox(' ', 'field_required[' . $i . ']', $field_required);
286
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
287
            $parametersTray->addElement($checkFieldRequired);
288
289
            $fieldMain      = (1 == $tableAutoincrement) ? 2 : 1;
290
            $checkFieldMain = new Tdmcreate\Form\FormRadio('', 'field_main', $fieldMain);
291
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
292
            $parametersTray->addElement($checkFieldMain);
293
294
            $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>'));
295
        }
296
    }
297
298
    /**
299
     * @public function getFormEdit
300
     *
301
     * @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...
302
     * @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...
303
     * @param bool $action
304
     * @return mixed
305
     */
306
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
307
    {
308
        $helper = Tdmcreate\Helper::getInstance();
309
        // Header function class
310
        $fieldsForm = self::getInstance();
311
        $form       = $fieldsForm->getHeaderForm($action);
312
313
        $class = 'even';
314
        // Get the number of fields - goffy
315
        $tablesHandler      = $helper->getHandler('Tables');
316
        $tables             = $tablesHandler->get($fieldTid);
317
        $tableAutoincrement = $tables->getVar('table_autoincrement');
318
        $fieldNumb          = $tables->getVar('table_nbfields');
319
        $fName              = $tables->getVar('table_fieldname');
320
321
        // Get the list of fields
322
        $cr = new \CriteriaCompo();
323
        $cr->add(new \Criteria('field_mid', $fieldMid));
324
        $cr->add(new \Criteria('field_tid', $fieldTid));
325
        $cr->setSort('field_order'); //added by goffy
326
        $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

326
        $fields = $helper->getHandler('Fields')->/** @scrutinizer ignore-call */ getObjects($cr);
Loading history...
327
        unset($cr);
328
        $id = 1;
329
        foreach ($fields as $field) {
330
            $class   = ('even' === $class) ? 'odd' : 'even';
331
            $fieldId = (int)$field->getVar('field_id');
332
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
333
                $fieldsObj = $helper->getHandler('Fields')->get($fieldId);
334
                $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

334
                $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...
335
            } else {
336
                // show field with settings
337
                $form->addElement(new \XoopsFormHidden('field_id[' . $id . ']', $fieldId));
338
339
                $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="' . $class . '">'));
340
                // Index ID
341
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $id . '</td>'));
342
                // Field Name
343
                $fieldName = new \XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name[' . $id . ']', 15, 255, $field->getVar('field_name'));
344
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldName->render() . '</td>'));
345
                // Field Type
346
                $fieldTypeSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type[' . $id . ']', $field->getVar('field_type'));
347
                $fieldTypeSelect->addOptionArray($helper->getHandler('Fieldtype')->getList());
348
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldTypeSelect->render() . '</td>'));
349
                // Field Value
350
                $fieldValue = new \XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value[' . $id . ']', 10, 200, $field->getVar('field_value'));
351
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldValue->render() . '</td>'));
352
                // Field Attributes
353
                $fieldAttributesSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute[' . $id . ']', $field->getVar('field_attribute'));
354
                $fieldAttributesSelect->addOptionArray($helper->getHandler('Fieldattributes')->getList());
355
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldAttributesSelect->render() . '</td>'));
356
                // Field Null
357
                $fieldNullSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null[' . $id . ']', $field->getVar('field_null'));
358
                $fieldNullSelect->addOptionArray($helper->getHandler('Fieldnull')->getList());
359
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldNullSelect->render() . '</td>'));
360
                // Field Default
361
                $fieldDefault = new \XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default[' . $id . ']', 15, 25, $field->getVar('field_default'));
362
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldDefault->render() . '</td>'));
363
                // Field Key
364
                $fieldKeySelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key[' . $id . ']', $field->getVar('field_key'));
365
                $fieldKeySelect->addOptionArray($helper->getHandler('Fieldkey')->getList());
366
                $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldKeySelect->render() . '</td>'));
367
                // Field Void
368
                if ((1 == $id) && (1 == $tableAutoincrement)) {
369
                    $form->addElement(new Tdmcreate\Html\FormLabel('<td>&nbsp;</td></tr>'));
370
                } else {
371
                    // Box header row
372
                    $parametersTray = new \XoopsFormElementTray('', '<br>');
373
                    // Field Elements
374
                    $crElement = new \CriteriaCompo();
375
                    $crElement->add(new \Criteria('fieldelement_tid', 0));
376
                    $crTable = new \CriteriaCompo();
377
                    $crTable->add(new \Criteria('fieldelement_mid', $fieldMid));
378
                    $fieldElementsSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element[' . $id . ']', $field->getVar('field_element'));
379
                    $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crElement));
380
                    $fieldElementsSelect->addOptionArray($helper->getHandler('Fieldelements')->getList($crTable));
381
                    unset($crElement, $crTable);
382
                    $parametersTray->addElement($fieldElementsSelect);
383
384
                    $checkFieldParent = new \XoopsFormCheckBox(' ', 'field_parent[' . $id . ']', $field->getVar('field_parent'));
385
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
386
                    $parametersTray->addElement($checkFieldParent);
387
388
                    $checkFieldAdmin = new \XoopsFormCheckBox(' ', 'field_admin[' . $id . ']', $field->getVar('field_admin'));
389
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
390
                    $parametersTray->addElement($checkFieldAdmin);
391
392
                    $checkFieldInList = new \XoopsFormCheckBox(' ', 'field_inlist[' . $id . ']', $field->getVar('field_inlist'));
393
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
394
                    $parametersTray->addElement($checkFieldInList);
395
396
                    $checkFieldInForm = new \XoopsFormCheckBox(' ', 'field_inform[' . $id . ']', $field->getVar('field_inform'));
397
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
398
                    $parametersTray->addElement($checkFieldInForm);
399
400
                    $checkFieldUser = new \XoopsFormCheckBox(' ', 'field_user[' . $id . ']', $field->getVar('field_user'));
401
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
402
                    $parametersTray->addElement($checkFieldUser);
403
404
                    $checkFieldThead = new \XoopsFormCheckBox(' ', 'field_thead[' . $id . ']', $field->getVar('field_thead'));
405
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
406
                    $parametersTray->addElement($checkFieldThead);
407
408
                    $checkFieldTbody = new \XoopsFormCheckBox(' ', 'field_tbody[' . $id . ']', $field->getVar('field_tbody'));
409
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
410
                    $parametersTray->addElement($checkFieldTbody);
411
412
                    $checkFieldTfoot = new \XoopsFormCheckBox(' ', 'field_tfoot[' . $id . ']', $field->getVar('field_tfoot'));
413
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
414
                    $parametersTray->addElement($checkFieldTfoot);
415
416
                    $checkFieldBlock = new \XoopsFormCheckBox('', 'field_block[' . $id . ']', $field->getVar('field_block'));
417
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
418
                    $parametersTray->addElement($checkFieldBlock);
419
420
                    $check_field_search = new \XoopsFormCheckBox(' ', 'field_search[' . $id . ']', $field->getVar('field_search'));
421
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
422
                    $parametersTray->addElement($check_field_search);
423
424
                    $checkFieldRequired = new \XoopsFormCheckBox(' ', 'field_required[' . $id . ']', $field->getVar('field_required'));
425
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
426
                    $parametersTray->addElement($checkFieldRequired);
427
428
                    $fieldMain      = (1 == $field->getVar('field_main')) ? $id : 1;
429
                    $checkFieldMain = new Tdmcreate\Form\FormRadio('', 'field_main', $fieldMain);
430
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
431
                    $parametersTray->addElement($checkFieldMain);
432
433
                    $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>'));
434
                }
435
            }
436
            ++$id;
437
        }
438
        // If you change number fields in tables,
439
        // adding missing fields or delete unnecessary fields
440
        // By goffy
441
        for ($i = $id; $i <= $fieldNumb; ++$i) {
442
            $class = ('even' === $class) ? 'odd' : 'even';
443
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
444
        }
445
        unset($id);
446
447
        // Footer form
448
        return $fieldsForm->getFooterForm($form);
449
    }
450
451
    /**
452
     * @private function getFooterForm
453
     *
454
     * @param $form
455
     *
456
     * @return mixed
457
     */
458
    private function getFooterForm($form)
459
    {
460
        // Send Form Data
461
        $form->addElement(new Tdmcreate\Html\FormLabel('</tbody>'));
462
        $form->addElement(new Tdmcreate\Html\FormLabel('<tfoot><tr>'));
463
        $formHidden = new \XoopsFormHidden('op', 'save');
464
        $formButton = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
465
        $form->addElement(new Tdmcreate\Html\FormLabel('<td colspan="8">' . $formHidden->render() . '</td>'));
466
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . $formButton->render() . '</td>'));
467
        $form->addElement(new Tdmcreate\Html\FormLabel('</tr></tfoot></table>'));
468
469
        return $form;
470
    }
471
472
    /**
473
     * Get Values.
474
     * @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...
475
     * @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...
476
     * @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...
477
     * @return array
478
     */
479
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
480
    {
481
        $ret             = $this->getValues($keys, $format, $maxDepth);
482
        $ret['id']       = $this->getVar('field_id');
483
        $ret['mid']      = $this->getVar('field_mid');
484
        $ret['tid']      = $this->getVar('field_tid');
485
        $ret['order']    = $this->getVar('field_order');
486
        $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

486
        $ret['name']     = str_replace('_', ' ', ucfirst(/** @scrutinizer ignore-type */ $this->getVar('field_name')));
Loading history...
487
        $ret['parent']   = $this->getVar('field_parent');
488
        $ret['inlist']   = $this->getVar('field_inlist');
489
        $ret['inform']   = $this->getVar('field_inform');
490
        $ret['admin']    = $this->getVar('field_admin');
491
        $ret['user']     = $this->getVar('field_user');
492
        $ret['block']    = $this->getVar('field_block');
493
        $ret['main']     = $this->getVar('field_main');
494
        $ret['search']   = $this->getVar('field_search');
495
        $ret['required'] = $this->getVar('field_required');
496
497
        return $ret;
498
    }
499
}
500