Passed
Pull Request — master (#144)
by Michael
03:10
created

Fields   A

Complexity

Total Complexity 38

Size/Duplication

Total Lines 465
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 280
dl 0
loc 465
rs 9.36
c 2
b 0
f 0
wmc 38

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormNew() 0 19 3
A getInstance() 0 8 2
A getHeaderForm() 0 30 3
A getFooterForm() 0 12 1
A __call() 0 5 2
A getValuesFields() 0 19 1
A __construct() 0 26 1
F getFormNewLine() 0 119 16
C getFormEdit() 0 143 9
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
 * @version         $Id: 1.91 fields.php 12258 2014-01-02 09:33:29Z timgno $
28
 */
29
//include __DIR__.'/autoload.php';
30
31
/**
32
 * Class Fields.
33
 */
34
class Fields extends \XoopsObject
35
{
36
    /**
37
     *  @public function constructor class
38
     *
39
     *  @param null
40
     */
41
    public function __construct()
42
    {
43
        $this->initVar('field_id', XOBJ_DTYPE_INT);
44
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
45
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
46
        $this->initVar('field_order', XOBJ_DTYPE_INT);
47
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
54
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
55
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
56
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
57
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
58
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
59
        $this->initVar('field_user', XOBJ_DTYPE_INT);
60
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
61
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
62
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
63
        $this->initVar('field_block', XOBJ_DTYPE_INT);
64
        $this->initVar('field_main', XOBJ_DTYPE_INT);
65
        $this->initVar('field_search', XOBJ_DTYPE_INT);
66
        $this->initVar('field_required', XOBJ_DTYPE_INT);
67
    }
68
69
    /**
70
     * @param string $method
71
     * @param array  $args
72
     *
73
     * @return mixed
74
     */
75
    public function __call($method, $args)
76
    {
77
        $arg = isset($args[0]) ? $args[0] : null;
78
79
        return $this->getVar($method, $arg);
80
    }
81
82
    /**
83
     * @static function getInstance
84
     *
85
     * @return Fields
86
     */
87
    public static function getInstance()
88
    {
89
        static $instance = false;
90
        if (!$instance) {
91
            $instance = new self();
92
        }
93
94
        return $instance;
95
    }
96
97
    /**
98
     * @private function getHeaderForm
99
     *
100
     * @param bool $action
101
     * @return Tdmcreate\Form\ThemeForm
102
     */
103
    private function getHeaderForm($action = false)
104
    {
105
        if (false === $action) {
106
            $action = $_SERVER['REQUEST_URI'];
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);
113
        $form->setExtra('enctype="multipart/form-data"');
114
115
        // New Object HtmlTable
116
        $form->addElement(new Tdmcreate\Html\FormLabel('<table cellspacing="1" class="outer width100">'));
117
        $form->addElement(new Tdmcreate\Html\FormLabel('<thead class="center">'));
118
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head"><th colspan="9">' . $title . '</th></tr>'));
119
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="head width5">'));
120
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ID . '</td>'));
121
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NAME . '</td>'));
122
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_TYPE . '</td>'));
123
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_VALUE . '</th>'));
124
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_ATTRIBUTE . '</th>'));
125
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_NULL . '</th>'));
126
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_DEFAULT . '</th>'));
127
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_KEY . '</th>'));
128
        $form->addElement(new Tdmcreate\Html\FormLabel('<td>' . _AM_TDMCREATE_FIELD_PARAMETERS . '</th>'));
129
        $form->addElement(new Tdmcreate\Html\FormLabel('</tr></thead>'));
130
        $form->addElement(new Tdmcreate\Html\FormLabel('<tbody>'));
131
132
        return $form;
133
    }
134
135
    /**
136
     * @public function getFormNew
137
     *
138
     * @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...
139
     * @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...
140
     * @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...
141
     * @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...
142
     * @param bool $action
143
     * @return mixed
144
     */
145
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
146
    {
147
        $helper = Tdmcreate\Helper::getInstance();
148
        // Header function class
149
        $fieldsForm = self::getInstance();
150
        $form = $fieldsForm->getHeaderForm($action);
151
        // Get handler tables
152
        $tableObj = $helper->getHandler('Tables'); // Changed by goffy
153
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement'); // Added by goffy
154
        // Loop for fields number
155
        $class = 'even';
156
        for ($i = 1; $i <= $fieldNumb; ++$i) {
157
            $class = ('even' === $class) ? 'odd' : 'even';
158
            // Replaced creation of new line by new function - goffy
159
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
160
        }
161
162
        // Footer form
163
        return $fieldsForm->getFooterForm($form);
164
    }
165
166
    /**
167
     * @private function getFormNewLine
168
     *
169
     * @param $form
170
     * @param $class
171
     * @param $i
172
     * @param $fieldMid
173
     * @param $fieldTid
174
     * @param $fName
175
     * @param $tableAutoincrement
176
     */
177
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
178
    {
179
        $helper = Tdmcreate\Helper::getInstance();
180
        $form->addElement(new \XoopsFormHidden('field_id[' . $i . ']', 0));
181
        $form->addElement(new \XoopsFormHidden('field_mid', $fieldMid));
182
        $form->addElement(new \XoopsFormHidden('field_tid', $fieldTid));
183
184
        $form->addElement(new Tdmcreate\Html\FormLabel('<tr class="' . $class . '">'));
185
        // Index ID
186
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $i . '</td>'));
187
        // Field Name
188
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName . '_id' : $fName . '_') : '');
189
        $fieldName = new \XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name[' . $i . ']', 15, 255, $thisFieldName);
190
        $form->addElement(new Tdmcreate\Html\FormLabel('<td class="center">' . $fieldName->render() . '</td>'));
191
        // Field Type
192
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
193
        $fieldTypeSelect = new \XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type[' . $i . ']', $value);
194
        $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

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

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

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

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