Passed
Branch master (31be8b)
by Gino
03:04
created

TDMCreateFields::getFormNewLine()   F

Complexity

Conditions 16
Paths 12288

Size

Total Lines 120
Code Lines 92

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 120
rs 2
cc 16
eloc 92
nc 12288
nop 7

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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       The XOOPS Project http://sourceforge.net/projects/xoops/
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
*  @Class TDMCreateFields
28
*  @extends XoopsObject
29
*/
30
31
/**
32
 * Class TDMCreateFields.
33
 */
34
class TDMCreateFields extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
35
{
36
    /**
37
     * @var mixed
38
     */
39
    private $tdmcreate;
40
41
    /**
42
     * Options.
43
     */
44
    public $options = array(
45
        'parent',
46
        'admin',
47
        'inlist',
48
        'inform',
49
        'user',
50
        'thead',
51
        'tbody',
52
        'tfoot',
53
        'block',
54
        'search',
55
        'required',
56
    );
57
58
    /*
59
    *  @public function constructor class
60
    *  @param null
61
    */
62
    /**
63
     *
64
     */
65
    public function __construct()
66
    {
67
        $this->tdmcreate = TDMCreateHelper::getInstance();
68
        $this->initVar('field_id', XOBJ_DTYPE_INT);
69
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
70
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
71
        $this->initVar('field_order', XOBJ_DTYPE_INT);
72
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
73
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
74
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
75
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
76
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
77
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
78
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
79
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
80
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
81
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
82
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
83
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
84
        $this->initVar('field_user', XOBJ_DTYPE_INT);
85
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
86
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
87
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
88
        $this->initVar('field_block', XOBJ_DTYPE_INT);
89
        $this->initVar('field_main', XOBJ_DTYPE_INT);
90
        $this->initVar('field_search', XOBJ_DTYPE_INT);
91
        $this->initVar('field_required', XOBJ_DTYPE_INT);
92
    }
93
94
    /**
95
     * @param string $method
96
     * @param array  $args
97
     *
98
     * @return mixed
99
     */
100
    public function __call($method, $args)
101
    {
102
        $arg = isset($args[0]) ? $args[0] : null;
103
104
        return $this->getVar($method, $arg);
105
    }
106
107
    /*
108
     * @static function &getInstance
109
     *
110
     * @return TDMCreateFields
111
     */
112
    public static function &getInstance()
113
    {
114
        static $instance = false;
115
        if (!$instance) {
116
            $instance = new self();
117
        }
118
119
        return $instance;
120
    }
121
122
    /*
123
     * @private function getHeaderForm
124
     *
125
     * @param bool $action
126
     * @return TDMCreateThemeForm
127
     */
128
    private function getHeaderForm($action = false)
129
    {
130
        if ($action === false) {
131
            $action = $_SERVER['REQUEST_URI'];
132
        }
133
134
        $isNew = $this->isNew();
135
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
136
137
        $form = new TDMCreateThemeForm(null, 'form', $action, 'post', true);
138
        $form->setExtra('enctype="multipart/form-data"');
139
140
        // New Object HtmlTable
141
        $form->addElement(new TDMCreateFormLabel('<table cellspacing="1" class="outer width100">'));
142
        $form->addElement(new TDMCreateFormLabel('<thead class="center">'));
143
        $form->addElement(new TDMCreateFormLabel('<tr class="head"><th colspan="9">'.$title.'</th></tr>'));
144
        $form->addElement(new TDMCreateFormLabel('<tr class="head width5">'));
145
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ID.'</td>'));
146
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NAME.'</td>'));
147
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_TYPE.'</td>'));
148
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_VALUE.'</th>'));
149
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ATTRIBUTE.'</th>'));
150
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NULL.'</th>'));
151
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_DEFAULT.'</th>'));
152
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_KEY.'</th>'));
153
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_PARAMETERS.'</th>'));
154
        $form->addElement(new TDMCreateFormLabel('</tr></thead>'));
155
        $form->addElement(new TDMCreateFormLabel('<tbody>'));
156
157
        //
158
        return $form;
159
    }
160
161
    /*
162
     * @public function getFormNew
163
     *
164
     * @param null $fieldMid
165
     * @param null $fieldTid
166
     * @param null $fieldNumb
167
     * @param null $fieldName
168
     * @param bool $action
169
     * @return mixed
170
     */
171
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
172
    {
173
        // Header function class
174
        $fieldsForm = self::getInstance();
175
        $form = $fieldsForm->getHeaderForm($action);
176
        // Get handler tables
177
        $tableObj = $this->tdmcreate->getHandler('tables'); // Changed by goffy
178
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement'); // Added by goffy
179
        // Loop for fields number
180
        $class = 'even';
181
        for ($i = 1; $i <= $fieldNumb; ++$i) {
182
            $class = ($class == 'even') ? 'odd' : 'even';
183
            // Replaced creation of new line by new function - goffy
184
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
185
        }
186
187
        // Footer form
188
        return $fieldsForm->getFooterForm($form);
189
    }
190
191
    /**
192
     * @private function getFormNewLine
193
     *
194
     * @param $form
195
     * @param $class
196
     * @param $i
197
     * @param $fieldMid
198
     * @param $fieldTid
199
     * @param $fName
200
     * @param $tableAutoincrement
201
     */
202
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
203
    {
204
        $form->addElement(new XoopsFormHidden('field_id['.$i.']', 0));
205
        $form->addElement(new XoopsFormHidden('field_mid', $fieldMid));
206
        $form->addElement(new XoopsFormHidden('field_tid', $fieldTid));
207
208
        $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
209
        // Index ID
210
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>'));
211
        // Field Name
212
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName.'_id' : $fName.'_') : '');
213
        $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $thisFieldName);
214
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
215
        // Field Type
216
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
217
        $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value);
218
        $fieldTypeSelect->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList());
219
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
220
        // Field Value
221
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
222
        $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 5, 20, $value);
223
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
224
        // Field Attributes
225
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
226
        $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']', $value);
227
        $fieldAttributesSelect->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList());
228
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
229
        // Field Null
230
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '2';
231
        $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']', $value);
232
        $fieldNullSelect->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList());
233
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
234
        // Field Default
235
        $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25);
236
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
237
        // Field Key
238
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
239
        $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']', $value);
240
        $fieldKeySelect->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList());
241
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
242
        // Field Void
243
        if ((1 == $i) && (1 == $tableAutoincrement)) {
244
            $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
245
        } else {
246
            // Box header row
247
            $parametersTray = new XoopsFormElementTray('', '<br />');
248
            // Field Elements
249
            $criteriaElement = new CriteriaCompo();
250
            $criteriaElement->add(new Criteria('fieldelement_tid', 0));
251
            $criteriaTable = new CriteriaCompo();
252
            $criteriaTable->add(new Criteria('fieldelement_mid', $fieldMid));
253
            $fieldElementsSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']');
254
            $fieldElementsSelect->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteriaElement));
255
            $fieldElementsSelect->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteriaTable));
256
            unset($criteriaElement, $criteriaTable);
257
            $parametersTray->addElement($fieldElementsSelect);
258
259
            $field_parent = 0;
260
            $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']', $field_parent);
261
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
262
            $parametersTray->addElement($checkFieldParent);
263
264
            $field_admin = 0;
265
            $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin);
266
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
267
            $parametersTray->addElement($checkFieldAdmin);
268
269
            $field_inlist = 0;
270
            $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist);
271
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
272
            $parametersTray->addElement($checkFieldInList);
273
274
            $field_inform = 0;
275
            $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform);
276
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
277
            $parametersTray->addElement($checkFieldInForm);
278
279
            $field_user = 0;
280
            $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user);
281
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
282
            $parametersTray->addElement($checkFieldUser);
283
284
            $field_thead = 0;
285
            $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$i.']', $field_thead);
286
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
287
            $parametersTray->addElement($checkFieldThead);
288
289
            $field_tbody = 0;
290
            $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$i.']', $field_tbody);
291
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
292
            $parametersTray->addElement($checkFieldTbody);
293
294
            $field_tfoot = 0;
295
            $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$i.']', $field_tfoot);
296
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
297
            $parametersTray->addElement($checkFieldTfoot);
298
299
            $field_block = 0;
300
            $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block);
301
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
302
            $parametersTray->addElement($checkFieldBlock);
303
304
            $field_search = 0;
305
            $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search);
306
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
307
            $parametersTray->addElement($check_field_search);
308
309
            $field_required = 0;
310
            $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required);
311
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
312
            $parametersTray->addElement($checkFieldRequired);
313
314
            $fieldMain = (1 == $tableAutoincrement) ? 2 : 1;
315
            $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
316
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
317
            $parametersTray->addElement($checkFieldMain);
318
            //
319
            $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>'));
320
        }
321
    }
322
323
    /*
324
     * @public function getFormEdit
325
     *
326
     * @param null $fieldMid
327
     * @param null $fieldTid
328
     * @param bool $action
329
     * @return mixed
330
     */
331
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
332
    {
333
        // Header function class
334
        $fieldsForm = self::getInstance();
335
        $form = $fieldsForm->getHeaderForm($action);
336
        //
337
        $class = 'even';
338
        // Get the number of fields - goffy
339
        $tablesHandler = &$this->tdmcreate->getHandler('tables');
340
        $tables = $tablesHandler->get($fieldTid);
341
        $tableAutoincrement = $tables->getVar('table_autoincrement');
342
        $fieldNumb = $tables->getVar('table_nbfields');
343
        $fName = $tables->getVar('table_fieldname');
344
345
        // Get the list of fields
346
        $criteria = new CriteriaCompo();
347
        $criteria->add(new Criteria('field_mid', $fieldMid));
348
        $criteria->add(new Criteria('field_tid', $fieldTid));
349
        $criteria->setSort('field_id'); //added by goffy
350
        $fields = $this->tdmcreate->getHandler('fields')->getObjects($criteria);
351
        unset($criteria);
352
        $id = 1;
353
        foreach ($fields as $field) {
354
            $class = ($class == 'even') ? 'odd' : 'even';
355
            $fieldId = (int) ($field->getVar('field_id'));
356
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
357
                $fieldsObj = &$this->tdmcreate->getHandler('fields')->get($fieldId);
358
                $this->tdmcreate->getHandler('fields')->delete($fieldsObj, true);
359
            } else {
360
                // show field with settings
361
                $form->addElement(new XoopsFormHidden('field_id['.$id.']', $fieldId));
362
                //$form->addElement(new XoopsFormHidden('field_mid', $fieldMid));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
363
                //$form->addElement(new XoopsFormHidden('field_tid', $fieldTid));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
364
365
                $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
366
                // Index ID
367
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>'));
368
                // Field Name
369
                $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$id.']', 15, 255, $field->getVar('field_name'));
370
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
371
                // Field Type
372
                $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$id.']', $field->getVar('field_type'));
373
                $fieldTypeSelect->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList());
374
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
375
                // Field Value
376
                $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$id.']', 5, 20, $field->getVar('field_value'));
377
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
378
                // Field Attributes
379
                $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$id.']', $field->getVar('field_attribute'));
380
                $fieldAttributesSelect->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList());
381
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
382
                // Field Null
383
                $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$id.']', $field->getVar('field_null'));
384
                $fieldNullSelect->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList());
385
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
386
                // Field Default
387
                $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$id.']', 15, 25, $field->getVar('field_default'));
388
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
389
                // Field Key
390
                $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$id.']', $field->getVar('field_key'));
391
                $fieldKeySelect->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList());
392
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
393
                // Field Void
394
                if ((1 == $id) && (1 == $tableAutoincrement)) {
395
                    $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
396
                } else {
397
                    // Box header row
398
                    $parametersTray = new XoopsFormElementTray('', '<br />');
399
                    // Field Elements
400
                    $criteriaElement = new CriteriaCompo();
401
                    $criteriaElement->add(new Criteria('fieldelement_tid', 0));
402
                    $criteriaTable = new CriteriaCompo();
403
                    $criteriaTable->add(new Criteria('fieldelement_mid', $fieldMid));
404
                    $fieldElementsSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$id.']', $field->getVar('field_element'));
405
                    $fieldElementsSelect->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteriaElement));
406
                    $fieldElementsSelect->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteriaTable));
407
                    unset($criteriaElement, $criteriaTable);
408
                    $parametersTray->addElement($fieldElementsSelect);
409
410
                    // Options
411
                    /*$moduleOption = $this->getOptions();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
412
                    $checkbox     = new XoopsFormCheckbox(' ', 'fields_option[' . $id . ']', $moduleOption, '<br />');
413
                    $checkbox->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
414
                    foreach ($this->options as $option) {
415
                        $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_FIELD_' . strtoupper($option)));
416
                    }
417
                    $parametersTray->addElement($checkbox);*/
418
419
                    $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$id.']', $field->getVar('field_parent'));
420
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
421
                    $parametersTray->addElement($checkFieldParent);
422
423
                    $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$id.']', $field->getVar('field_admin'));
424
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
425
                    $parametersTray->addElement($checkFieldAdmin);
426
427
                    $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$id.']', $field->getVar('field_inlist'));
428
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
429
                    $parametersTray->addElement($checkFieldInList);
430
431
                    $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$id.']', $field->getVar('field_inform'));
432
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
433
                    $parametersTray->addElement($checkFieldInForm);
434
435
                    $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$id.']', $field->getVar('field_user'));
436
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
437
                    $parametersTray->addElement($checkFieldUser);
438
439
                    $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$id.']', $field->getVar('field_thead'));
440
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
441
                    $parametersTray->addElement($checkFieldThead);
442
443
                    $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$id.']', $field->getVar('field_tbody'));
444
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
445
                    $parametersTray->addElement($checkFieldTbody);
446
447
                    $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$id.']', $field->getVar('field_tfoot'));
448
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
449
                    $parametersTray->addElement($checkFieldTfoot);
450
451
                    $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$id.']', $field->getVar('field_block'));
452
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
453
                    $parametersTray->addElement($checkFieldBlock);
454
455
                    $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$id.']', $field->getVar('field_search'));
456
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
457
                    $parametersTray->addElement($check_field_search);
458
459
                    $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$id.']', $field->getVar('field_required'));
460
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
461
                    $parametersTray->addElement($checkFieldRequired);
462
463
                    $fieldMain = (1 == $field->getVar('field_main')) ? $id : 1;
464
                    $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
465
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
466
                    $parametersTray->addElement($checkFieldMain);
467
                    //
468
                    $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>'));
469
                }
470
            }
471
            ++$id;
472
        }
473
        // If you change number fields in tables,
474
        // adding missing fields or delete unnecessary fields
475
        // By goffy
476
        for ($i = $id; $i <= $fieldNumb; ++$i) {
477
            $class = ($class == 'even') ? 'odd' : 'even';
478
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
479
        }
480
        unset($id);
481
482
        // Footer form
483
        return $fieldsForm->getFooterForm($form);
484
    }
485
486
    /*
487
    *  @private function getFooterForm
488
    *  @param null
489
    */
490
    /**
491
     * @param $form
492
     *
493
     * @return mixed
494
     */
495
    private function getFooterForm($form)
496
    {
497
        // Send Form Data
498
        $form->addElement(new TDMCreateFormLabel('</tbody>'));
499
        $form->addElement(new TDMCreateFormLabel('<tfoot><tr>'));
500
        $formHidden = new XoopsFormHidden('op', 'save');
501
        $formButton = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
502
        $form->addElement(new TDMCreateFormLabel('<td colspan="8">'.$formHidden->render().'</td>'));
503
        $form->addElement(new TDMCreateFormLabel('<td>'.$formButton->render().'</td>'));
504
        $form->addElement(new TDMCreateFormLabel('</tr></tfoot></table>'));
505
506
        return $form;
507
    }
508
509
    /**
510
     * Get Values.
511
     */
512
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
513
    {
514
        $ret = parent::getValues($keys, $format, $maxDepth);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getValues() instead of getValuesFields()). Are you sure this is correct? If so, you might want to change this to $this->getValues().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
515
        $ret['id'] = $this->getVar('field_id');
516
        $ret['mid'] = $this->getVar('field_mid');
517
        $ret['tid'] = $this->getVar('field_tid');
518
        $ret['order'] = $this->getVar('field_order');
519
        $ret['name'] = str_replace('_', ' ', ucfirst($this->getVar('field_name')));
520
        $ret['parent'] = $this->getVar('field_parent');
521
        $ret['inlist'] = $this->getVar('field_inlist');
522
        $ret['inform'] = $this->getVar('field_inform');
523
        $ret['admin'] = $this->getVar('field_admin');
524
        $ret['user'] = $this->getVar('field_user');
525
        $ret['block'] = $this->getVar('field_block');
526
        $ret['main'] = $this->getVar('field_main');
527
        $ret['search'] = $this->getVar('field_search');
528
        $ret['required'] = $this->getVar('field_required');
529
530
        return $ret;
531
    }
532
533
    /**
534
     * Get Options.
535
     */
536
    /**
537
     * @param $key
538
     *
539
     * @return string
540
     */
541
    public function getOptionsFields()
542
    {
543
        $retFields = array();
544
        foreach ($this->options as $option) {
545
            if ($this->getVar('field_'.$option) == 1) {
546
                array_push($retFields, $option);
547
            }
548
        }
549
550
        return $retFields;
551
    }
552
553
    /**
554
     * Get Defined Language.
555
     */
556
    /**
557
     * @param $lang
558
     *
559
     * @return string
560
     */
561
    private static function getDefinedLanguage($lang)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
562
    {
563
        if (defined($lang)) {
564
            return constant($lang);
565
        }
566
567
        return $lang;
568
    }
569
}
570
571
/*
572
*  @Class TDMCreateFieldsHandler
573
*  @extends XoopsPersistableObjectHandler
574
*/
575
576
/**
577
 * Class TDMCreateFieldsHandler.
578
 */
579
class TDMCreateFieldsHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
580
{
581
    /*
582
    *  @public function constructor class
583
    *  @param mixed $db
584
    */
585
    /**
586
     * @param null|object $db
587
     */
588
    public function __construct(&$db)
589
    {
590
        parent::__construct($db, 'tdmcreate_fields', 'tdmcreatefields', 'field_id', 'field_name');
591
    }
592
593
    /**
594
     * @param bool $isNew
595
     *
596
     * @return object
597
     */
598
    public function &create($isNew = true)
599
    {
600
        return parent::create($isNew);
601
    }
602
603
    /**
604
     * retrieve a field.
605
     *
606
     * @param int  $i      field id
607
     * @param null $fields
608
     *
609
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
610
     *               object
611
     */
612
    public function &get($i = null, $fields = null)
613
    {
614
        return parent::get($i, $fields);
615
    }
616
617
    /**
618
     * get inserted id.
619
     *
620
     * @param null
621
     *
622
     * @return int reference to the {@link TDMCreateFields} object
623
     */
624
    public function getInsertId()
625
    {
626
        return $this->db->getInsertId();
627
    }
628
629
    /**
630
     * get IDs of objects matching a condition.
631
     *
632
     * @param object $criteria {@link CriteriaElement} to match
633
     *
634
     * @return array of object IDs
635
     */
636
    public function &getIds($criteria)
637
    {
638
        return parent::getIds($criteria);
639
    }
640
641
    /**
642
     * insert a new field in the database.
643
     *
644
     * @param object $field reference to the {@link TDMCreateFields} object
645
     * @param bool   $force
646
     *
647
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
648
     */
649
    public function insert(&$field, $force = false)
650
    {
651
        if (!parent::insert($field, $force)) {
652
            return false;
653
        }
654
655
        return true;
656
    }
657
658
    /**
659
     * Get Count Fields.
660
     */
661
    public function getCountFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
662
    {
663
        $criteriaCountFields = new CriteriaCompo();
664
        $criteriaCountFields = $this->getFieldsCriteria($criteriaCountFields, $start, $limit, $sort, $order);
665
666
        return $this->getCount($criteriaCountFields);
667
    }
668
669
    /**
670
     * Get All Fields.
671
     */
672
    public function getAllFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
673
    {
674
        $criteriaAllFields = new CriteriaCompo();
675
        $criteriaAllFields = $this->getFieldsCriteria($criteriaAllFields, $start, $limit, $sort, $order);
676
677
        return $this->getAll($criteriaAllFields);
678
    }
679
680
    /**
681
     * Get All Fields By Module & Table Id.
682
     */
683
    public function getAllFieldsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'field_order ASC, field_id, field_name', $order = 'ASC')
684
    {
685
        $criteriaAllFieldsByModule = new CriteriaCompo();
686
        $criteriaAllFieldsByModule->add(new Criteria('field_mid', $modId));
687
        $criteriaAllFieldsByModule->add(new Criteria('field_tid', $tabId));
688
        $criteriaAllFieldsByModule = $this->getFieldsCriteria($criteriaAllFieldsByModule, $start, $limit, $sort, $order);
689
690
        return $this->getAll($criteriaAllFieldsByModule);
691
    }
692
693
    /**
694
     * Get Fields Criteria.
695
     */
696
    private function getFieldsCriteria($criteriaFields, $start, $limit, $sort, $order)
697
    {
698
        $criteriaFields->setStart($start);
699
        $criteriaFields->setLimit($limit);
700
        $criteriaFields->setSort($sort);
701
        $criteriaFields->setOrder($order);
702
703
        return $criteriaFields;
704
    }
705
}
706