Completed
Pull Request — master (#144)
by Michael
04:31
created

ClassFiles   F

Complexity

Total Complexity 74

Size/Duplication

Total Lines 788
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 438
dl 0
loc 788
rs 2.48
c 0
b 0
f 0
wmc 74

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitVar() 0 5 1
A getClassGetTableSolenameById() 0 23 1
A getClassCreate() 0 9 1
A __construct() 0 3 1
A getClassCounter() 0 17 1
A getToArrayInObject() 0 18 1
A getClassByCategory() 0 37 2
A getPermissionsInForm() 0 41 1
A getClassAll() 0 17 1
A getOptionsCheck() 0 28 3
A getClassObjectHandler() 0 32 3
B getValuesInObject() 0 59 9
A write() 0 6 1
A getFunctionForm() 0 57 4
B render() 0 40 6
B getClassObject() 0 65 8
A getClassCriteria() 0 18 1
A getInstance() 0 8 2
A getClassGet() 0 9 1
D getInitVars() 0 58 24
A getNewInsertId() 0 13 1
A getClassGetInsertId() 0 9 1

How to fix   Complexity   

Complex Class

Complex classes like ClassFiles often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ClassFiles, and based on these observations, apply Extract Interface, too.

1
<?php namespace XoopsModules\Tdmcreate\Files\Classes;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tc module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: ClassFiles.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class ClassFiles.
30
 */
31
class ClassFiles extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *
36
     *  @param null
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     *  @static function getInstance
45
     *
46
     *  @param null
47
     *
48
     * @return ClassFiles
49
     */
50
    public static function getInstance()
51
    {
52
        static $instance = false;
53
        if (!$instance) {
54
            $instance = new self();
55
        }
56
57
        return $instance;
58
    }
59
60
    /**
61
     * @public function write
62
     *
63
     * @param string $module
64
     * @param string $table
65
     * @param mixed  $tables
66
     * @param        $filename
67
     */
68
    public function write($module, $table, $tables, $filename)
69
    {
70
        $this->setModule($module);
71
        $this->setTable($table);
72
        $this->setTables($tables);
73
        $this->setFileName($filename);
74
    }
75
76
    /**
77
     *  @private function getInitVar
78
     *
79
     *  @param string $fieldName
80
     *  @param string $type
81
     *
82
     * @return string
83
     */
84
    private function getInitVar($fieldName, $type = 'INT')
85
    {
86
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
87
88
        return $cc->getClassInitVar($fieldName, $type);
89
    }
90
91
    /**
92
     *  @private function getInitVars
93
     *
94
     *  @param array $fields
95
     *
96
     * @return string
97
     */
98
    private function getInitVars($fields)
99
    {
100
        $tc = Tdmcreate\Helper::getInstance();
101
        $ret = '';
102
        // Creation of the initVar functions list
103
        foreach (array_keys($fields) as $f) {
104
            $fieldName = $fields[$f]->getVar('field_name');
105
            $fieldType = $fields[$f]->getVar('field_type');
106
            if ($fieldType > 1) {
107
                $fType = $tc->getHandler('fieldtype')->get($fieldType);
108
                $fieldTypeName = $fType->getVar('fieldtype_name');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldTypeName is dead and can be removed.
Loading history...
109
            } else {
110
                $fieldType = null;
111
            }
112
            switch ($fieldType) {
113
                case 2:
114
                case 3:
115
                case 4:
116
                case 5:
117
                    $ret .= $this->getInitVar($fieldName, 'INT');
118
                    break;
119
                case 6:
120
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
121
                    break;
122
                case 7:
123
                case 8:
124
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
125
                    break;
126
                case 10:
127
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
128
                    break;
129
                case 11:
130
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
131
                    break;
132
                case 12:
133
                    $ret .= $this->getInitVar($fieldName, 'URL');
134
                    break;
135
                case 13:
136
                case 14:
137
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
138
                    break;
139
                case 15:
140
                case 16:
141
                case 17:
142
                case 18:
143
                    $ret .= $this->getInitVar($fieldName, 'TXTAREA');
144
                    break;
145
                case 19:
146
                case 20:
147
                case 21:
148
                case 22:
149
                case 23:
150
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
151
                    break;
152
            }
153
        }
154
155
        return $ret;
156
    }
157
158
    /**
159
     * @private  function getClassObject
160
     * @param $module
161
     * @param $table
162
     * @param $fields
163
     * @return string
164
     */
165
    private function getClassObject($module, $table, $fields)
166
    {
167
        $tc = Tdmcreate\Helper::getInstance();
168
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
169
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
170
        $moduleDirname = $module->getVar('mod_dirname');
171
        $tableName = $table->getVar('table_name');
172
        $ucfModuleDirname = ucfirst($moduleDirname);
173
        $ucfTableName = ucfirst($tableName);
174
        $ret = $pc->getPhpCodeDefined();
175
        $ret .= $pc->getPhpCodeCommentMultiLine(['Class Object' => $ucfModuleDirname . $ucfTableName]);
176
        $cCl = '';
177
178
        $fieldInForm = [];
179
        $fieldElementId = [];
180
        $optionsFieldName = [];
181
        foreach (array_keys($fields) as $f) {
182
            $fieldName = $fields[$f]->getVar('field_name');
183
            $fieldElement = $fields[$f]->getVar('field_element');
184
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
185
            $fieldElements = $tc->getHandler('fieldelements')->get($fieldElement);
186
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
187
            $rpFieldName = $this->getRightString($fieldName);
188
            if (in_array(5, $fieldElementId)) {
189
                if (count($rpFieldName) % 5) {
0 ignored issues
show
Bug introduced by
$rpFieldName of type string is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

189
                if (count(/** @scrutinizer ignore-type */ $rpFieldName) % 5) {
Loading history...
190
                    $optionsFieldName[] = "'" . $rpFieldName . "'";
191
                } else {
192
                    $optionsFieldName[] = "'" . $rpFieldName . "'\n";
193
                }
194
            }
195
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
196
                $fieldId = $fieldName;
197
            }
198
        }
199
        if (in_array(5, $fieldElementId) > 1) {
200
            $optionsElements = implode(', ', $optionsFieldName);
0 ignored issues
show
Unused Code introduced by
The assignment to $optionsElements is dead and can be removed.
Loading history...
201
            $cCl .= $pc->getPhpCodeCommentMultiLine(['Options' => '']);
202
            $options = $pc->getPhpCodeArray('', $optionsFieldName, true);
203
            $cCl .= $pc->getPhpCodeVariableClass('private', 'options', $options);
204
        }
205
        unset($optionsFieldName);
206
207
        $cCl .= $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t");
208
        $constr = $this->getInitVars($fields);
209
        $cCl .= $pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t");
210
        $arrayGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null'];
211
        $cCl .= $pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t");
212
        $getInstance = $pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t");
213
        $instance = $xc->getXcEqualsOperator('$instance', 'new self()', null, false, "\t\t\t");
214
        $getInstance .= $pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t");
215
        $cCl .= $pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t");
216
217
        $cCl .= $this->getNewInsertId($table);
218
        $cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
219
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
220
        $cCl .= $this->getToArrayInObject($table);
221
222
        if (in_array(5, $fieldElementId) > 1) {
223
            $cCl .= $this->getOptionsCheck($table);
224
        }
225
        unset($fieldElementId);
226
227
        $ret .= $pc->getPhpCodeClass($ucfModuleDirname . $ucfTableName, $cCl, 'XoopsObject');
228
229
        return $ret;
230
    }
231
232
    /**
233
     *  @private function getNewInsertId
234
     *
235
     *  @param $table
236
     *
237
     * @return string
238
     */
239
    private function getNewInsertId($table)
240
    {
241
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
242
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
243
        $tableName = $table->getVar('table_name');
244
        $ucfTableName = ucfirst($tableName);
245
        $ret = $pc->getPhpCodeCommentMultiLine(['The new inserted' => '$Id', '@return' => 'inserted id'], "\t");
246
        $getInsertedId = $xc->getXcEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, false, "\t\t");
247
        $getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t");
248
249
        $ret .= $pc->getPhpCodeFunction('getNewInsertedId' . $ucfTableName, '', $getInsertedId, 'public ', false, "\t");
250
251
        return $ret;
252
    }
253
254
    /**
255
     * @private function getFunctionForm
256
     *
257
     * @param string $module
258
     * @param string $table
259
     *
260
     * @param        $fieldId
261
     * @param        $fieldInForm
262
     * @return string
263
     */
264
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
265
    {
266
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
267
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
268
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
269
        $fe = ClassFormElements::getInstance();
270
        $moduleDirname = $module->getVar('mod_dirname');
271
        $tableName = $table->getVar('table_name');
272
        $tableSoleName = $table->getVar('table_solename');
273
        $tableCategory = $table->getVar('table_category');
274
        $tablePermissions = $table->getVar('table_permissions');
0 ignored issues
show
Unused Code introduced by
The assignment to $tablePermissions is dead and can be removed.
Loading history...
275
        $ucfTableName = ucfirst($tableName);
276
        $stuTableSoleName = mb_strtoupper($tableSoleName);
277
        $language = $this->getLanguage($moduleDirname, 'AM');
278
        $fe->initForm($module, $table);
279
        $ret = $pc->getPhpCodeCommentMultiLine(['@public function' => 'getForm', '@param bool' => '$action', '@return' => 'XoopsThemeForm'], "\t");
280
        $action = $xc->getXcEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, false, "\t\t\t");
281
        $ucfModuleDirname = ucfirst($moduleDirname);
282
        $getForm = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t");
283
        //$getForm .= $pc->getPhpCodeConditions('$action', ' === ', 'false', $action, false, "\t\t");
284
        $getForm .= $pc->getPhpCodeConditions('false', ' === ', '$action', $action, false, "\t\t");
285
        $xUser = $pc->getPhpCodeGlobals('xoopsUser');
286
        $xModule = $pc->getPhpCodeGlobals('xoopsModule');
287
        if (1 != $tableCategory/* && (1 == $tablePermissions)*/) {
288
            $getForm .= $pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t");
289
            $getForm .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t");
290
            $getForm .= $pc->getPhpCodeTernaryOperator('groups', 'is_object(' . $xUser . ')', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t");
291
            $checkRight = $xc->getXcCheckRight('$gpermHandler', $permString = '', 32, '$groups', $xModule . '->getVar(\'mid\')', true);
292
            $ternaryOperator = $pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t\t");
293
            $permissionUpload = $xc->getXcEqualsOperator('$permissionUpload', 'true', null, false, "\t\t\t\t");
294
            $ternOperator = $pc->getPhpCodeRemoveCarriageReturn($ternaryOperator, '', "\r");
295
            $if = $pc->getPhpCodeConditions('!' . $xUser . '->isAdmin(' . $xModule . '->mid())', '', '', $ternaryOperator, $permissionUpload, "\t\t\t");
296
            $getForm .= $pc->getPhpCodeConditions($xUser, '', '', $if, $ternOperator, "\t\t");
297
        }
298
        $getForm .= $pc->getPhpCodeCommentLine('Title', '', "\t\t");
299
        $getForm .= $pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "sprintf({$language}{$stuTableSoleName}_ADD)", "sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t");
300
        $getForm .= $pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t");
301
        $getForm .= $xc->getXcLoad('XoopsFormLoader', "\t\t");
302
        $getForm .= $cc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post');
303
        $getForm .= $cc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'");
304
        $getForm .= $fe->renderElements();
305
306
        if (in_array(1, $fieldInForm)) {
307
            if (1 == $table->getVar('table_permissions')) {
308
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId);
309
            }
310
        }
311
        $getForm .= $pc->getPhpCodeCommentLine('To Save', '', "\t\t");
312
        //$hiddenSave = $cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false);
313
        $getForm .= $cc->getClassAddElement('form', "new \XoopsFormHidden('op', 'save')");
314
        //$buttonSend = $cc->getClassXoopsFormButton('', '', 'submit', '_SUBMIT', 'submit', true);
315
        $getForm .= $cc->getClassAddElement('form', "new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)");
316
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
317
318
        $ret .= $pc->getPhpCodeFunction('getForm' . $ucfTableName, '$action = false', $getForm, 'public ', false, "\t");
319
320
        return $ret;
321
    }
322
323
    /**
324
     *  @private function getPermissionsInForm
325
     *
326
     *  @param string $moduleDirname
327
     *  @param string $fieldId
328
     *
329
     * @return string
330
     */
331
    private function getPermissionsInForm($moduleDirname, $fieldId)
332
    {
333
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
334
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
335
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
336
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
337
        $permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
338
        $permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
339
        $ret = $pc->getPhpCodeCommentLine('Permissions', '', "\t\t");
340
        $ret .= $xc->getXcEqualsOperator('$memberHandler', "xoops_getHandler('member')", null, false, "\t\t");
341
        $ret .= $xc->getXcEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, false, "\t\t");
342
        $ret .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, false, "\t\t");
343
        $ret .= $pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t");
344
        $fId = $xc->getXcGetVar('', 'this', $fieldId, true);
345
        $mId = $xc->getXcGetVar('', "GLOBALS['xoopsModule']", 'mid', true);
346
        $ifGroups = $xc->getXcGetGroupIds('groupsIdsApprove', 'gpermHandler', "'{$moduleDirname}_approve'", $fId, $mId, "\t\t\t");
347
        $ifGroups .= $pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t");
348
        $ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$groupsIdsApprove', false, "\t\t\t");
349
        $ifGroups .= $xc->getXcGetGroupIds('groupsIdsSubmit', 'gpermHandler', "'{$moduleDirname}_submit'", $fId, $mId, "\t\t\t");
350
        $ifGroups .= $pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t");
351
        $ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$groupsIdsSubmit', false, "\t\t\t");
352
        $ifGroups .= $xc->getXcGetGroupIds('groupsIdsView', 'gpermHandler', "'{$moduleDirname}_view'", $fId, $mId, "\t\t\t");
353
        $ifGroups .= $pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t");
354
        $ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$groupsIdsView', false, "\t\t\t");
355
356
        $else = $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$fullList', false, "\t\t\t");
357
        $else .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$fullList', false, "\t\t\t");
358
        $else .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$fullList', false, "\t\t\t");
359
360
        $ret .= $pc->getPhpCodeConditions('!$this->isNew()', null, null, $ifGroups, $else, "\t\t");
361
        $ret .= $pc->getPhpCodeCommentLine('To Approve', '', "\t\t");
362
        $ret .= $cc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList');
363
        $ret .= $cc->getClassAddElement('form', '$groupsCanApproveCheckbox');
364
        $ret .= $pc->getPhpCodeCommentLine('To Submit', '', "\t\t");
365
        $ret .= $cc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList');
366
        $ret .= $cc->getClassAddElement('form', '$groupsCanSubmitCheckbox');
367
        $ret .= $pc->getPhpCodeCommentLine('To View', '', "\t\t");
368
        $ret .= $cc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList');
369
        $ret .= $cc->getClassAddElement('form', '$groupsCanViewCheckbox');
370
371
        return $ret;
372
    }
373
374
    /**
375
     * @private  function getValuesInObject
376
     *
377
     * @param $moduleDirname
378
     * @param $table
379
     * @param $fields
380
     * @return string
381
     * @internal param $null
382
     */
383
    private function getValuesInObject($moduleDirname, $table, $fields)
384
    {
385
        $tc = Tdmcreate\Helper::getInstance();
386
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
387
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
388
        $stuModuleDirname = mb_strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
The assignment to $stuModuleDirname is dead and can be removed.
Loading history...
389
        $ucfTableName = ucfirst($table->getVar('table_name'));
390
        $ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Values', '@param null $keys' => '', '@param null $format' => '', '@param null$maxDepth' => '', '@return' => 'array'], "\t");
391
        $ucfModuleDirname = ucfirst($moduleDirname);
392
        $getValues = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t");
393
        $getValues .= $xc->getXcEqualsOperator('$ret', '$this->getValues($keys, $format, $maxDepth)', null, false, "\t\t");
394
395
        foreach (array_keys($fields) as $f) {
396
            $fieldName = $fields[$f]->getVar('field_name');
397
            $fieldElement = $fields[$f]->getVar('field_element');
398
            $rpFieldName = $this->getRightString($fieldName);
399
            switch ($fieldElement) {
400
                case 3:
401
                case 4:
402
                    $getValues .= $pc->getPhpCodeStripTags("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", false, "\t\t");
403
                break;
404
                case 8:
405
                    $getValues .= $xc->getXcUnameFromId("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", "\t\t");
406
                break;
407
                case 15:
408
                    $getValues .= $xc->getXcFormatTimeStamp("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", 's', "\t\t");
409
                break;
410
                default:
411
                    if ($fieldElement > 15) {
412
                        $fieldElements = $tc->getHandler('fieldelements')->get($fieldElement);
413
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
414
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
415
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
416
                        $fieldNameDesc = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
0 ignored issues
show
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $haystack of mb_strrpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

416
                        $fieldNameDesc = mb_substr($fieldElementName, mb_strrpos(/** @scrutinizer ignore-type */ $fieldElementName, ':'), mb_strlen($fieldElementName));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

416
                        $fieldNameDesc = mb_substr(/** @scrutinizer ignore-type */ $fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

416
                        $fieldNameDesc = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen(/** @scrutinizer ignore-type */ $fieldElementName));
Loading history...
417
                        $topicTableName = str_replace(': ', '', mb_strtolower($fieldNameDesc));
418
                        $fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid);
419
                        foreach (array_keys($fieldsTopics) as $g) {
420
                            $fieldNameTopic = $fieldsTopics[$g]->getVar('field_name');
421
                            if (1 == $fieldsTopics[$g]->getVar('field_main')) {
422
                                $fieldMainTopic = $fieldNameTopic;
423
                            }
424
                        }
425
                        $getHandlerVar = "\${$moduleDirname}->getHandler('{$topicTableName}')";
426
                        $getValues .= $xc->getXcEqualsOperator("\${$topicTableName}", $getHandlerVar, null, false, "\t\t");
427
                        $getTopicTable = "\${$topicTableName}->get(\$this->getVar('{$fieldName}'))";
428
                        $getValues .= $xc->getXcEqualsOperator("\${$topicTableName}Obj", $getTopicTable, null, false, "\t\t");
429
                        $fMainTopic = "\${$topicTableName}Obj->getVar('{$fieldMainTopic}')";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldMainTopic does not seem to be defined for all execution paths leading up to this point.
Loading history...
430
                        $getValues .= $xc->getXcEqualsOperator("\$ret['{$rpFieldName}']", $fMainTopic, null, false, "\t\t");
431
                    } else {
432
                        $getValues .= $xc->getXcGetVar("ret['{$rpFieldName}']", 'this', $fieldName, false, "\t\t");
433
                    }
434
                break;
435
            }
436
        }
437
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
438
439
        $ret .= $pc->getPhpCodeFunction('getValues' . $ucfTableName, '$keys = null, $format = null, $maxDepth = null', $getValues, 'public ', false, "\t");
440
441
        return $ret;
442
    }
443
444
    /**
445
     *  @private function getToArrayInObject
446
     *
447
     *  @param $table
448
     *
449
     * @return string
450
     */
451
    private function getToArrayInObject($table)
452
    {
453
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
454
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
455
        $tableName = $table->getVar('table_name');
456
        $ucfTableName = ucfirst($tableName);
457
        $multiLineCom = ['Returns an array representation' => 'of the object', '' => '', '@return' => 'array'];
458
        $ret = $pc->getPhpCodeCommentMultiLine($multiLineCom, "\t");
459
460
        $getToArray = $pc->getPhpCodeArray('ret', [], false, "\t\t");
461
        $getToArray .= $xc->getXcEqualsOperator('$vars', '$this->getVars()', null, false, "\t\t");
462
        $foreach = $xc->getXcGetVar('ret[$var]', 'this', '"{$var}"', false, "\t");
463
        $getToArray .= $pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t");
464
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
465
466
        $ret .= $pc->getPhpCodeFunction('toArray' . $ucfTableName, '', $getToArray, 'public ', false, "\t");
467
468
        return $ret;
469
    }
470
471
    /**
472
     *  @private function getOptionsCheck
473
     *
474
     *  @param $table
475
     *
476
     * @return string
477
     */
478
    private function getOptionsCheck($table)
479
    {
480
        $tc = Tdmcreate\Helper::getInstance();
481
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
482
        $tableName = $table->getVar('table_name');
483
        $ucfTableName = ucfirst($tableName);
484
        $ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Options'], "\t");
485
        $getOptions = $pc->getPhpCodeArray('ret', [], false, "\t");
486
487
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
488
        foreach (array_keys($fields) as $f) {
489
            $fieldName = $fields[$f]->getVar('field_name');
490
            $fieldElement = $fields[$f]->getVar('field_element');
491
492
            $fieldElements = $tc->getHandler('fieldelements')->get($fieldElement);
493
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
494
            $rpFieldName = $this->getRightString($fieldName);
495
            if (5 == $fieldElementId) {
496
                $arrayPush = $pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t");
497
                $getOptions .= $pc->getPhpCodeConditions(1, ' == ', "\$this->getVar('{$fieldName}')", $arrayPush, false, "\t\t");
498
            }
499
        }
500
501
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
502
503
        $ret .= $pc->getPhpCodeFunction('getOptions' . $ucfTableName, '', $getOptions, 'public ', false, "\t");
504
505
        return $ret;
506
    }
507
508
    /**
509
     * @public function getClassHandler
510
     *
511
     * @param string $moduleDirname
512
     * @param string $table
513
     * @param string $fieldId
514
     * @param        $fieldName
515
     * @param string $fieldMain
516
     *
517
     * @param        $fieldParent
518
     * @param        $fieldParentId
519
     * @param        $fieldElement
520
     * @return string
521
     */
522
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement)
523
    {
524
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
525
        $tableName = $table->getVar('table_name');
526
        $tableCategory = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableCategory is dead and can be removed.
Loading history...
527
        $tableSoleName = $table->getVar('table_solename');
528
        $tableFieldname = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableFieldname is dead and can be removed.
Loading history...
529
        $ucfModuleDirname = ucfirst($moduleDirname);
530
        $ucfTableName = ucfirst($tableName);
531
        $ucfTableSoleName = ucfirst($tableSoleName);
0 ignored issues
show
Unused Code introduced by
The assignment to $ucfTableSoleName is dead and can be removed.
Loading history...
532
        $ucfModuleTable = $ucfModuleDirname . $ucfTableName;
533
        $multiLineCom = ['Class Object Handler' => $ucfModuleDirname . $ucfTableName];
534
        $ret = $pc->getPhpCodeCommentMultiLine($multiLineCom);
535
536
        $cClh = $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null|XoopsDatabase $db'], "\t");
537
        $constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n";
538
539
        $cClh .= $pc->getPhpCodeFunction('__construct', 'XoopsDatabase $db', $constr, 'public ', false, "\t");
540
        $cClh .= $this->getClassCreate();
541
        $cClh .= $this->getClassGet();
542
        $cClh .= $this->getClassGetInsertId();
543
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
544
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
545
        $cClh .= $this->getClassCriteria($tableName);
546
        if ($fieldElement > 15 && in_array(1, $fieldParentId)) {
547
            $cClh .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableFieldName does not exist. Did you maybe mean $tableFieldname?
Loading history...
548
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
549
        }
550
551
        $ret .= $pc->getPhpCodeClass("{$ucfModuleTable}Handler", $cClh, 'XoopsPersistableObjectHandler');
552
553
        return $ret;
554
    }
555
556
    /**
557
     *  @public function getClassCreate
558
     *
559
     *  @return string
560
     */
561
    private function getClassCreate()
562
    {
563
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
564
        $ret = $pc->getPhpCodeCommentMultiLine(['@param bool' => '$isNew', '' => '', '@return' => 'object'], "\t");
565
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
566
567
        $ret .= $pc->getPhpCodeFunction('create', '$isNew = true', $cClhc, 'public ', false, "\t");
568
569
        return $ret;
570
    }
571
572
    /**
573
     *  @public function getClassGet
574
     *
575
     *  @return string
576
     */
577
    private function getClassGet()
578
    {
579
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
580
        $ret = $pc->getPhpCodeCommentMultiLine(['retrieve a' => 'field', '' => '', '@param int' => '$i field id', '@param null' => 'fields', '@return mixed reference to the' => '{@link Get} object'], "\t");
581
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
582
583
        $ret .= $pc->getPhpCodeFunction('get', '$i = null, $fields = null', $cClhg, 'public ', false, "\t");
584
585
        return $ret;
586
    }
587
588
    /**
589
     *  @public function getClassGetInsertId
590
     *
591
     *  @return string
592
     */
593
    private function getClassGetInsertId()
594
    {
595
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
596
        $ret = $pc->getPhpCodeCommentMultiLine(['get inserted' => 'id', '' => '', '@param' => 'null', '@return integer reference to the' => '{@link Get} object'], "\t");
597
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
598
599
        $ret .= $pc->getPhpCodeFunction('getInsertId', '', $cClhgid, 'public ', false, "\t");
600
601
        return $ret;
602
    }
603
604
    /**
605
     *  @public function getClassCounter
606
     *
607
     *  @param $tableName
608
     *  @param $fieldId
609
     *  @param $fieldMain
610
     *
611
     *  @return string
612
     */
613
    private function getClassCounter($tableName, $fieldId, $fieldMain)
614
    {
615
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
616
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
617
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
618
        $ucfTableName = ucfirst($tableName);
619
        $ret = $pc->getPhpCodeCommentMultiLine(['Get Count ' . $ucfTableName => 'in the database', '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t");
620
621
        $critCount = $cc->getClassCriteriaCompo('crCount' . $ucfTableName, "\t\t");
622
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
623
        $critCount .= $xc->getXcEqualsOperator('$crCount' . $ucfTableName, $paramsCrit, null, false, "\t\t");
624
        $critCount .= $this->getSimpleString("return parent::getCount(\$crCount{$ucfTableName});", "\t\t");
625
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
626
627
        $ret .= $pc->getPhpCodeFunction('getCount' . $ucfTableName, $params, $critCount, 'public ', false, "\t");
628
629
        return $ret;
630
    }
631
632
    /**
633
     *  @public function getClassAll
634
     *
635
     *  @param $tableName
636
     *  @param $fieldId
637
     *  @param $fieldMain
638
     *
639
     *  @return string
640
     */
641
    private function getClassAll($tableName, $fieldId, $fieldMain)
642
    {
643
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
644
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
645
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
646
        $ucfTableName = ucfirst($tableName);
647
        $ret = $pc->getPhpCodeCommentMultiLine(['Get All ' . $ucfTableName => 'in the database', '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t");
648
649
        $critAll = $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t");
650
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
651
        $critAll .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCrit, null, false, "\t\t");
652
        $critAll .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t");
653
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
654
655
        $ret .= $pc->getPhpCodeFunction('getAll' . $ucfTableName, $params, $critAll, 'public ', false, "\t");
656
657
        return $ret;
658
    }
659
660
    /**
661
     * @public function getClassByCategory
662
     *
663
     * @param $moduleDirname
664
     * @param $tableName
665
     * @param $tableFieldName
666
     * @param $fieldId
667
     * @param $fieldName
668
     * @param $fieldMain
669
     * @param $fieldParent
670
     *
671
     * @param $fieldElement
672
     * @return string
673
     */
674
    private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement)
0 ignored issues
show
Unused Code introduced by
The parameter $fieldParent is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

674
    private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, /** @scrutinizer ignore-unused */ $fieldParent, $fieldElement)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
675
    {
676
        $tc = Tdmcreate\Helper::getInstance();
677
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
678
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
679
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
680
        $ucfTableName = ucfirst($tableName);
681
        $fieldElements = $tc->getHandler('fieldelements')->get($fieldElement);
682
        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldElementMid is dead and can be removed.
Loading history...
683
        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldElementTid is dead and can be removed.
Loading history...
684
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
685
        $fieldNameDesc = ucfirst(mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)));
0 ignored issues
show
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $haystack of mb_strrpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

685
        $fieldNameDesc = ucfirst(mb_substr($fieldElementName, mb_strrpos(/** @scrutinizer ignore-type */ $fieldElementName, ':'), mb_strlen($fieldElementName)));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

685
        $fieldNameDesc = ucfirst(mb_substr(/** @scrutinizer ignore-type */ $fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

685
        $fieldNameDesc = ucfirst(mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen(/** @scrutinizer ignore-type */ $fieldElementName)));
Loading history...
686
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
687
        $lcfTopicTableName = lcfirst($topicTableName);
688
689
        $ret = $pc->getPhpCodeCommentMultiLine(["Get All {$ucfTableName} By" => "{$fieldNameDesc} Id", '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t");
690
691
        $critAll = $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t");
692
        $param1 = "'{$moduleDirname}_view'";
693
        $param2 = "\$GLOBALS['xoopsUser']->getGroups()";
694
        $param3 = "\$GLOBALS['xoopsModule']->getVar('mid')";
695
        $critAll .= $xc->getXcGetItemIds($lcfTopicTableName, 'gpermHandler', $param1, $param2, $param3, "\t\t");
696
        $critAll .= $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t");
697
698
        if (false !== mb_strpos($fieldName, 'status')) {
699
            $crit = $cc->getClassCriteria('', "'{$fieldName}'", '0', "'!='", true);
700
            $critAll .= $cc->getClassAdd('crAll' . $ucfTableName, $crit, "\t\t");
701
        }
702
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
703
        $critAll .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCritAll, null, false, "\t\t");
704
705
        $critAll .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t");
706
        $params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
707
708
        $ret .= $pc->getPhpCodeFunction("getAll{$ucfTableName}By{$fieldNameDesc}Id" . $ucfTableName, $params, $critAll, 'public ', false, "\t");
709
710
        return $ret;
711
    }
712
713
    /**
714
     *  @public function getClassCriteria
715
     *
716
     *  @param $tableName
717
     *  @return string
718
     */
719
    private function getClassCriteria($tableName)
720
    {
721
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
722
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
723
        $ucfTableName = ucfirst($tableName);
724
        $ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Criteria ' . $ucfTableName, '@param       ' => "\$cr{$ucfTableName}", '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t");
725
726
        $paramsAllCriteria = "\$cr{$ucfTableName}, \$start, \$limit, \$sort, \$order";
727
728
        $critSets = $cc->getClassSetStart('cr' . $ucfTableName, 'start', "\t\t");
729
        $critSets .= $cc->getClassSetLimit('cr' . $ucfTableName, 'limit', "\t\t");
730
        $critSets .= $cc->getClassSetSort('cr' . $ucfTableName, 'sort', "\t\t");
731
        $critSets .= $cc->getClassSetOrder('cr' . $ucfTableName, 'order', "\t\t");
732
        $critSets .= $this->getSimpleString("return \$cr{$ucfTableName};", "\t\t");
733
734
        $ret .= $pc->getPhpCodeFunction("get{$ucfTableName}Criteria", $paramsAllCriteria, $critSets, 'private ', false, "\t");
735
736
        return $ret;
737
    }
738
739
    /**
740
     * @public function getClassGetTableSolenameById
741
     *
742
     * @param $moduleDirname
743
     * @param $table
744
     *
745
     * @param $fieldMain
746
     * @return string
747
     */
748
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
749
    {
750
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
751
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
752
        $tableName = $table->getVar('table_name');
753
        $tableSoleName = $table->getVar('table_solename');
754
        $ucfTableSoleName = ucfirst($tableSoleName);
755
        $ccTableSoleName = $this->getCamelCase($tableSoleName, true);
756
        $ret = $pc->getPhpCodeCommentMultiLine(['Returns the' => $ucfTableSoleName . ' from id', '' => '', '@return' => 'string'], "\t");
757
        $soleName = $xc->getXcEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t");
758
        $soleName .= $xc->getXcEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t");
759
760
        $contentIf = $xc->getXoopsHandlerLine($moduleDirname, $tableName, "\t\t\t");
761
        $contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $handler of XoopsModules\Tdmcreate\F...teXoopsCode::getXcGet(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

761
        $contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', /** @scrutinizer ignore-type */ true, false, "\t\t\t");
Loading history...
762
        $getVar = $xc->getXcGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
763
        $contentIf .= $pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
764
765
        $soleName .= $pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t");
766
        $soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
767
768
        $ret .= $pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t");
769
770
        return $ret;
771
    }
772
773
    /**
774
     * @public function render
775
     * @param null
776
     *
777
     * @return bool|string
778
     */
779
    public function render()
780
    {
781
        $tc = Tdmcreate\Helper::getInstance();
782
        $module = $this->getModule();
783
        $table = $this->getTable();
784
        $filename = $this->getFileName();
785
        $tableName = $table->getVar('table_name');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableName is dead and can be removed.
Loading history...
786
        $tableFieldName = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableFieldName is dead and can be removed.
Loading history...
787
        $tableCategory = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableCategory is dead and can be removed.
Loading history...
788
        $moduleDirname = $module->getVar('mod_dirname');
789
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
790
        $fieldInForm = [];
791
        $fieldParentId = [];
792
        $fieldElementId = [];
793
        $fieldParent = null;
794
        foreach (array_keys($fields) as $f) {
795
            $fieldName = $fields[$f]->getVar('field_name');
796
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
797
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
798
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
799
                $fieldId = $fieldName; // $fieldId = fields parameter index field
800
            }
801
            if (1 == $fields[$f]->getVar('field_main')) {
802
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
803
            }
804
            if (1 == $fields[$f]->getVar('field_parent')) {
805
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
806
            }
807
            $fieldElement = $fields[$f]->getVar('field_element');
808
809
            $fieldElements = $tc->getHandler('fieldelements')->get($fieldElement);
810
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
811
        }
812
        $content = $this->getHeaderFilesComments($module, $filename);
813
        $content .= $this->getClassObject($module, $table, $fields);
814
        $content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldName seems to be defined by a foreach iteration on line 794. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldElement seems to be defined by a foreach iteration on line 794. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
815
816
        $this->create($moduleDirname, 'class', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
817
818
        return $this->renderFile();
819
    }
820
}
821