Completed
Push — master ( e9acbc...ae1831 )
by Gino
06:34 queued 02:43
created

TDMCreateFieldsHandler::insert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 3
b 1
f 0
nc 2
nop 2
dl 0
loc 8
rs 9.4285
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
     *  @public function constructor class
38
     *
39
     *  @param null
40
     */
41
    public function __construct()
42
    {
43
        $this->initVar('field_id', XOBJ_DTYPE_INT);
44
        $this->initVar('field_mid', XOBJ_DTYPE_INT);
45
        $this->initVar('field_tid', XOBJ_DTYPE_INT);
46
        $this->initVar('field_order', XOBJ_DTYPE_INT);
47
        $this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
54
        $this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
55
        $this->initVar('field_parent', XOBJ_DTYPE_INT);
56
        $this->initVar('field_admin', XOBJ_DTYPE_INT);
57
        $this->initVar('field_inlist', XOBJ_DTYPE_INT);
58
        $this->initVar('field_inform', XOBJ_DTYPE_INT);
59
        $this->initVar('field_user', XOBJ_DTYPE_INT);
60
        $this->initVar('field_thead', XOBJ_DTYPE_INT);
61
        $this->initVar('field_tbody', XOBJ_DTYPE_INT);
62
        $this->initVar('field_tfoot', XOBJ_DTYPE_INT);
63
        $this->initVar('field_block', XOBJ_DTYPE_INT);
64
        $this->initVar('field_main', XOBJ_DTYPE_INT);
65
        $this->initVar('field_search', XOBJ_DTYPE_INT);
66
        $this->initVar('field_required', XOBJ_DTYPE_INT);
67
    }
68
69
    /**
70
     * @param string $method
71
     * @param array  $args
72
     *
73
     * @return mixed
74
     */
75
    public function __call($method, $args)
76
    {
77
        $arg = isset($args[0]) ? $args[0] : null;
78
79
        return $this->getVar($method, $arg);
80
    }
81
82
    /*
83
     * @static function getInstance
84
     *
85
     * @return TDMCreateFields
86
     */
87
    public static function getInstance()
88
    {
89
        static $instance = false;
90
        if (!$instance) {
91
            $instance = new self();
92
        }
93
94
        return $instance;
95
    }
96
97
    /*
98
     * @private function getHeaderForm
99
     *
100
     * @param bool $action
101
     * @return TDMCreateThemeForm
102
     */
103
    private function getHeaderForm($action = false)
104
    {
105
        if ($action === false) {
106
            $action = $_SERVER['REQUEST_URI'];
107
        }
108
109
        $isNew = $this->isNew();
110
        $title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
111
112
        $form = new TDMCreateThemeForm(null, 'form', $action, 'post', true);
113
        $form->setExtra('enctype="multipart/form-data"');
114
115
        // New Object HtmlTable
116
        $form->addElement(new TDMCreateFormLabel('<table cellspacing="1" class="outer width100">'));
117
        $form->addElement(new TDMCreateFormLabel('<thead class="center">'));
118
        $form->addElement(new TDMCreateFormLabel('<tr class="head"><th colspan="9">'.$title.'</th></tr>'));
119
        $form->addElement(new TDMCreateFormLabel('<tr class="head width5">'));
120
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ID.'</td>'));
121
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NAME.'</td>'));
122
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_TYPE.'</td>'));
123
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_VALUE.'</th>'));
124
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_ATTRIBUTE.'</th>'));
125
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_NULL.'</th>'));
126
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_DEFAULT.'</th>'));
127
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_KEY.'</th>'));
128
        $form->addElement(new TDMCreateFormLabel('<td>'._AM_TDMCREATE_FIELD_PARAMETERS.'</th>'));
129
        $form->addElement(new TDMCreateFormLabel('</tr></thead>'));
130
        $form->addElement(new TDMCreateFormLabel('<tbody>'));
131
132
        //
133
        return $form;
134
    }
135
136
    /*
137
     * @public function getFormNew
138
     *
139
     * @param null $fieldMid
140
     * @param null $fieldTid
141
     * @param null $fieldNumb
142
     * @param null $fieldName
143
     * @param bool $action
144
     * @return mixed
145
     */
146
    public function getFormNew($fieldMid = null, $fieldTid = null, $fieldNumb = null, $fieldName = null, $action = false)
147
    {
148
        $tdmcreate = TDMCreateHelper::getInstance();
149
        // Header function class
150
        $fieldsForm = self::getInstance();
151
        $form = $fieldsForm->getHeaderForm($action);
152
        // Get handler tables
153
        $tableObj = $tdmcreate->getHandler('tables'); // Changed by goffy
154
        $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...
155
        // Loop for fields number
156
        $class = 'even';
157
        for ($i = 1; $i <= $fieldNumb; ++$i) {
158
            $class = ($class == 'even') ? 'odd' : 'even';
159
            // Replaced creation of new line by new function - goffy
160
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fieldName, $tableAutoincrement);
161
        }
162
163
        // Footer form
164
        return $fieldsForm->getFooterForm($form);
165
    }
166
167
    /**
168
     * @private function getFormNewLine
169
     *
170
     * @param $form
171
     * @param $class
172
     * @param $i
173
     * @param $fieldMid
174
     * @param $fieldTid
175
     * @param $fName
176
     * @param $tableAutoincrement
177
     */
178
    private function getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement)
179
    {
180
        $tdmcreate = TDMCreateHelper::getInstance();
181
        $form->addElement(new XoopsFormHidden('field_id['.$i.']', 0));
182
        $form->addElement(new XoopsFormHidden('field_mid', $fieldMid));
183
        $form->addElement(new XoopsFormHidden('field_tid', $fieldTid));
184
185
        $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
186
        // Index ID
187
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>'));
188
        // Field Name
189
        $thisFieldName = (!empty($fName) ? ((1 == $i) ? $fName.'_id' : $fName.'_') : '');
190
        $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $thisFieldName);
191
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
192
        // Field Type
193
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
194
        $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value);
195
        $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...
196
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
197
        // Field Value
198
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '8' : '';
199
        $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 10, 200, $value);
200
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
201
        // Field Attributes
202
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '3' : '';
203
        $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']', $value);
204
        $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...
205
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
206
        // Field Null
207
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '2';
208
        $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']', $value);
209
        $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...
210
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
211
        // Field Default
212
        $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25);
213
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
214
        // Field Key
215
        $value = (1 == $i) && (1 == $tableAutoincrement) ? '2' : '';
216
        $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']', $value);
217
        $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...
218
        $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
219
        // Field Void
220
        if ((1 == $i) && (1 == $tableAutoincrement)) {
221
            $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
222
        } else {
223
            // Box header row
224
            $parametersTray = new XoopsFormElementTray('', '<br />');
225
            // Field Elements
226
            $crElement = new CriteriaCompo();
227
            $crElement->add(new Criteria('fieldelement_tid', 0));
228
            $crTable = new CriteriaCompo();
229
            $crTable->add(new Criteria('fieldelement_mid', $fieldMid));
230
            $fieldElementsSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']');
231
            $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crElement));
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...
232
            $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crTable));
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...
233
            unset($crElement, $crTable);
234
            $parametersTray->addElement($fieldElementsSelect);
235
236
            $field_parent = 0;
237
            $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']', $field_parent);
238
            $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
239
            $parametersTray->addElement($checkFieldParent);
240
241
            $field_admin = 0;
242
            $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin);
243
            $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
244
            $parametersTray->addElement($checkFieldAdmin);
245
246
            $field_inlist = 0;
247
            $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist);
248
            $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
249
            $parametersTray->addElement($checkFieldInList);
250
251
            $field_inform = 0;
252
            $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform);
253
            $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
254
            $parametersTray->addElement($checkFieldInForm);
255
256
            $field_user = 0;
257
            $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user);
258
            $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
259
            $parametersTray->addElement($checkFieldUser);
260
261
            $field_thead = 0;
262
            $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$i.']', $field_thead);
263
            $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
264
            $parametersTray->addElement($checkFieldThead);
265
266
            $field_tbody = 0;
267
            $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$i.']', $field_tbody);
268
            $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
269
            $parametersTray->addElement($checkFieldTbody);
270
271
            $field_tfoot = 0;
272
            $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$i.']', $field_tfoot);
273
            $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
274
            $parametersTray->addElement($checkFieldTfoot);
275
276
            $field_block = 0;
277
            $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block);
278
            $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
279
            $parametersTray->addElement($checkFieldBlock);
280
281
            $field_search = 0;
282
            $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search);
283
            $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
284
            $parametersTray->addElement($check_field_search);
285
286
            $field_required = 0;
287
            $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required);
288
            $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
289
            $parametersTray->addElement($checkFieldRequired);
290
291
            $fieldMain = (1 == $tableAutoincrement) ? 2 : 1;
292
            $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
293
            $checkFieldMain->addOption($i, _AM_TDMCREATE_FIELD_MAIN);
294
            $parametersTray->addElement($checkFieldMain);
295
            //
296
            $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>'));
297
        }
298
    }
299
300
    /*
301
     * @public function getFormEdit
302
     *
303
     * @param null $fieldMid
304
     * @param null $fieldTid
305
     * @param bool $action
306
     * @return mixed
307
     */
308
    public function getFormEdit($fieldMid = null, $fieldTid = null, $action = false)
309
    {
310
        $tdmcreate = TDMCreateHelper::getInstance();
311
        // Header function class
312
        $fieldsForm = self::getInstance();
313
        $form = $fieldsForm->getHeaderForm($action);
314
        //
315
        $class = 'even';
316
        // Get the number of fields - goffy
317
        $tablesHandler = &$tdmcreate->getHandler('tables');
318
        $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...
319
        $tableAutoincrement = $tables->getVar('table_autoincrement');
320
        $fieldNumb = $tables->getVar('table_nbfields');
321
        $fName = $tables->getVar('table_fieldname');
322
323
        // Get the list of fields
324
        $cr = new CriteriaCompo();
325
        $cr->add(new Criteria('field_mid', $fieldMid));
326
        $cr->add(new Criteria('field_tid', $fieldTid));
327
        $cr->setSort('field_id'); //added by goffy
328
        $fields = $tdmcreate->getHandler('fields')->getObjects($cr);
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...
329
        unset($cr);
330
        $id = 1;
331
        foreach ($fields as $field) {
332
            $class = ($class == 'even') ? 'odd' : 'even';
333
            $fieldId = (int) ($field->getVar('field_id'));
334
            if ($id > $fieldNumb) {   // delete additional fields, if number of fields is reduced - goffy
335
                $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...
336
                $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...
337
            } else {
338
                // show field with settings
339
                $form->addElement(new XoopsFormHidden('field_id['.$id.']', $fieldId));
340
341
                $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">'));
342
                // Index ID
343
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>'));
344
                // Field Name
345
                $fieldName = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$id.']', 15, 255, $field->getVar('field_name'));
346
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldName->render().'</td>'));
347
                // Field Type
348
                $fieldTypeSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$id.']', $field->getVar('field_type'));
349
                $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...
350
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldTypeSelect->render().'</td>'));
351
                // Field Value
352
                $fieldValue = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$id.']', 10, 200, $field->getVar('field_value'));
353
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldValue->render().'</td>'));
354
                // Field Attributes
355
                $fieldAttributesSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$id.']', $field->getVar('field_attribute'));
356
                $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...
357
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldAttributesSelect->render().'</td>'));
358
                // Field Null
359
                $fieldNullSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$id.']', $field->getVar('field_null'));
360
                $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...
361
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldNullSelect->render().'</td>'));
362
                // Field Default
363
                $fieldDefault = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$id.']', 15, 25, $field->getVar('field_default'));
364
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldDefault->render().'</td>'));
365
                // Field Key
366
                $fieldKeySelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$id.']', $field->getVar('field_key'));
367
                $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...
368
                $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldKeySelect->render().'</td>'));
369
                // Field Void
370
                if ((1 == $id) && (1 == $tableAutoincrement)) {
371
                    $form->addElement(new TDMCreateFormLabel('<td>&nbsp;</td></tr>'));
372
                } else {
373
                    // Box header row
374
                    $parametersTray = new XoopsFormElementTray('', '<br />');
375
                    // Field Elements
376
                    $crElement = new CriteriaCompo();
377
                    $crElement->add(new Criteria('fieldelement_tid', 0));
378
                    $crTable = new CriteriaCompo();
379
                    $crTable->add(new Criteria('fieldelement_mid', $fieldMid));
380
                    $fieldElementsSelect = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$id.']', $field->getVar('field_element'));
381
                    $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crElement));
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...
382
                    $fieldElementsSelect->addOptionArray($tdmcreate->getHandler('fieldelements')->getList($crTable));
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...
383
                    unset($crElement, $crTable);
384
                    $parametersTray->addElement($fieldElementsSelect);
385
386
                    $checkFieldParent = new XoopsFormCheckBox(' ', 'field_parent['.$id.']', $field->getVar('field_parent'));
387
                    $checkFieldParent->addOption(1, _AM_TDMCREATE_FIELD_PARENT);
388
                    $parametersTray->addElement($checkFieldParent);
389
390
                    $checkFieldAdmin = new XoopsFormCheckBox(' ', 'field_admin['.$id.']', $field->getVar('field_admin'));
391
                    $checkFieldAdmin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
392
                    $parametersTray->addElement($checkFieldAdmin);
393
394
                    $checkFieldInList = new XoopsFormCheckBox(' ', 'field_inlist['.$id.']', $field->getVar('field_inlist'));
395
                    $checkFieldInList->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
396
                    $parametersTray->addElement($checkFieldInList);
397
398
                    $checkFieldInForm = new XoopsFormCheckBox(' ', 'field_inform['.$id.']', $field->getVar('field_inform'));
399
                    $checkFieldInForm->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
400
                    $parametersTray->addElement($checkFieldInForm);
401
402
                    $checkFieldUser = new XoopsFormCheckBox(' ', 'field_user['.$id.']', $field->getVar('field_user'));
403
                    $checkFieldUser->addOption(1, _AM_TDMCREATE_FIELD_USER);
404
                    $parametersTray->addElement($checkFieldUser);
405
406
                    $checkFieldThead = new XoopsFormCheckBox(' ', 'field_thead['.$id.']', $field->getVar('field_thead'));
407
                    $checkFieldThead->addOption(1, _AM_TDMCREATE_FIELD_THEAD);
408
                    $parametersTray->addElement($checkFieldThead);
409
410
                    $checkFieldTbody = new XoopsFormCheckBox(' ', 'field_tbody['.$id.']', $field->getVar('field_tbody'));
411
                    $checkFieldTbody->addOption(1, _AM_TDMCREATE_FIELD_TBODY);
412
                    $parametersTray->addElement($checkFieldTbody);
413
414
                    $checkFieldTfoot = new XoopsFormCheckBox(' ', 'field_tfoot['.$id.']', $field->getVar('field_tfoot'));
415
                    $checkFieldTfoot->addOption(1, _AM_TDMCREATE_FIELD_TFOOT);
416
                    $parametersTray->addElement($checkFieldTfoot);
417
418
                    $checkFieldBlock = new XoopsFormCheckBox('', 'field_block['.$id.']', $field->getVar('field_block'));
419
                    $checkFieldBlock->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
420
                    $parametersTray->addElement($checkFieldBlock);
421
422
                    $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$id.']', $field->getVar('field_search'));
423
                    $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
424
                    $parametersTray->addElement($check_field_search);
425
426
                    $checkFieldRequired = new XoopsFormCheckBox(' ', 'field_required['.$id.']', $field->getVar('field_required'));
427
                    $checkFieldRequired->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
428
                    $parametersTray->addElement($checkFieldRequired);
429
430
                    $fieldMain = (1 == $field->getVar('field_main')) ? $id : 1;
431
                    $checkFieldMain = new TDMCreateFormRadio('', 'field_main', $fieldMain);
432
                    $checkFieldMain->addOption($id, _AM_TDMCREATE_FIELD_MAIN);
433
                    $parametersTray->addElement($checkFieldMain);
434
                    //
435
                    $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>'));
436
                }
437
            }
438
            ++$id;
439
        }
440
        // If you change number fields in tables,
441
        // adding missing fields or delete unnecessary fields
442
        // By goffy
443
        for ($i = $id; $i <= $fieldNumb; ++$i) {
444
            $class = ($class == 'even') ? 'odd' : 'even';
445
            $this->getFormNewLine($form, $class, $i, $fieldMid, $fieldTid, $fName, $tableAutoincrement);
446
        }
447
        unset($id);
448
449
        // Footer form
450
        return $fieldsForm->getFooterForm($form);
451
    }
452
453
    /**
454
     *  @private function getFooterForm
455
     *
456
     *  @param null
457
     * @param $form
458
     *
459
     * @return mixed
460
     */
461
    private function getFooterForm($form)
462
    {
463
        // Send Form Data
464
        $form->addElement(new TDMCreateFormLabel('</tbody>'));
465
        $form->addElement(new TDMCreateFormLabel('<tfoot><tr>'));
466
        $formHidden = new XoopsFormHidden('op', 'save');
467
        $formButton = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
468
        $form->addElement(new TDMCreateFormLabel('<td colspan="8">'.$formHidden->render().'</td>'));
469
        $form->addElement(new TDMCreateFormLabel('<td>'.$formButton->render().'</td>'));
470
        $form->addElement(new TDMCreateFormLabel('</tr></tfoot></table>'));
471
472
        return $form;
473
    }
474
475
    /**
476
     * Get Values.
477
     */
478
    public function getValuesFields($keys = null, $format = null, $maxDepth = null)
479
    {
480
        $ret = $this->getValues($keys, $format, $maxDepth);
481
        $ret['id'] = $this->getVar('field_id');
482
        $ret['mid'] = $this->getVar('field_mid');
483
        $ret['tid'] = $this->getVar('field_tid');
484
        $ret['order'] = $this->getVar('field_order');
485
        $ret['name'] = str_replace('_', ' ', ucfirst($this->getVar('field_name')));
486
        $ret['parent'] = $this->getVar('field_parent');
487
        $ret['inlist'] = $this->getVar('field_inlist');
488
        $ret['inform'] = $this->getVar('field_inform');
489
        $ret['admin'] = $this->getVar('field_admin');
490
        $ret['user'] = $this->getVar('field_user');
491
        $ret['block'] = $this->getVar('field_block');
492
        $ret['main'] = $this->getVar('field_main');
493
        $ret['search'] = $this->getVar('field_search');
494
        $ret['required'] = $this->getVar('field_required');
495
496
        return $ret;
497
    }
498
}
499
500
/*
501
*  @Class TDMCreateFieldsHandler
502
*  @extends XoopsPersistableObjectHandler
503
*/
504
505
/**
506
 * Class TDMCreateFieldsHandler.
507
 */
508
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...
509
{
510
    /**
511
     *  @public function constructor class
512
     *
513
     *  @param mixed $db
514
     * @param null|object $db
515
     */
516
    public function __construct(&$db)
517
    {
518
        parent::__construct($db, 'tdmcreate_fields', 'tdmcreatefields', 'field_id', 'field_name');
519
    }
520
521
    /**
522
     * @param bool $isNew
523
     *
524
     * @return object
525
     */
526
    public function create($isNew = true)
527
    {
528
        return parent::create($isNew);
529
    }
530
531
    /**
532
     * retrieve a field.
533
     *
534
     * @param int  $i      field id
535
     * @param null $fields
536
     *
537
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
538
     *               object
539
     */
540
    public function get($i = null, $fields = null)
541
    {
542
        return parent::get($i, $fields);
543
    }
544
545
    /**
546
     * get inserted id.
547
     *
548
     * @param null
549
     *
550
     * @return int reference to the {@link TDMCreateFields} object
551
     */
552
    public function getInsertId()
553
    {
554
        return $this->db->getInsertId();
555
    }
556
557
    /**
558
     * Get Count Fields.
559
     */
560
    public function getCountFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
561
    {
562
        $crCountFields = new CriteriaCompo();
563
        $crCountFields = $this->getFieldsCriteria($crCountFields, $start, $limit, $sort, $order);
564
565
        return $this->getCount($crCountFields);
566
    }
567
568
    /**
569
     * Get All Fields.
570
     */
571
    public function getAllFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
572
    {
573
        $crAllFields = new CriteriaCompo();
574
        $crAllFields = $this->getFieldsCriteria($crAllFields, $start, $limit, $sort, $order);
575
576
        return $this->getAll($crAllFields);
577
    }
578
579
    /**
580
     * Get All Fields By Module & Table Id.
581
     */
582
    public function getAllFieldsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'field_order ASC, field_id, field_name', $order = 'ASC')
583
    {
584
        $crAllFieldsByModule = new CriteriaCompo();
585
        $crAllFieldsByModule->add(new Criteria('field_mid', $modId));
586
        $crAllFieldsByModule->add(new Criteria('field_tid', $tabId));
587
        $crAllFieldsByModule = $this->getFieldsCriteria($crAllFieldsByModule, $start, $limit, $sort, $order);
588
589
        return $this->getAll($crAllFieldsByModule);
590
    }
591
592
    /**
593
     * Get Fields Criteria.
594
     */
595
    private function getFieldsCriteria($crFields, $start, $limit, $sort, $order)
596
    {
597
        $crFields->setStart($start);
598
        $crFields->setLimit($limit);
599
        $crFields->setSort($sort);
600
        $crFields->setOrder($order);
601
602
        return $crFields;
603
    }
604
}
605