Passed
Branch master (38ab27)
by Michael
03:06
created

TDMCreateFields::getFormNewLine()   F

Complexity

Conditions 16
Paths 12288

Size

Total Lines 119
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 92
nc 12288
nop 7
dl 0
loc 119
rs 2
c 0
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
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * tdmcreatereate module.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.7
20
 *
21
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
22
 *
23
 * @version         $Id: 1.91 fields.php 12258 2014-01-02 09:33:29Z timgno $
24
 */
25
include __DIR__.'/autoload.php';
26
27
/**
28
 * Class TDMCreateFields.
29
 */
30
class TDMCreateFields extends XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
{
32
    /**
33
     *  @public function constructor class
34
     *
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        $this->initVar('field_id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
40
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
41
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
42
        $this->initVar('field_order', XOBJ_DTYPE_INT);
43
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
45
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
46
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
47
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
52
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
53
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
54
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
55
        $this->initVar('field_user', XOBJ_DTYPE_INT);
56
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
57
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
58
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
59
        $this->initVar('field_block', XOBJ_DTYPE_INT);
60
        $this->initVar('field_main', XOBJ_DTYPE_INT);
61
        $this->initVar('field_search', XOBJ_DTYPE_INT);
62
        $this->initVar('field_required', XOBJ_DTYPE_INT);
63
    }
64
65
    /**
66
     * @param string $method
67
     * @param array  $args
68
     *
69
     * @return mixed
70
     */
71
    public function __call($method, $args)
72
    {
73
        $arg = isset($args[0]) ? $args[0] : null;
74
75
        return $this->getVar($method, $arg);
76
    }
77
78
    /**
79
     * @static function getInstance
80
     *
81
     * @return TDMCreateFields
82
     */
83
    public static function getInstance()
84
    {
85
        static $instance = false;
86
        if (!$instance) {
87
            $instance = new self();
88
        }
89
90
        return $instance;
91
    }
92
93
    /**
94
     * @private function getHeaderForm
95
     *
96
     * @param bool $action
97
     * @return TDMCreateThemeForm
98
     */
99
    private function getHeaderForm($action = false)
100
    {
101
        if (false === $action) {
102
            $action = $_SERVER['REQUEST_URI'];
103
        }
104
105
        $isNew = $this->isNew();
106
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
107
108
        $form = new TDMCreateThemeForm(null, 'form', $action, 'post', true);
109
        $form->setExtra('enctype="multipart/form-data"');
110
111
        // New Object HtmlTable
112
        $form->addElement(new TDMCreateFormLabel('<table cellspacing="1" class="outer width100">'));
113
        $form->addElement(new TDMCreateFormLabel('<thead class="center">'));
114
        $form->addElement(new TDMCreateFormLabel('<tr class="head"><th colspan="9">'.$title.'</th></tr>'));
115
        $form->addElement(new TDMCreateFormLabel('<tr class="head width5">'));
116
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ID.'</td>'));
117
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NAME.'</td>'));
118
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_TYPE.'</td>'));
119
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_VALUE.'</th>'));
120
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ATTRIBUTE.'</th>'));
121
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NULL.'</th>'));
122
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_DEFAULT.'</th>'));
123
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_KEY.'</th>'));
124
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_PARAMETERS.'</th>'));
125
        $form->addElement(new TDMCreateFormLabel('</tr></thead>'));
126
        $form->addElement(new TDMCreateFormLabel('<tbody>'));
127
128
        return $form;
129
    }
130
131
    /**
132
     * @public function getFormNew
133
     *
134
     * @param null $fieldMid
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...
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...
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...
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...
135
     * @param null $fieldTid
136
     * @param null $fieldNumb
137
     * @param null $fieldName
138
     * @param bool $action
139
     * @return mixed
140
     */
141
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
142
    {
143
        $tdmcreate = TDMCreateHelper::getInstance();
144
        // Header function class
145
        $fieldsForm = self::getInstance();
146
        $form = $fieldsForm->getHeaderForm($action);
147
        // Get handler tables
148
        $tableObj = $tdmcreate->getHandler('tables'); // Changed by goffy
149
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement'); // Added by goffy
150
        // Loop for fields number
151
        $class = 'even';
152
        for ($i = 1; $i <= $fieldNumb; ++$i) {
153
            $class = ('even' === $class) ? 'odd' : 'even';
154
            // Replaced creation of new line by new function - goffy
155
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
156
        }
157
158
        // Footer form
159
        return $fieldsForm->getFooterForm($form);
160
    }
161
162
    /**
163
     * @private function getFormNewLine
164
     *
165
     * @param $form
166
     * @param $class
167
     * @param $i
168
     * @param $fieldMid
169
     * @param $fieldTid
170
     * @param $fName
171
     * @param $tableAutoincrement
172
     */
173
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
174
    {
175
        $tdmcreate = TDMCreateHelper::getInstance();
176
        $form->addElement(new XoopsFormHidden('field_id['.$i.']', 0));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
177
        $form->addElement(new XoopsFormHidden('field_mid', $fieldMid));
178
        $form->addElement(new XoopsFormHidden('field_tid', $fieldTid));
179
180
        $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
181
        // Index ID
182
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>'));
183
        // Field Name
184
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName.'_id' : $fName.'_') : '');
185
        $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $thisFieldName);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
186
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
187
        // Field Type
188
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
189
        $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
190
        $fieldTypeSelect->addOptionArray($tdmcreate->getHandler('fieldtype')->getList());
191
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
192
        // Field Value
193
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
194
        $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 10, 200, $value);
195
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
196
        // Field Attributes
197
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
198
        $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']', $value);
199
        $fieldAttributesSelect->addOptionArray($tdmcreate->getHandler('fieldattributes')->getList());
200
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
201
        // Field Null
202
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '2';
203
        $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']', $value);
204
        $fieldNullSelect->addOptionArray($tdmcreate->getHandler('fieldnull')->getList());
205
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
206
        // Field Default
207
        $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25);
208
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
209
        // Field Key
210
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
211
        $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']', $value);
212
        $fieldKeySelect->addOptionArray($tdmcreate->getHandler('fieldkey')->getList());
213
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
214
        // Field Void
215
        if ((1 == $i) && (1 == $tableAutoincrement)) {
216
            $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
217
        } else {
218
            // Box header row
219
            $parametersTray = new XoopsFormElementTray('', '<br>');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
220
            // Field Elements
221
            $crElement = new CriteriaCompo();
0 ignored issues
show
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
222
            $crElement->add(new Criteria('fieldelement_tid', 0));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
223
            $crTable = new CriteriaCompo();
224
            $crTable->add(new Criteria('fieldelement_mid', $fieldMid));
225
            $fieldElementsSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']');
226
            $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crElement));
227
            $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crTable));
228
            unset($crElement, $crTable);
229
            $parametersTray->addElement($fieldElementsSelect);
230
231
            $field_parent = 0;
232
            $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']', $field_parent);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
233
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
234
            $parametersTray->addElement($checkFieldParent);
235
236
            $field_admin = 0;
237
            $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin);
238
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
239
            $parametersTray->addElement($checkFieldAdmin);
240
241
            $field_inlist = 0;
242
            $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist);
243
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
244
            $parametersTray->addElement($checkFieldInList);
245
246
            $field_inform = 0;
247
            $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform);
248
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
249
            $parametersTray->addElement($checkFieldInForm);
250
251
            $field_user = 0;
252
            $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user);
253
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
254
            $parametersTray->addElement($checkFieldUser);
255
256
            $field_thead = 0;
257
            $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$i.']', $field_thead);
258
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
259
            $parametersTray->addElement($checkFieldThead);
260
261
            $field_tbody = 0;
262
            $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$i.']', $field_tbody);
263
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
264
            $parametersTray->addElement($checkFieldTbody);
265
266
            $field_tfoot = 0;
267
            $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$i.']', $field_tfoot);
268
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
269
            $parametersTray->addElement($checkFieldTfoot);
270
271
            $field_block = 0;
272
            $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block);
273
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
274
            $parametersTray->addElement($checkFieldBlock);
275
276
            $field_search = 0;
277
            $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search);
278
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
279
            $parametersTray->addElement($check_field_search);
280
281
            $field_required = 0;
282
            $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required);
283
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
284
            $parametersTray->addElement($checkFieldRequired);
285
286
            $fieldMain = (1 == $tableAutoincrement) ? 2 : 1;
287
            $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
288
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
289
            $parametersTray->addElement($checkFieldMain);
290
291
            $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parametersTray->render().'</div></div></td></tr>'));
292
        }
293
    }
294
295
    /**
296
     * @public function getFormEdit
297
     *
298
     * @param null $fieldMid
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...
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...
299
     * @param null $fieldTid
300
     * @param bool $action
301
     * @return mixed
302
     */
303
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
304
    {
305
        $tdmcreate = TDMCreateHelper::getInstance();
306
        // Header function class
307
        $fieldsForm = self::getInstance();
308
        $form = $fieldsForm->getHeaderForm($action);
309
310
        $class = 'even';
311
        // Get the number of fields - goffy
312
        $tablesHandler = &$tdmcreate->getHandler('tables');
313
        $tables = $tablesHandler->get($fieldTid);
314
        $tableAutoincrement = $tables->getVar('table_autoincrement');
315
        $fieldNumb = $tables->getVar('table_nbfields');
316
        $fName = $tables->getVar('table_fieldname');
317
318
        // Get the list of fields
319
        $cr = new CriteriaCompo();
320
        $cr->add(new Criteria('field_mid', $fieldMid));
321
        $cr->add(new Criteria('field_tid', $fieldTid));
322
        $cr->setSort('field_id'); //added by goffy
323
        $fields = $tdmcreate->getHandler('fields')->getObjects($cr);
324
        unset($cr);
325
        $id = 1;
326
        foreach ($fields as $field) {
327
            $class = ('even' === $class) ? 'odd' : 'even';
328
            $fieldId = (int)$field->getVar('field_id');
329
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
330
                $fieldsObj = &$tdmcreate->getHandler('fields')->get($fieldId);
331
                $tdmcreate->getHandler('fields')->delete($fieldsObj, true);
332
            } else {
333
                // show field with settings
334
                $form->addElement(new XoopsFormHidden('field_id['.$id.']', $fieldId));
335
336
                $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
337
                // Index ID
338
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>'));
339
                // Field Name
340
                $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$id.']', 15, 255, $field->getVar('field_name'));
341
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
342
                // Field Type
343
                $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$id.']', $field->getVar('field_type'));
344
                $fieldTypeSelect->addOptionArray($tdmcreate->getHandler('fieldtype')->getList());
345
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
346
                // Field Value
347
                $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$id.']', 10, 200, $field->getVar('field_value'));
348
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
349
                // Field Attributes
350
                $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$id.']', $field->getVar('field_attribute'));
351
                $fieldAttributesSelect->addOptionArray($tdmcreate->getHandler('fieldattributes')->getList());
352
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
353
                // Field Null
354
                $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$id.']', $field->getVar('field_null'));
355
                $fieldNullSelect->addOptionArray($tdmcreate->getHandler('fieldnull')->getList());
356
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
357
                // Field Default
358
                $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$id.']', 15, 25, $field->getVar('field_default'));
359
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
360
                // Field Key
361
                $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$id.']', $field->getVar('field_key'));
362
                $fieldKeySelect->addOptionArray($tdmcreate->getHandler('fieldkey')->getList());
363
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
364
                // Field Void
365
                if ((1 == $id) && (1 == $tableAutoincrement)) {
366
                    $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
367
                } else {
368
                    // Box header row
369
                    $parametersTray = new XoopsFormElementTray('', '<br>');
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($tdmcreate->getHandler('fieldelements')->getList($crElement));
377
                    $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crTable));
378
                    unset($crElement, $crTable);
379
                    $parametersTray->addElement($fieldElementsSelect);
380
381
                    $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$id.']', $field->getVar('field_parent'));
382
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
383
                    $parametersTray->addElement($checkFieldParent);
384
385
                    $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$id.']', $field->getVar('field_admin'));
386
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
387
                    $parametersTray->addElement($checkFieldAdmin);
388
389
                    $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$id.']', $field->getVar('field_inlist'));
390
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
391
                    $parametersTray->addElement($checkFieldInList);
392
393
                    $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$id.']', $field->getVar('field_inform'));
394
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
395
                    $parametersTray->addElement($checkFieldInForm);
396
397
                    $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$id.']', $field->getVar('field_user'));
398
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
399
                    $parametersTray->addElement($checkFieldUser);
400
401
                    $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$id.']', $field->getVar('field_thead'));
402
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
403
                    $parametersTray->addElement($checkFieldThead);
404
405
                    $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$id.']', $field->getVar('field_tbody'));
406
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
407
                    $parametersTray->addElement($checkFieldTbody);
408
409
                    $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$id.']', $field->getVar('field_tfoot'));
410
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
411
                    $parametersTray->addElement($checkFieldTfoot);
412
413
                    $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$id.']', $field->getVar('field_block'));
414
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
415
                    $parametersTray->addElement($checkFieldBlock);
416
417
                    $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$id.']', $field->getVar('field_search'));
418
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
419
                    $parametersTray->addElement($check_field_search);
420
421
                    $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$id.']', $field->getVar('field_required'));
422
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
423
                    $parametersTray->addElement($checkFieldRequired);
424
425
                    $fieldMain = (1 == $field->getVar('field_main')) ? $id : 1;
426
                    $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
427
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
428
                    $parametersTray->addElement($checkFieldMain);
429
430
                    $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parametersTray->render().'</div></div></td></tr>'));
431
                }
432
            }
433
            ++$id;
434
        }
435
        // If you change number fields in tables,
436
        // adding missing fields or delete unnecessary fields
437
        // By goffy
438
        for ($i = $id; $i <= $fieldNumb; ++$i) {
439
            $class = ('even' === $class) ? 'odd' : 'even';
440
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
441
        }
442
        unset($id);
443
444
        // Footer form
445
        return $fieldsForm->getFooterForm($form);
446
    }
447
448
    /**
449
     * @private function getFooterForm
450
     *
451
     * @param $form
452
     *
453
     * @return mixed
454
     */
455
    private function getFooterForm($form)
456
    {
457
        // Send Form Data
458
        $form->addElement(new TDMCreateFormLabel('</tbody>'));
459
        $form->addElement(new TDMCreateFormLabel('<tfoot><tr>'));
460
        $formHidden = new XoopsFormHidden('op', 'save');
461
        $formButton = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
462
        $form->addElement(new TDMCreateFormLabel('<td colspan="8">'.$formHidden->render().'</td>'));
463
        $form->addElement(new TDMCreateFormLabel('<td>'.$formButton->render().'</td>'));
464
        $form->addElement(new TDMCreateFormLabel('</tr></tfoot></table>'));
465
466
        return $form;
467
    }
468
469
    /**
470
     * Get Values.
471
     * @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...
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...
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...
472
     * @param null $format
473
     * @param null $maxDepth
474
     * @return array
475
     */
476
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
477
    {
478
        $ret = $this->getValues($keys, $format, $maxDepth);
479
        $ret['id'] = $this->getVar('field_id');
480
        $ret['mid'] = $this->getVar('field_mid');
481
        $ret['tid'] = $this->getVar('field_tid');
482
        $ret['order'] = $this->getVar('field_order');
483
        $ret['name'] = str_replace('_', ' ', ucfirst($this->getVar('field_name')));
484
        $ret['parent'] = $this->getVar('field_parent');
485
        $ret['inlist'] = $this->getVar('field_inlist');
486
        $ret['inform'] = $this->getVar('field_inform');
487
        $ret['admin'] = $this->getVar('field_admin');
488
        $ret['user'] = $this->getVar('field_user');
489
        $ret['block'] = $this->getVar('field_block');
490
        $ret['main'] = $this->getVar('field_main');
491
        $ret['search'] = $this->getVar('field_search');
492
        $ret['required'] = $this->getVar('field_required');
493
494
        return $ret;
495
    }
496
}
497
498
499
/**
500
 * Class TDMCreateFieldsHandler.
501
 */
502
class TDMCreateFieldsHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Bug introduced by
The type XoopsPersistableObjectHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
503
{
504
    /**
505
     * @public function constructor class
506
     *
507
     * @param mixed|XoopsDatabase $db
508
     */
509
    public function __construct(XoopsDatabase $db)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
510
    {
511
        parent::__construct($db, 'tdmcreate_fields', 'tdmcreatefields', 'field_id', 'field_name');
512
    }
513
514
    /**
515
     * @param bool $isNew
516
     *
517
     * @return \XoopsObject
518
     */
519
    public function create($isNew = true)
520
    {
521
        return parent::create($isNew);
522
    }
523
524
    /**
525
     * retrieve a field.
526
     *
527
     * @param int  $i      field id
528
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
529
     *
530
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
531
     *               object
532
     */
533
    public function get($i = null, $fields = null)
534
    {
535
        return parent::get($i, $fields);
536
    }
537
538
    /**
539
     * get inserted id.
540
     *
541
     * @param null
542
     *
543
     * @return int reference to the {@link TDMCreateFields} object
544
     */
545
    public function getInsertId()
546
    {
547
        return $this->db->getInsertId();
548
    }
549
550
    /**
551
     * Get Count Fields.
552
     * @param int    $start
553
     * @param int    $limit
554
     * @param string $sort
555
     * @param string $order
556
     * @return int
557
     */
558
    public function getCountFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
559
    {
560
        $crCountFields = new CriteriaCompo();
561
        $crCountFields = $this->getFieldsCriteria($crCountFields, $start, $limit, $sort, $order);
562
563
        return $this->getCount($crCountFields);
564
    }
565
566
    /**
567
     * Get All Fields.
568
     * @param int    $start
569
     * @param int    $limit
570
     * @param string $sort
571
     * @param string $order
572
     * @return array
573
     */
574
    public function getAllFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
575
    {
576
        $crAllFields = new CriteriaCompo();
577
        $crAllFields = $this->getFieldsCriteria($crAllFields, $start, $limit, $sort, $order);
578
579
        return $this->getAll($crAllFields);
580
    }
581
582
    /**
583
     * Get All Fields By Module & Table Id.
584
     * @param        $modId
585
     * @param        $tabId
586
     * @param int    $start
587
     * @param int    $limit
588
     * @param string $sort
589
     * @param string $order
590
     * @return array
591
     */
592
    public function getAllFieldsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'field_order ASC, field_id, field_name', $order = 'ASC')
593
    {
594
        $crAllFieldsByModule = new CriteriaCompo();
595
        $crAllFieldsByModule->add(new Criteria('field_mid', $modId));
596
        $crAllFieldsByModule->add(new Criteria('field_tid', $tabId));
597
        $crAllFieldsByModule = $this->getFieldsCriteria($crAllFieldsByModule, $start, $limit, $sort, $order);
598
599
        return $this->getAll($crAllFieldsByModule);
600
    }
601
602
    /**
603
     * Get Fields Criteria.
604
     * @param $crFields
605
     * @param $start
606
     * @param $limit
607
     * @param $sort
608
     * @param $order
609
     * @return mixed
610
     */
611
    private function getFieldsCriteria($crFields, $start, $limit, $sort, $order)
612
    {
613
        $crFields->setStart($start);
614
        $crFields->setLimit($limit);
615
        $crFields->setSort($sort);
616
        $crFields->setOrder($order);
617
618
        return $crFields;
619
    }
620
}
621