Completed
Pull Request — master (#115)
by Gino
03:12
created

TDMCreateFieldsHandler::getInsertId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
36
    /*
37
    *  @public function constructor class
38
    *  @param null
39
    */
40
    /**
41
     *
42
     */
43
    public function __construct()
44
    {        
45
        $this->initVar('field_id', XOBJ_DTYPE_INT);
46
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
47
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
48
        $this->initVar('field_order', XOBJ_DTYPE_INT);
49
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
54
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
55
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
56
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
57
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
58
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
59
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
60
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
61
        $this->initVar('field_user', XOBJ_DTYPE_INT);
62
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
63
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
64
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
65
        $this->initVar('field_block', XOBJ_DTYPE_INT);
66
        $this->initVar('field_main', XOBJ_DTYPE_INT);
67
        $this->initVar('field_search', XOBJ_DTYPE_INT);
68
        $this->initVar('field_required', XOBJ_DTYPE_INT);
69
    }
70
71
    /**
72
     * @param string $method
73
     * @param array  $args
74
     *
75
     * @return mixed
76
     */
77
    public function __call($method, $args)
78
    {
79
        $arg = isset($args[0]) ? $args[0] : null;
80
81
        return $this->getVar($method, $arg);
82
    }
83
84
    /*
85
     * @static function &getInstance
86
     *
87
     * @return TDMCreateFields
88
     */
89
    public static function &getInstance()
90
    {
91
        static $instance = false;
92
        if (!$instance) {
93
            $instance = new self();
94
        }
95
96
        return $instance;
97
    }
98
99
    /*
100
     * @public function getHeaderForm
101
     *
102
     * @param bool $action
103
     * @return TDMCreateThemeForm
104
     */
105
    public function getHeaderForm($action = false)
106
    {
107
        if ($action === false) {
108
            $action = $_SERVER['REQUEST_URI'];
109
        }
110
111
        $isNew = $this->isNew();
112
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
113
114
        $form = new TDMCreateThemeForm(null, 'form', $action, 'post', true);
115
        $form->setExtra('enctype="multipart/form-data"');
116
117
        // New Object HtmlTable
118
        $form->addElement(new TDMCreateFormLabel('<table cellspacing="1" class="outer width100">'));
119
        $form->addElement(new TDMCreateFormLabel('<thead class="center">'));
120
        $form->addElement(new TDMCreateFormLabel('<tr class="head"><th colspan="9">'.$title.'</th></tr>'));
121
        $form->addElement(new TDMCreateFormLabel('<tr class="head width5">'));
122
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ID.'</td>'));
123
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NAME.'</td>'));
124
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_TYPE.'</td>'));
125
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_VALUE.'</th>'));
126
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ATTRIBUTE.'</th>'));
127
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NULL.'</th>'));
128
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_DEFAULT.'</th>'));
129
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_KEY.'</th>'));
130
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_PARAMETERS.'</th>'));
131
        $form->addElement(new TDMCreateFormLabel('</tr></thead>'));
132
        $form->addElement(new TDMCreateFormLabel('<tbody>'));
133
134
        //
135
        return $form;
136
    }
137
138
    /*
139
     * @public function getFormNew
140
     *
141
     * @param null $fieldMid
142
     * @param null $fieldTid
143
     * @param null $fieldNumb
144
     * @param null $fieldName
145
     * @param bool $action
146
     * @return mixed
147
     */
148
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
149
    {
150
        // Header function class
151
        $fieldsForm = self::getInstance();
152
        $form = $fieldsForm->getHeaderForm($action);
153
        // Get handler tables
154
		$tdmcreate = TDMCreateHelper::getInstance();
155
        $tableObj = $tdmcreate->getHandler('tables'); // Changed by goffy
156
        $tableAutoincrement = $tableObj->get($fieldTid)->getVar('table_autoincrement'); // Added by goffy
0 ignored issues
show
Bug introduced by
The method get cannot be called on $tableObj (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
157
        // Loop for fields number
158
        $class = 'even';
159
        for ($i = 1; $i <= $fieldNumb; ++$i) {
160
            $class = ($class == 'even') ? 'odd' : 'even';
161
            // Replaced creation of new line by new function - goffy
162
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
163
        }
164
165
        // Footer form
166
        return $fieldsForm->getFooterForm($form);
167
    }
168
169
    /**
170
     * @private function getFormNewLine
171
     *
172
     * @param $form
173
     * @param $class
174
     * @param $i
175
     * @param $fieldMid
176
     * @param $fieldTid
177
     * @param $fName
178
     * @param $tableAutoincrement
179
     */
180
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
181
    {
182
        $tdmcreate = TDMCreateHelper::getInstance();
183
		$form->addElement(new XoopsFormHidden('field_id['.$i.']', 0));
184
        $form->addElement(new XoopsFormHidden('field_mid', $fieldMid));
185
        $form->addElement(new XoopsFormHidden('field_tid', $fieldTid));
186
187
        $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
188
        // Index ID
189
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>'));
190
        // Field Name
191
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName.'_id' : $fName.'_') : '');
192
        $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $thisFieldName);
193
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
194
        // Field Type
195
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
196
        $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value);
197
        $fieldTypeSelect->addOptionArray($tdmcreate->getHandler('fieldtype')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldtype') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
198
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
199
        // Field Value
200
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
201
        $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 10, 200, $value);
202
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
203
        // Field Attributes
204
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
205
        $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']', $value);
206
        $fieldAttributesSelect->addOptionArray($tdmcreate->getHandler('fieldattributes')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldattributes') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
207
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
208
        // Field Null
209
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '2';
210
        $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']', $value);
211
        $fieldNullSelect->addOptionArray($tdmcreate->getHandler('fieldnull')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldnull') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
212
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
213
        // Field Default
214
        $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25);
215
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
216
        // Field Key
217
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
218
        $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']', $value);
219
        $fieldKeySelect->addOptionArray($tdmcreate->getHandler('fieldkey')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldkey') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
220
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
221
        // Field Void
222
        if ((1 == $i) && (1 == $tableAutoincrement)) {
223
            $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
224
        } else {
225
            // Box header row
226
            $parametersTray = new XoopsFormElementTray('', '<br />');
227
            // Field Elements
228
            $criteriaElement = new CriteriaCompo();
229
            $criteriaElement->add(new Criteria('fieldelement_tid', 0));
230
            $criteriaTable = new CriteriaCompo();
231
            $criteriaTable->add(new Criteria('fieldelement_mid', $fieldMid));
232
            $fieldEleSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']');
233
            $fieldEleSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($criteriaElement));
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldelements') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
234
            $fieldEleSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($criteriaTable));
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldelements') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
235
            unset($criteriaElement, $criteriaTable);
236
            $parametersTray->addElement($fieldEleSelect);
237
238
            $field_parent = 0;
239
            $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']', $field_parent);
240
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
241
            $parametersTray->addElement($checkFieldParent);
242
243
            $field_admin = 0;
244
            $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin);
245
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
246
            $parametersTray->addElement($checkFieldAdmin);
247
248
            $field_inlist = 0;
249
            $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist);
250
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
251
            $parametersTray->addElement($checkFieldInList);
252
253
            $field_inform = 0;
254
            $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform);
255
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
256
            $parametersTray->addElement($checkFieldInForm);
257
258
            $field_user = 0;
259
            $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user);
260
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
261
            $parametersTray->addElement($checkFieldUser);
262
263
            $field_thead = 0;
264
            $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$i.']', $field_thead);
265
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
266
            $parametersTray->addElement($checkFieldThead);
267
268
            $field_tbody = 0;
269
            $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$i.']', $field_tbody);
270
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
271
            $parametersTray->addElement($checkFieldTbody);
272
273
            $field_tfoot = 0;
274
            $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$i.']', $field_tfoot);
275
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
276
            $parametersTray->addElement($checkFieldTfoot);
277
278
            $field_block = 0;
279
            $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block);
280
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
281
            $parametersTray->addElement($checkFieldBlock);
282
283
            $field_search = 0;
284
            $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search);
285
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
286
            $parametersTray->addElement($check_field_search);
287
288
            $field_required = 0;
289
            $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required);
290
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
291
            $parametersTray->addElement($checkFieldRequired);
292
293
            $fieldMain = (1 == $tableAutoincrement) ? 2 : 1;
294
            $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
295
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
296
            $parametersTray->addElement($checkFieldMain);
297
            //
298
            $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>'));
299
        }
300
    }
301
302
    /*
303
     * @public function getFormEdit
304
     *
305
     * @param null $fieldMid
306
     * @param null $fieldTid
307
     * @param bool $action
308
     * @return mixed
309
     */
310
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
311
    {
312
        $tdmcreate = TDMCreateHelper::getInstance();
313
		// Header function class
314
        $fieldsForm = self::getInstance();
315
        $form = $fieldsForm->getHeaderForm($action);
316
        //
317
        $class = 'even';
318
        // Get the number of fields - goffy
319
        $tablesHandler = $tdmcreate->getHandler('tables');
320
        $tables = $tablesHandler->get($fieldTid);
0 ignored issues
show
Bug introduced by
The method get cannot be called on $tablesHandler (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
321
        $tableAutoincrement = $tables->getVar('table_autoincrement');
322
        $fieldNumb = $tables->getVar('table_nbfields');
323
        $fName = $tables->getVar('table_fieldname');
324
325
        // Get the list of fields
326
        $criteria = new CriteriaCompo();
327
        $criteria->add(new Criteria('field_mid', $fieldMid));
328
        $criteria->add(new Criteria('field_tid', $fieldTid));
329
        $criteria->setSort('field_id'); //added by goffy
330
        $fields = $tdmcreate->getHandler('fields')->getObjects($criteria);
0 ignored issues
show
Bug introduced by
The method getObjects cannot be called on $tdmcreate->getHandler('fields') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
331
        unset($criteria);
332
        $id = 1;
333
        foreach ($fields as $field) {
334
            $class = ($class == 'even') ? 'odd' : 'even';
335
            $fieldId = (int) ($field->getVar('field_id'));
336
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
337
                $fieldsObj = $tdmcreate->getHandler('fields')->get($fieldId);
0 ignored issues
show
Bug introduced by
The method get cannot be called on $tdmcreate->getHandler('fields') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
338
                $tdmcreate->getHandler('fields')->delete($fieldsObj, true);
0 ignored issues
show
Bug introduced by
The method delete cannot be called on $tdmcreate->getHandler('fields') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
339
            } else {
340
                // show field with settings
341
                $form->addElement(new XoopsFormHidden('field_id['.$id.']', $fieldId));
342
343
                $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
344
                // Index ID
345
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>'));
346
                // Field Name
347
                $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$id.']', 15, 255, $field->getVar('field_name'));
348
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
349
                // Field Type
350
                $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$id.']', $field->getVar('field_type'));
351
                $fieldTypeSelect->addOptionArray($tdmcreate->getHandler('fieldtype')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldtype') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
352
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
353
                // Field Value
354
                $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$id.']', 10, 200, $field->getVar('field_value'));
355
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
356
                // Field Attributes
357
                $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$id.']', $field->getVar('field_attribute'));
358
                $fieldAttributesSelect->addOptionArray($tdmcreate->getHandler('fieldattributes')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldattributes') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
359
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
360
                // Field Null
361
                $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$id.']', $field->getVar('field_null'));
362
                $fieldNullSelect->addOptionArray($tdmcreate->getHandler('fieldnull')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldnull') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
363
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
364
                // Field Default
365
                $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$id.']', 15, 25, $field->getVar('field_default'));
366
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
367
                // Field Key
368
                $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$id.']', $field->getVar('field_key'));
369
                $fieldKeySelect->addOptionArray($tdmcreate->getHandler('fieldkey')->getList());
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldkey') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
370
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
371
                // Field Void
372
                if ((1 == $id) && (1 == $tableAutoincrement)) {
373
                    $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
374
                } else {
375
                    // Box header row
376
                    $parametersTray = new XoopsFormElementTray('', '<br />');
377
                    // Field Elements
378
                    $criteriaElement = new CriteriaCompo();
379
                    $criteriaElement->add(new Criteria('fieldelement_tid', 0));
380
                    $criteriaTable = new CriteriaCompo();
381
                    $criteriaTable->add(new Criteria('fieldelement_mid', $fieldMid));
382
                    $fieldEleSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$id.']', $field->getVar('field_element'));
383
                    $fieldEleSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($criteriaElement));
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldelements') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
384
                    $fieldEleSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($criteriaTable));
0 ignored issues
show
Bug introduced by
The method getList cannot be called on $tdmcreate->getHandler('fieldelements') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
385
                    unset($criteriaElement, $criteriaTable);
386
                    $parametersTray->addElement($fieldEleSelect);
387
388
                    $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$id.']', $field->getVar('field_parent'));
389
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
390
                    $parametersTray->addElement($checkFieldParent);
391
392
                    $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$id.']', $field->getVar('field_admin'));
393
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
394
                    $parametersTray->addElement($checkFieldAdmin);
395
396
                    $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$id.']', $field->getVar('field_inlist'));
397
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
398
                    $parametersTray->addElement($checkFieldInList);
399
400
                    $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$id.']', $field->getVar('field_inform'));
401
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
402
                    $parametersTray->addElement($checkFieldInForm);
403
404
                    $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$id.']', $field->getVar('field_user'));
405
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
406
                    $parametersTray->addElement($checkFieldUser);
407
408
                    $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$id.']', $field->getVar('field_thead'));
409
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
410
                    $parametersTray->addElement($checkFieldThead);
411
412
                    $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$id.']', $field->getVar('field_tbody'));
413
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
414
                    $parametersTray->addElement($checkFieldTbody);
415
416
                    $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$id.']', $field->getVar('field_tfoot'));
417
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
418
                    $parametersTray->addElement($checkFieldTfoot);
419
420
                    $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$id.']', $field->getVar('field_block'));
421
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
422
                    $parametersTray->addElement($checkFieldBlock);
423
424
                    $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$id.']', $field->getVar('field_search'));
425
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
426
                    $parametersTray->addElement($check_field_search);
427
428
                    $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$id.']', $field->getVar('field_required'));
429
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
430
                    $parametersTray->addElement($checkFieldRequired);
431
432
                    $fieldMain = (1 == $field->getVar('field_main')) ? $id : 1;
433
                    $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
434
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
435
                    $parametersTray->addElement($checkFieldMain);
436
                    //
437
                    $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>'));
438
                }
439
            }
440
            ++$id;
441
        }
442
        // If you change number fields in tables,
443
        // adding missing fields or delete unnecessary fields
444
        // By goffy
445
        for ($i = $id; $i <= $fieldNumb; ++$i) {
446
            $class = ($class == 'even') ? 'odd' : 'even';
447
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
448
        }
449
        unset($id);
450
451
        // Footer form
452
        return $fieldsForm->getFooterForm($form);
453
    }
454
455
    /*
456
    *  @private function getFooterForm
457
    *  @param null
458
    */
459
    /**
460
     * @param $form
461
     *
462
     * @return mixed
463
     */
464
    private function getFooterForm($form)
465
    {
466
        // Send Form Data
467
        $form->addElement(new TDMCreateFormLabel('</tbody>'));
468
        $form->addElement(new TDMCreateFormLabel('<tfoot><tr>'));
469
        $formHidden = new XoopsFormHidden('op', 'save');
470
        $formButton = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
471
        $form->addElement(new TDMCreateFormLabel('<td colspan="8">'.$formHidden->render().'</td>'));
472
        $form->addElement(new TDMCreateFormLabel('<td>'.$formButton->render().'</td>'));
473
        $form->addElement(new TDMCreateFormLabel('</tr></tfoot></table>'));
474
475
        return $form;
476
    }
477
478
    /**
479
     * Get Values.
480
     */
481
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
482
    {
483
        $ret = $this->getValues($keys, $format, $maxDepth);
484
        $ret['id'] = $this->getVar('field_id');
485
        $ret['mid'] = $this->getVar('field_mid');
486
        $ret['tid'] = $this->getVar('field_tid');
487
        $ret['order'] = $this->getVar('field_order');
488
        $ret['name'] = str_replace('_', ' ', ucfirst($this->getVar('field_name')));
489
        $ret['parent'] = $this->getVar('field_parent');
490
        $ret['inlist'] = $this->getVar('field_inlist');
491
        $ret['inform'] = $this->getVar('field_inform');
492
        $ret['admin'] = $this->getVar('field_admin');
493
        $ret['user'] = $this->getVar('field_user');
494
        $ret['block'] = $this->getVar('field_block');
495
        $ret['main'] = $this->getVar('field_main');
496
        $ret['search'] = $this->getVar('field_search');
497
        $ret['required'] = $this->getVar('field_required');
498
499
        return $ret;
500
    }
501
}
502
503
/*
504
*  @Class TDMCreateFieldsHandler
505
*  @extends XoopsPersistableObjectHandler
506
*/
507
508
/**
509
 * Class TDMCreateFieldsHandler.
510
 */
511
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...
512
{
513
    /*
514
    *  @public function constructor class
515
    *  @param mixed $db
516
    */
517
    /**
518
     * @param null|object $db
519
     */
520
    public function __construct(&$db)
521
    {
522
        parent::__construct($db, 'tdmcreate_fields', 'tdmcreatefields', 'field_id', 'field_name');
523
    }
524
525
    /**
526
     * @param bool $isNew
527
     *
528
     * @return object
529
     */
530
    public function create($isNew = true)
531
    {
532
        return parent::create($isNew);
533
    }
534
535
    /**
536
     * retrieve a field.
537
     *
538
     * @param int  $i      field id
539
     * @param null $fields
540
     *
541
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
542
     *               object
543
     */
544
    public function get($i = null, $fields = null)
545
    {
546
        return parent::get($i, $fields);
547
    }
548
549
    /**
550
     * get inserted id.
551
     *
552
     * @param null
553
     *
554
     * @return int reference to the {@link TDMCreateFields} object
555
     */
556
    public function getInsertId()
557
    {
558
        return $this->db->getInsertId();
559
    }
560
    
561
    /**
562
     * insert a new field in the database.
563
     *
564
     * @param object $field reference to the {@link TDMCreateFields} object
565
     * @param bool   $force
566
     *
567
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
568
     */
569
    public function insert(XoopsObject $field, $force = false)
570
    {
571
        if (!parent::insert($field, $force)) {
572
            return false;
573
        }
574
575
        return true;
576
    }
577
578
    /**
579
     * Get Count Fields.
580
     */
581
    public function getCountFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
582
    {
583
        $criteriaCountFields = new CriteriaCompo();
584
        $criteriaCountFields = $this->getFieldsCriteria($criteriaCountFields, $start, $limit, $sort, $order);
585
586
        return $this->getCount($criteriaCountFields);
587
    }
588
589
    /**
590
     * Get All Fields.
591
     */
592
    public function getAllFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
593
    {
594
        $criteriaAllFields = new CriteriaCompo();
595
        $criteriaAllFields = $this->getFieldsCriteria($criteriaAllFields, $start, $limit, $sort, $order);
596
597
        return $this->getAll($criteriaAllFields);
598
    }
599
600
    /**
601
     * Get All Fields By Module & Table Id.
602
     */
603
    public function getAllFieldsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'field_order ASC, field_id, field_name', $order = 'ASC')
604
    {
605
        $criteriaAllFieldsByModule = new CriteriaCompo();
606
        $criteriaAllFieldsByModule->add(new Criteria('field_mid', $modId));
607
        $criteriaAllFieldsByModule->add(new Criteria('field_tid', $tabId));
608
        $criteriaAllFieldsByModule = $this->getFieldsCriteria($criteriaAllFieldsByModule, $start, $limit, $sort, $order);
609
610
        return $this->getAll($criteriaAllFieldsByModule);
611
    }
612
613
    /**
614
     * Get Fields Criteria.
615
     */
616
    private function getFieldsCriteria($criteriaFields, $start, $limit, $sort, $order)
617
    {
618
        $criteriaFields->setStart($start);
619
        $criteriaFields->setLimit($limit);
620
        $criteriaFields->setSort($sort);
621
        $criteriaFields->setOrder($order);
622
623
        return $criteriaFields;
624
    }
625
}
626