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

ClassFormElements::getXoopsFormHidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: ClassFormElements.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class ClassFormElements.
27
 */
28
class ClassFormElements extends TDMCreateFile
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...
29
{
30
    /*
31
    * @var string
32
    */
33
    private $tdmcreate = null;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
35
    /*
36
    * @var mixed
37
    */
38
    private $xoopscode = null;
39
40
    /*
41
    * @var mixed
42
    */
43
    private $classcode = null;
44
45
    /**
46
     *  @public function constructor
47
     *
48
     *  @param null    
49
     */
50
    public function __construct()
51
    {
52
        parent::__construct();
53
        $this->tdmcreate = TDMCreateHelper::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateHelper::getInstance() of type object<TDMCreateHelper> is incompatible with the declared type string of property $tdmcreate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreatePhpCode::getInstance() of type object<TDMCreatePhpCode> is incompatible with the declared type string of property $phpcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
56
        $this->classcode = ClassXoopsCode::getInstance();
57
    }
58
59
    /*
60
    *  @static function &getInstance
61
    *  @param null
62
    */
63
    /**
64
     * @return ClassFormElements
65
     */
66
    public static function &getInstance()
67
    {
68
        static $instance = false;
69
        if (!$instance) {
70
            $instance = new self();
71
        }
72
73
        return $instance;
74
    }
75
76
    /*
77
    *  @public function initForm
78
    *  @param string $module
79
    *  @param string $table
80
    */
81
    /**
82
     * @param $module
83
     * @param $table
84
     */
85
    public function initForm($module, $table)
86
    {
87
        $this->setModule($module);
88
        $this->setTable($table);
89
    }
90
91
    /*
92
    *  @private function getXoopsFormText
93
    *  @param string $language
94
    *  @param string $fieldName
95
    *  @param string $required
96
    */
97
    /**
98
     * @param $language
99
     * @param $fieldName
100
     * @param $required
101
     *
102
     * @return string
103
     */
104
    private function getXoopsFormText($language, $fieldName, $fieldDefault, $required = 'false')
105
    {
106
        $ucfFieldName = $this->getCamelCase($fieldName, true);
107
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
108
        if ($fieldDefault != '') {
109
            $ret = $this->phpcode->getPhpCodeCommentLine('Form Text', $ucfFieldName);
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
110
            $ret .= $this->phpcode->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', "'{$fieldDefault}'", "\$this->getVar('{$fieldName}')");
0 ignored issues
show
Bug introduced by
The method getPhpCodeTernaryOperator cannot be called on $this->phpcode (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...
111
            $formText = $this->classcode->getClassXoopsFormText('', $language, $fieldName, 20, 150, "{$ccFieldName}", true);
112
            $ret .= $this->classcode->getClassAddElement('form', $formText.$required);
113
        } else {
114
            $ret = $this->phpcode->getPhpCodeCommentLine('Form Text', $ucfFieldName);
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
115
            $formText = $this->classcode->getClassXoopsFormText('', $language, $fieldName, 50, 255, "this->getVar('{$fieldName}')", true);
116
            $ret .= $this->classcode->getClassAddElement('form', $formText.$required);
117
        }
118
119
        return $ret;
120
    }
121
122
    /*
123
    *  @private function getXoopsFormText
124
    *  @param string $language
125
    *  @param string $fieldName
126
    *  @param string $required
127
    */
128
    /**
129
     * @param        $language
130
     * @param        $fieldName
131
     * @param string $required
132
     *
133
     * @return string
134
     */
135
    private function getXoopsFormTextArea($language, $fieldName, $required = 'false')
136
    {
137
        $ucfFieldName = $this->getCamelCase($fieldName, true);
138
        $ret = $this->phpcode->getPhpCodeCommentLine('Form Text Area', $ucfFieldName);
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
139
        $formTextArea = $this->classcode->getClassXoopsFormTextArea('', $language, $fieldName, 4, 47, true);
140
        $ret .= $this->classcode->getClassAddElement('form', $formTextArea.$required);
141
142
        return $ret;
143
    }
144
145
    /*
146
    *  @private function getXoopsFormDhtmlTextArea
147
    *  @param string $language
148
    *  @param string $moduleDirname
149
    *  @param string $fieldName
150
    *  @param string $required
151
    */
152
    /**
153
     * @param        $language
154
     * @param        $moduleDirname
155
     * @param        $fieldName
156
     * @param string $required
157
     *
158
     * @return string
159
     */
160
    private function getXoopsFormDhtmlTextArea($language, $moduleDirname, $fieldName, $required = 'false')
161
    {
162
        $rpFieldName = $this->getRightString($fieldName);
163
        $ret = $this->phpcode->getPhpCodeArray('editorConfigs');
0 ignored issues
show
Bug introduced by
The method getPhpCodeArray cannot be called on $this->phpcode (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...
164
        $configs = array('name' => "'{$fieldName}'", 'value' => "\$this->getVar('{$fieldName}', 'e')", 'rows' => 5, 'cols' => 40,
165
                        'width' => "'100%'", 'height' => "'400px'", 'editor' => "\$this->{$moduleDirname}->getConfig('{$moduleDirname}_editor_{$rpFieldName}')", );
166
        foreach ($configs as $c => $d) {
167
            $ret .= "\$editorConfigs['{$c}'] = {$d};";
168
        }
169
        $formEditor = $this->classcode->getClassXoopsFormEditor('', $language, $fieldName, 'editorConfigs', true);
170
        $ret .= $this->classcode->getClassAddElement('form', $formEditor.$required);
171
172
        return $ret;
173
    }
174
175
    /*
176
    *  @private function getXoopsFormCheckBox
177
    *  @param string $language
178
    *  @param string $fieldName
179
    *  @param string $required
180
    */
181
    /**
182
     * @param        $language
183
     * @param        $fieldName
184
     * @param string $required
185
     *
186
     * @return string
187
     */
188
    private function getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required = 'false')
189
    {
190
        $stuTableSoleName = strtoupper($tableSoleName);
191
        $ucfFieldName = $this->getCamelCase($fieldName, true);
192
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
193
        if (in_array(5, $fieldElementId) > 1) {
194
            $ret = <<<EOT
195
        // Form Check Box List Options
196
		\$checkOption          = \$this->getOptions();
197
        \$check{$ucfFieldName} = new XoopsFormCheckbox('<hr />', '{$tableSoleName}_option', \$checkOption, false);
198
        \$check{$ucfFieldName}->setDescription({$language}{$stuTableSoleName}_OPTIONS_DESC);
199
        foreach(\$this->options as \$option) {
200
            \$check{$ucfFieldName}->addOption(\$option, {$language}{$stuTableSoleName}_ . strtoupper(\$option));
201
        }
202
		\$form->addElement(\$check{$ucfFieldName}{$required} );\n
203
EOT;
204
        } else {
205
            $ret = <<<EOT
206
        // Form Check Box
207
        \${$ccFieldName} = \$this->isNew() ? 0 : \$this->getVar('{$fieldName}');
208
        \$check{$ucfFieldName} = new XoopsFormCheckBox({$language}, '{$fieldName}', \${$ccFieldName});
209
        \$check{$ucfFieldName}->addOption(1, " ");
210
        \$form->addElement( \$check{$ucfFieldName}{$required} );\n
211
EOT;
212
        }
213
214
        return $ret;
215
    }
216
217
    /*
218
    *  @private function getXoopsFormHidden
219
    *  @param string $fieldName
220
    */
221
    /**
222
     * @param $fieldName
223
     *
224
     * @return string
225
     */
226
    private function getXoopsFormHidden($fieldName)
227
    {
228
        $ucfFieldName = $this->getCamelCase($fieldName, true);
229
        $ret = $this->phpcode->getPhpCodeCommentLine('Form Hidden', $ucfFieldName);
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
230
        $formHidden = $this->classcode->getClassXoopsFormHidden('', $fieldName, $fieldName, true, true);
231
        $ret .= $this->classcode->getClassAddElement('form', $formHidden);
232
233
        return $ret;
234
    }
235
236
    /*
237
    *  @private function getXoopsFormImageList
238
    *  @param string $language
239
    *  @param string $moduleDirname
240
    *  @param string $tableName
241
    *  @param string $fieldName
242
    *  @param string $required
243
    */
244
    /**
245
     * @param        $language
246
     * @param        $moduleDirname
247
     * @param        $tableName
248
     * @param        $tableSoleName
249
     * @param        $fieldName
250
     * @param string $required
251
     *
252
     * @return string
253
     */
254
    private function getXoopsFormImageList($language, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required = 'false')
255
    {
256
        $stuTableName = strtoupper($tableName);
257
        $rpFieldName = $this->getRightString($fieldName);
258
        $stuSoleName = strtoupper($tableSoleName.'_'.$rpFieldName);
259
        $ucfFieldName = $this->getCamelCase($fieldName, true);
260
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
261
        $ret = <<<EOT
262
        // Form Frameworks Image Files
263
        \$get{$ucfFieldName} = \$this->getVar('{$fieldName}');
264
        \${$ccFieldName} = \$get{$ucfFieldName} ? \$get{$ucfFieldName} : 'blank.gif';
265
        \$imageDirectory = '/Frameworks/moduleclasses/icons/32';
266
        \$imageTray = new XoopsFormElementTray({$language}{$stuSoleName},'<br />');
267
        \$imageSelect = new XoopsFormSelect(sprintf({$language}FORM_IMAGE_PATH, ".{\$imageDirectory}/"), '{$fieldName}', \${$ccFieldName}, 5);
268
        \$imageArray = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$imageDirectory );
269
        foreach( \$imageArray as \$image1 ) {
270
            \$imageSelect->addOption("{\$image1}", \$image1);
271
        }
272
        \$imageSelect->setExtra( "onchange='showImgSelected(\"image1\", \"{$fieldName}\", \"".\$imageDirectory."\", \"\", \"".XOOPS_URL."\")'" );
273
        \$imageTray->addElement(\$imageSelect, false);
274
        \$imageTray->addElement( new XoopsFormLabel( '', "<br /><img src='".XOOPS_URL."/".\$imageDirectory."/".\${$ccFieldName}."' name='image1' id='image1' alt='' />" ) );
275
        // Form File
276
        \$fileSelectTray = new XoopsFormElementTray('','<br />');
277
        \$fileSelectTray->addElement(new XoopsFormFile({$language}FORM_IMAGE_LIST_{$stuTableName} , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')));
278
        \$fileSelectTray->addElement(new XoopsFormLabel(''));
279
        \$imageTray->addElement(\$fileSelectTray);
280
        \$form->addElement( \$imageTray{$required} );\n
281
EOT;
282
283
        return $ret;
284
    }
285
286
    /*
287
    *  @private function getXoopsFormSelectFile
288
    *  @param string $language
289
    *  @param string $moduleDirname
290
    *  @param string $fieldName
291
    *  @param string $fieldDefault
292
    *  @param string $fieldElement
293
    *  @param string $required
294
    */
295
    /**
296
     * @param        $language
297
     * @param        $moduleDirname
298
     * @param        $fieldName
299
     * @param string $required
300
     *
301
     * @return string
302
     */
303
    private function getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $required = 'false')
304
    {
305
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
306
        $ret = <<<EOT
307
        // Image Select or Upload
308
        if ( \$this->{$moduleDirname}->getConfig('useshots') ) {
309
            \${$ccFieldName} = \$this->getVar('{$fieldName}');
310
            \$uploadDirectory = '/uploads/{$moduleDirname}/images/shots';
311
            \${$moduleDirname}ShotImage = \${$fieldName} ? \${$fieldName} : 'blank.gif';
312
            //
313
            \$imageTray = new XoopsFormElementTray({$language}FORM_IMAGE,'<br />');
314
            \$imageSelect = new XoopsFormSelect(sprintf({$language}_FORM_PATH, \$uploadDirectory ), 'selected_image',\${$moduleDirname}ShotImage);
315
            \$imageArray = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$uploadDirectory );
316
            foreach( \$imageArray as \$image ) {
317
                \$imageSelect->addOption("{\$image}", \$image);
318
            }
319
            \$imageSelect->setExtra( "onchange='showImgSelected(\"image3\", \"selected_image\", \"" . \$uploadDirectory . "\", \"\", \"" . XOOPS_URL . "\")'" );
320
            \$imageTray->addElement(\$imageSelect,false);
321
            \$imageTray -> addElement( new XoopsFormLabel( '', "<br /><img src='" . XOOPS_URL . "/" . \$uploadDirectory . "/" . \${$moduleDirname}ShotImage . "' name='image3' id='image3' alt='' />" ) );
322
            \$fileSelectTray= new XoopsFormElementTray('','<br />');
323
            //if (\$permissionUpload == true) {
324
                \$fileSelectTray->addElement(new XoopsFormFile({$language}_FORM_UPLOAD , 'attachedimage', \$this->{$moduleDirname}->getConfig('maxuploadsize')){$required});
325
            //}
326
            \$imageTray->addElement(\$fileSelectTray);
327
            \$form->addElement(\$imageTray);
328
        }\n
329
EOT;
330
331
        return $ret;
332
    }
333
334
    /*
335
    *  @private function getXoopsFormUrlFile
336
    *  @param string $language
337
    *  @param string $moduleDirname
338
    *  @param string $fieldName
339
    *  @param string $fieldDefault
340
    *
341
    *  @param string $required
342
    */
343
    /**
344
     * @param   $language
345
     * @param   $moduleDirname
346
     * @param   $fieldName
347
     * @param   $fieldDefault
348
     * @param $required
349
     *
350
     * @return string
351
     */
352
    private function getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $required = 'false')
353
    {
354
        $ret = <<<EOT
355
        // Form Url Text File
356
        \$formUrlFile = new XoopsFormElementTray({$language}FORM_FILE,'<br /><br />');
357
        \$formUrl     = \$this->isNew() ? '{$fieldDefault}' : \$this->getVar('{$fieldName}');
358
        \$formText    = new XoopsFormText({$language}FORM_TEXT, '{$fieldName}', 75, 255, \$formUrl);
359
        \$formUrlFile->addElement(\$formText{$required} );
360
        \$formUrlFile->addElement(new XoopsFormFile({$language}FORM_UPLOAD , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')){$required});
361
        \$form->addElement(\$formUrlFile);\n
362
EOT;
363
364
        return $ret;
365
    }
366
367
    /*
368
    *  @private function getXoopsFormUploadImage
369
    *  @param string $language
370
    *  @param string $moduleDirname
371
    *  @param string $tableName
372
    *  @param string $required
373
    */
374
    /**
375
     * @param        $language
376
     * @param        $moduleDirname
377
     * @param        $tableName
378
     * @param string $required
379
     *
380
     * @return string
381
     */
382
    private function getXoopsFormUploadImage($language, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required = 'false')
383
    {
384
        $stuTableName = strtoupper($tableName);
385
        $stuSoleName = strtoupper($tableSoleName);
386
        $ucfFieldName = $this->getCamelCase($fieldName, true);
387
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
388
        $ret = <<<EOT
389
        // Form Upload Image
390
        \$get{$ucfFieldName} = \$this->getVar('{$fieldName}');
391
        \${$ccFieldName} = \$get{$ucfFieldName} ? \$get{$ucfFieldName} : 'blank.gif';
392
        \$imageDirectory = '/uploads/{$moduleDirname}/images/{$tableName}';
393
        //
394
        \$imageTray   = new XoopsFormElementTray({$language}{$stuSoleName}_IMAGE,'<br />');
395
        \$imageSelect = new XoopsFormSelect(sprintf({$language}FORM_IMAGE_PATH, ".{\$imageDirectory}/"), '{$fieldName}', \${$ccFieldName}, 5);
396
        \$imageArray  = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$imageDirectory );
397
        foreach( \$imageArray as \$image ) {
398
            \$imageSelect->addOption("{\$image}", \$image);
399
        }
400
        \$imageSelect->setExtra( "onchange='showImgSelected(\"image2\", \"{$fieldName}\", \"".\$imageDirectory."\", \"\", \"".XOOPS_URL."\")'" );
401
        \$imageTray->addElement(\$imageSelect, false);
402
        \$imageTray->addElement( new XoopsFormLabel( '', "<br /><img src='".XOOPS_URL."/".\$imageDirectory."/".\${$ccFieldName}."' name='image2' id='image2' alt='' />" ) );
403
        // Form File
404
        \$fileSelectTray = new XoopsFormElementTray('','<br />');
405
        \$fileSelectTray->addElement(new XoopsFormFile({$language}FORM_UPLOAD_IMAGE_{$stuTableName} , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')));
406
        \$fileSelectTray->addElement(new XoopsFormLabel(''));
407
        \$imageTray->addElement(\$fileSelectTray);
408
        \$form->addElement( \$imageTray{$required} );\n
409
EOT;
410
411
        return $ret;
412
    }
413
414
    /*
415
    *  @private function getXoopsFormUploadFile
416
    *  @param string $language
417
    *  @param string $moduleDirname
418
    *  @param string $tableName
419
    *  @param string $fieldName
420
    *  @param string $required
421
    */
422
    /**
423
     * @param        $language
424
     * @param        $moduleDirname
425
     * @param        $tableName
426
     * @param        $fieldName
427
     * @param string $required
428
     *
429
     * @return string
430
     */
431
    private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
432
    {
433
        $stuTableName = strtoupper($tableName);
434
        $ret = <<<EOT
435
        // Form file
436
        \$form->addElement( new XoopsFormFile({$language}FORM_UPLOAD_FILE_{$stuTableName}, '{$fieldName}', \$this->{$moduleDirname}->getConfig('maxsize')){$required} );\n
437
EOT;
438
439
        return $ret;
440
    }
441
442
    /*
443
    *  @private function getXoopsFormColorPicker
444
    *  @param string $language
445
    *  @param string $fieldName
446
    *  @param string $required
447
    */
448
    /**
449
     * @param        $language
450
     * @param        $moduleDirname
451
     * @param        $fieldName
452
     * @param string $required
453
     *
454
     * @return string
455
     */
456
    private function getXoopsFormColorPicker($language, $moduleDirname, $fieldName, $required = 'false')
457
    {
458
        $ret = <<<EOT
459
        // Form Color Picker
460
        \$form->addElement( new XoopsFormColorPicker({$language}, '{$fieldName}', \$this->{$moduleDirname}->getConfig('maxsize')){$required} );\n
461
EOT;
462
463
        return $ret;
464
    }
465
466
    /*
467
    *  @private function getXoopsFormSelectBox
468
    *  @param string $language
469
    *  @param string $tableName
470
    *  @param string $fieldName
471
    *  @param string $required
472
    */
473
    /**
474
     * @param $language
475
     * @param $moduleDirname
476
     * @param $tableName
477
     * @param $fieldName
478
     * @param $required
479
     *
480
     * @return string
481
     */
482
    private function getXoopsFormSelectBox($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
483
    {
484
        $ucfTableName = ucfirst($tableName);
485
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
486
        $ret = <<<EOT
487
        // {$ucfTableName} handler
488
		\${$tableName}Handler =& \$this->{$moduleDirname}->getHandler('{$tableName}');
489
		// Form Select
490
        \${$ccFieldName}Select = new XoopsFormSelect({$language}, '{$fieldName}', \$this->getVar('{$fieldName}'));
491
        \${$ccFieldName}Select->addOption('Empty');
492
        \${$ccFieldName}Select->addOptionArray(\${$tableName}Handler->getList());
493
        \$form->addElement( \${$ccFieldName}Select{$required} );\n
494
EOT;
495
496
        return $ret;
497
    }
498
499
    /*
500
    *  @private function getXoopsFormSelectUser
501
    *  @param string $language
502
    *  @param string $fieldName
503
    *  @param string $required
504
    */
505
    /**
506
     * @param        $language
507
     * @param        $fieldName
508
     * @param string $required
509
     *
510
     * @return string
511
     */
512
    private function getXoopsFormSelectUser($language, $fieldName, $required = 'false')
513
    {
514
        $ret = <<<EOT
515
        // Form Select User
516
        \$form->addElement( new XoopsFormSelectUser({$language}, '{$fieldName}', false, \$this->getVar('{$fieldName}'), 1, false){$required} );\n
517
EOT;
518
519
        return $ret;
520
    }
521
522
    /*
523
    *  @private function getXoopsFormRadioYN
524
    *  @param string $language
525
    *  @param string $fieldName
526
    *  @param string $required
527
    */
528
    /**
529
     * @param        $language
530
     * @param        $fieldName
531
     * @param string $required
532
     *
533
     * @return string
534
     */
535
    private function getXoopsFormRadioYN($language, $fieldName, $required = 'false')
536
    {
537
        $ccFieldName = $this->getCamelCase($fieldName, false, true);
538
        $ret = <<<EOT
539
        // Form Radio Yes/No
540
        \${$ccFieldName} = \$this->isNew() ? 0 : \$this->getVar('{$fieldName}');
541
        \$form->addElement( new XoopsFormRadioYN({$language}, '{$fieldName}', \${$ccFieldName}){$required} );\n
542
EOT;
543
544
        return $ret;
545
    }
546
547
    /*
548
    *  @private function getXoopsFormTextDateSelect
549
    *  @param string $language
550
    *  @param string $fieldName
551
    *  @param string $required
552
    */
553
    /**
554
     * @param        $language
555
     * @param        $fieldName
556
     * @param string $required
557
     *
558
     * @return string
559
     */
560
    private function getXoopsFormTextDateSelect($language, $fieldName, $required = 'false')
561
    {
562
        $ret = <<<EOT
563
        // Form Text Date Select
564
        \$form->addElement( new XoopsFormTextDateSelect({$language}, '{$fieldName}', '', \$this->getVar('{$fieldName}')){$required} );\n
565
EOT;
566
567
        return $ret;
568
    }
569
570
    /*
571
    *  @private function getXoopsFormTable
572
    *  @param string $language
573
    *  @param string $moduleDirname
574
    *  @param string $table
575
    *  @param string $fields
576
    *  @param string $required
577
    */
578
    /**
579
     * @param        $language
580
     * @param        $moduleDirname
581
     * @param        $tableName
582
     * @param        $fieldName
583
     * @param        $fieldElement
584
     * @param string $required
585
     *
586
     * @return string
587
     */
588
    private function getXoopsFormTable($language, $moduleDirname, $tableName, $fieldName, $fieldElement, $required = 'false')
589
    {
590
        $ucfTableName = ucfirst($tableName);
591
        $ret = '';
592
        if ($fieldElement > 15) {
593
            $fElement = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (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...
594
            $rpFieldelementName = strtolower(str_replace('Table : ', '', $fElement->getVar('fieldelement_name')));
595
            $ccFieldName = $this->getCamelCase($fieldName, false, true);
596
            $ret .= <<<EOT
597
			// Form Table {$ucfTableName}
598
			\${$rpFieldelementName}Handler =& \$this->{$moduleDirname}->getHandler('{$rpFieldelementName}');
599
			\${$ccFieldName}Select = new XoopsFormSelect({$language}, '{$fieldName}', \$this->getVar('{$fieldName}'));
600
			\${$ccFieldName}Select->addOptionArray(\${$rpFieldelementName}Handler->getList());
601
			\$form->addElement( \${$ccFieldName}Select{$required} );\n		
602
EOT;
603
        }
604
605
        return $ret;
606
    }
607
608
    /*
609
    *  @private function getXoopsFormTopic
610
    *  @param string $language
611
    *  @param string $moduleDirname
612
    *  @param string $table
613
    *  @param string $fields
614
    *  @param string $required
615
    */
616
    /**
617
     * @param        $language
618
     * @param        $moduleDirname
619
     * @param        $table
620
     * @param        $fields
621
     * @param string $required
622
     *
623
     * @return string
624
     */
625
    private function getXoopsFormTopic($language, $moduleDirname, $topicTableName, $fieldId, $fieldPid, $fieldMain, $required = 'false')
626
    {
627
        $ucfTopicTableName = ucfirst($topicTableName);
628
        $stlTopicTableName = strtolower($topicTableName);
629
        $ccFieldPid = $this->getCamelCase($fieldPid, false, true);
630
        $ret = <<<EOT
631
        // Form Topic {$ucfTopicTableName}
632
        \${$stlTopicTableName}Handler = \$this->{$moduleDirname}->getHandler('{$stlTopicTableName}');
633
        \$criteria = new CriteriaCompo();
634
        \${$stlTopicTableName}Count = \${$stlTopicTableName}Handler->getCount( \$criteria );
635
        if(\${$stlTopicTableName}Count) {
636
            include_once(XOOPS_ROOT_PATH . '/class/tree.php');
637
			\${$stlTopicTableName}All = \${$stlTopicTableName}Handler->getAll(\$criteria);
638
            \${$stlTopicTableName}Tree = new XoopsObjectTree( \${$stlTopicTableName}All, '{$fieldId}', '{$fieldPid}' );
639
            \${$ccFieldPid} = \${$stlTopicTableName}Tree->makeSelBox( '{$fieldPid}', '{$fieldMain}', '--', \$this->getVar('{$fieldPid}', 'e' ), true );
640
            \$form->addElement( new XoopsFormLabel ( {$language}, \${$ccFieldPid} ){$required} );
641
        }
642
		unset(\$criteria);\n
643
EOT;
644
645
        return $ret;
646
    }
647
648
    /*
649
    *  @private function getXoopsFormTag
650
    *  @param string $moduleDirname
651
    *  @param string $fieldId
652
    *  @param string $required
653
    */
654
    /**
655
     * @param        $moduleDirname
656
     * @param        $fieldId
657
     * @param string $required
658
     *
659
     * @return string
660
     */
661
    private function getXoopsFormTag($moduleDirname, $fieldId, $required = 'false')
662
    {
663
        $ret = <<<EOT
664
		// Use tag module
665
		\$dirTag = is_dir(XOOPS_ROOT_PATH . '/modules/tag') ? true : false;
666
        if ((\$this->{$moduleDirname}->getConfig('usetag') == 1) && \$dirTag){
667
            \$tagId = \$this->isNew() ? 0 : \$this->getVar('{$fieldId}');
668
            include_once XOOPS_ROOT_PATH.'/modules/tag/include/formtag.php';
669
            \$form->addElement(new XoopsFormTag('tag', 60, 255, \$tagId, 0){$required});
670
        }\n
671
EOT;
672
673
        return $ret;
674
    }
675
676
    /*
677
    *  @public function renderElements
678
    *  @param null
679
    */
680
    /**
681
     * @return string
682
     */
683
    public function renderElements()
684
    {
685
        $module = $this->getModule();
686
        $table = $this->getTable();
687
        $moduleDirname = $module->getVar('mod_dirname');
688
        $tableName = $table->getVar('table_name');
689
        $tableSoleName = $table->getVar('table_solename');
690
        $languageFunct = $this->getLanguage($moduleDirname, 'AM');
691
        //$language_table = $languageFunct . strtoupper($tableName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
692
        $ret = '';
693
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order ASC, field_id');
694
        $fieldId = '';
695
        $fieldIdTopic = '';
696
        $fieldPidTopic = '';
697
        $fieldMainTopic = '';
698
        $fieldElementId = array();
699
        foreach (array_keys($fields) as $f) {
700
            $fieldName = $fields[$f]->getVar('field_name');
701
            $fieldDefault = $fields[$f]->getVar('field_default');
702
            $fieldElement = $fields[$f]->getVar('field_element');
703
            $fieldParent = $fields[$f]->getVar('field_parent');
704
            $fieldInForm = $fields[$f]->getVar('field_inform');
705
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
706
                $fieldId = $fieldName;
707
            }
708
            $rpFieldName = $this->getRightString($fieldName);
709
            $language = $languageFunct.strtoupper($tableSoleName).'_'.strtoupper($rpFieldName);
710
            $required = (1 == $fields[$f]->getVar('field_required')) ? ', true' : '';
711
            //
712
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (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...
713
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
714
            //
715
            if (1 == $fieldInForm) {
716
                // Switch elements
717
                switch ($fieldElement) {
718
                    case 1:
719
                        break;
720
                    case 2:
721
                        $ret .= $this->getXoopsFormText($language, $fieldName, $fieldDefault, $required);
722
                        break;
723
                    case 3:
724
                        $ret .= $this->getXoopsFormTextArea($language, $fieldName, $required);
725
                        break;
726
                    case 4:
727
                        $ret .= $this->getXoopsFormDhtmlTextArea($language, $moduleDirname, $fieldName, $required);
728
                        break;
729
                    case 5:
730
                        $ret .= $this->getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required);
731
                        break;
732
                    case 6:
733
                        $ret .= $this->getXoopsFormRadioYN($language, $fieldName, $required);
734
                        break;
735
                    case 7:
736
                        $ret .= $this->getXoopsFormSelectBox($language, $moduleDirname, $tableName, $fieldName, $required);
737
                        break;
738
                    case 8:
739
                        $ret .= $this->getXoopsFormSelectUser($language, $fieldName, $required);
740
                        break;
741
                    case 9:
742
                        $ret .= $this->getXoopsFormColorPicker($language, $moduleDirname, $fieldName, $required);
743
                        break;
744
                    case 10:
745
                        $ret .= $this->getXoopsFormImageList($languageFunct, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required);
746
                        break;
747
                    case 11:
748
                        $ret .= $this->getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $required);
749
                        break;
750
                    case 12:
751
                        $ret .= $this->getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $fieldElement, $required);
0 ignored issues
show
Unused Code introduced by
The call to ClassFormElements::getXoopsFormUrlFile() has too many arguments starting with $required.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
752
                        break;
753
                    case 13:
754
                        $ret .= $this->getXoopsFormUploadImage($languageFunct, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required);
755
                        break;
756
                    case 14:
757
                        $ret .= $this->getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required);
758
                        break;
759
                    case 15:
760
                        $ret .= $this->getXoopsFormTextDateSelect($language, $moduleDirname, $fieldName, $required);
0 ignored issues
show
Unused Code introduced by
The call to ClassFormElements::getXoopsFormTextDateSelect() has too many arguments starting with $required.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
761
                        break;
762
                    default:
763
                        // If we use tag module
764
                        if (1 == $table->getVar('table_tag')) {
765
                            $ret .= $this->getXoopsFormTag($moduleDirname, $fieldId, $required);
766
                        }
767
                        // If we want to hide XoopsFormHidden() or field id
768
                        if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
769
                            $ret .= $this->getXoopsFormHidden($fieldName);
770
                        }
771
                        break;
772
                }
773
                if ($fieldElement > 15) {
774
                    if (1 == $table->getVar('table_category') || (1 == $fieldParent)) {
775
                        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (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...
776
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
777
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
778
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
779
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
780
                        $topicTableName = str_replace(': ', '', $fieldNameDesc);
781
                        $fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid);
782
                        foreach (array_keys($fieldsTopics) as $f) {
783
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
784
                            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
785
                                $fieldIdTopic = $fieldNameTopic;
786
                            }
787
                            if (1 == $fieldsTopics[$f]->getVar('field_parent')) {
788
                                $fieldPidTopic = $fieldNameTopic;
789
                            }
790
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
791
                                $fieldMainTopic = $fieldNameTopic;
792
                            }
793
                        }
794
                        $ret .= $this->getXoopsFormTopic($language, $moduleDirname, $topicTableName, $fieldIdTopic, $fieldPidTopic, $fieldMainTopic, $required);
795
                    } else {
796
                        $ret .= $this->getXoopsFormTable($language, $moduleDirname, $tableName, $fieldName, $fieldElement, $required);
797
                    }
798
                }
799
            }
800
        }
801
        unset($fieldElementId);
802
803
        return $ret;
804
    }
805
}
806