Passed
Push — master ( 0c230a...202965 )
by Michael
02:53
created

TDMCreateXoopsCode::getXcLoadLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
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       XOOPS Project (https://xoops.org)
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: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TDMCreateXoopsCode.
27
 */
28
class TDMCreateXoopsCode
29
{
30
    /**
31
     *  @static function getInstance
32
     *  @param null
33
     */
34
35
    /**
36
     * @return TDMCreateXoopsCode
37
     */
38
    public static function getInstance()
39
    {
40
        static $instance = false;
41
        if (!$instance) {
42
            $instance = new self();
43
        }
44
45
        return $instance;
46
    }
47
48
    /**
49
     *  @public function getXcSwitch
50
     *  @param $op
51
     *  @param $cases
52
     *  @param $defaultAfterCase
53
     *  @param $default
54
     *  @param $t - Indentation
55
     *
56
     * @return string
57
     */
58
    public function getXcSwitch($op = '', $cases = [], $defaultAfterCase = false, $default = false, $t = '')
59
    {
60
        $pc = TDMCreatePhpCode::getInstance();
61
        $contentSwitch = $pc->getPhpCodeCaseSwitch($cases, $defaultAfterCase, $default, $t);
62
63
        return $pc->getPhpCodeSwitch($op, $contentSwitch, $t);
64
    }
65
66
    /**
67
     *  @public function getXcEqualsOperator
68
     *  @param $var
69
     *  @param $value
70
     *  @param $interlock
71
     *  @param $ref
72
     *  @param $t - Indentation
73
     *
74
     *  @return string
75
     */
76
    public function getXcEqualsOperator($var, $value, $interlock = null, $ref = false, $t = '')
77
    {
78
        if (false === $ref) {
79
            $ret = "{$t}{$var} {$interlock}= {$value};\n";
80
        } else {
81
            $ret = "{$t}{$var} = {$value};\n";
82
        }
83
84
        return $ret;
85
    }
86
87
    /**
88
     *  @public function getXcCPHeader
89
     *  @param null
90
     *  @return string
91
     */
92
    public function getXcCPHeader()
93
    {
94
        return "xoops_cp_header();\n";
95
    }
96
97
    /**
98
     *  @public function getXcCPFooter
99
     *  @param null
100
     *  @return string
101
     */
102
    public function getXcCPFooter()
103
    {
104
        return "xoops_cp_footer();\n";
105
    }
106
107
    /**
108
     *  @public function getXcLoad
109
     *
110
     *  @param $var
111
     *  @param $t
112
     *  @return string
113
     */
114
    public function getXcLoad($var = '', $t = '')
115
    {
116
        return "{$t}xoops_load('{$var}');\n";
117
    }
118
119
    /**
120
     *  @public function getXcLoadLanguage
121
     *
122
     *  @param $lang
123
     *  @param $t
124
     *  @param $domain
125
     *
126
     *  @return string
127
     */
128
    public function getXcLoadLanguage($lang, $t = '', $domain = '')
129
    {
130
        if ('' === $domain) {
131
            return "{$t}xoops_loadLanguage('{$lang}');\n";
132
        }
133
134
        return "{$t}xoops_loadLanguage('{$lang}', '{$domain}');\n";
135
    }
136
137
    /**
138
     *  @public function getXcAnchorFunction
139
     *  @param $anchor
140
     *  @param $name
141
     *  @param $vars
142
     *  @param $close
143
     *
144
     *  @return string
145
     */
146
    public function getXcAnchorFunction($anchor, $name, $vars, $close = false)
147
    {
148
        $semicolon = false !== $close ? ';' : '';
149
150
        return "\${$anchor}->{$name}({$vars}){$semicolon}";
151
    }
152
153
    /**
154
     *  @public function getXcSetVar
155
     *  @param $tableName
156
     *  @param $fieldName
157
     *  @param $var
158
     * @param $t
159
     *  @return string
160
     */
161
    public function getXcSetVar($tableName, $fieldName, $var, $t = '')
162
    {
163
        return "{$t}\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
164
    }
165
166
    /**
167
     *  @public function getXcGetVar
168
     *  @param $varLeft
169
     *  @param $handle
170
     *  @param $var
171
     *  @param $isParam
172
     * @param $t
173
     *
174
     *  @return string
175
     */
176
    public function getXcGetVar($varLeft = '', $handle = '', $var = '', $isParam = false, $t = '')
177
    {
178
        if (!$isParam) {
179
            $ret = "{$t}\${$varLeft} = \${$handle}->getVar('{$var}');\n";
180
        } else {
181
            $ret = "\${$handle}->getVar('{$var}')";
182
        }
183
184
        return $ret;
185
    }
186
187
    /**
188
     *  @public function getXcGroupPermForm
189
     *  @param $varLeft
190
     *  @param $formTitle
191
     *  @param $moduleId
192
     *  @param $permName
193
     *  @param $permDesc
194
     *  @param $filename
195
     * @param $t
196
     *
197
     *  @return string
198
     */
199
    public function getXcGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '')
200
    {
201
        return "{$t}\${$varLeft} = new XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
202
    }
203
204
    /**
205
     *  @public function getXcAddItem
206
     *  @param $varLeft
207
     *  @param $paramLeft
208
     *  @param $paramRight
209
     * @param $t
210
     *
211
     *  @return string
212
     */
213
    public function getXcAddItem($varLeft = '', $paramLeft = '', $paramRight = '', $t = '')
214
    {
215
        return "{$t}\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
216
    }
217
218
    /**
219
     * @public function getXcGetGroupIds
220
     * @param string $var
221
     * @param string $anchor
222
     * @param        $param1
223
     * @param        $param2
224
     * @param        $param3
225
     * @param string $t
226
     * @return string
227
     */
228
    public function getXcGetGroupIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
229
    {
230
        return "{$t}\${$var} = \${$anchor}->getGroupIds({$param1}, {$param2}, {$param3});\n";
231
    }
232
233
    /**
234
     * @public function getXcGetItemIds
235
     * @param string $var
236
     * @param string $anchor
237
     * @param        $param1
238
     * @param        $param2
239
     * @param        $param3
240
     * @param string $t
241
     * @return string
242
     */
243
    public function getXcGetItemIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
244
    {
245
        return "{$t}\${$var} = \${$anchor}->getItemIds({$param1}, {$param2}, {$param3});\n";
246
    }
247
248
    /**
249
     * @public function getXcTextDateSelectSetVar
250
     * @param        $tableName
251
     * @param        $tableSoleName
252
     * @param        $fieldName
253
     * @param string $t
254
     * @return string
255
     */
256
    public function getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName, $t = '')
257
    {
258
        $tf = TDMCreateFile::getInstance();
259
        $rightField = $tf->getRightString($fieldName);
260
        $ucfRightFiled = ucfirst($rightField);
261
        $value = "date_create_from_format(_SHORTDATESTRING, \$_POST['{$fieldName}'])";
262
        $ret = $this->getXcEqualsOperator("\${$tableSoleName}{$ucfRightFiled}", $value, null, false, $t);
263
        $ret .= $this->getXcSetVar($tableName, $fieldName, "\${$tableSoleName}{$ucfRightFiled}->getTimestamp()", $t);
264
265
        return $ret;
266
    }
267
268
    /**
269
     *  @public function getXcCheckBoxOrRadioYNSetVar
270
     *  @param $tableName
271
     *  @param $fieldName
272
     * @param $t
273
     *  @return string
274
     */
275
    public function getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName, $t = '')
276
    {
277
        return $this->getXcSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')", $t);
278
    }
279
280
    /**
281
     *  @public function getXcMediaUploader
282
     *  @param $var
283
     *  @param $dirPath
284
     *  @param $moduleDirname
285
     * @param $t
286
     *  @return string
287
     */
288
    public function getXcMediaUploader($var, $dirPath, $moduleDirname, $t = '')
289
    {
290
        $mimetypes = $this->getXcGetConfig($moduleDirname, 'mimetypes');
291
        $maxsize = $this->getXcGetConfig($moduleDirname, 'maxsize');
292
293
        return "{$t}\${$var} = new XoopsMediaUploader({$dirPath}, 
294
													{$mimetypes}, 
295
													{$maxsize}, null, null);\n";
296
    }
297
298
    /**
299
     *  @public function getXcXoopsCaptcha
300
     *  @param $var
301
     *  @param $instance
302
     * @param $t
303
     *
304
     *  @return string
305
     */
306
    public function getXcGetInstance($var = '', $instance = '', $t = '')
307
    {
308
        return "{$t}\${$var} = {$instance}::getInstance();\n";
309
    }
310
311
    /**
312
     *  @public function getXcXoopsCaptcha
313
     *  @param $t
314
     *  @return string
315
     */
316
    public function getXcXoopsCaptcha($t = '')
317
    {
318
        return "{$t}\$xoopsCaptcha = XoopsCaptcha::getInstance();\n";
319
    }
320
321
    /**
322
     *  @public function getXcXoopsImgListArray
323
     *  @param $return
324
     *  @param $var
325
     *  @param $t
326
     *
327
     *  @return string
328
     */
329
    public function getXcXoopsImgListArray($return, $var, $t = '')
330
    {
331
        return "{$t}\${$return} = XoopsLists::getImgListAsArray( {$var} );\n";
332
    }
333
334
    /**
335
     *  @public function getXcGetConfig
336
     *  @param $moduleDirname
337
     *  @param $name
338
     *  @return string
339
     */
340
    public function getXcGetConfig($moduleDirname, $name)
341
    {
342
        return "\${$moduleDirname}->getConfig('{$name}')";
343
    }
344
345
    /**
346
     *  @public function getXcIdGetVar
347
     *  @param $lpFieldName
348
     * @param $t
349
     *  @return string
350
     */
351
    public function getXcIdGetVar($lpFieldName, $t = '')
352
    {
353
        return "{$t}\${$lpFieldName}['id'] = \$i;\n";
354
    }
355
356
    /**
357
     *  @public function getXcGetVarAll
358
     *  @param $lpFieldName
359
     *  @param $rpFieldName
360
     *  @param $tableName
361
     *  @param $fieldName
362
     * @param $t
363
     *  @return string
364
     */
365
    public function getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
366
    {
367
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
368
    }
369
370
    /**
371
     * @public function getXoopsHandlerInstance
372
     * @param        $moduleDirname
373
     *
374
     * @param string $t
375
     * @return string
376
     */
377
    public function getXoopsHandlerInstance($moduleDirname, $t = '')
378
    {
379
        $ucfModuleDirname = ucfirst($moduleDirname);
380
        $ret = "{$t}// Get instance of module\n";
381
        $ret .= "{$t}\${$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();\n";
382
383
        return $ret;
384
    }
385
386
    /**
387
     * @public function getXoopsHandlerLine
388
     * @param $moduleDirname
389
     * @param $tableName
390
     * @param $t
391
     * @return string
392
     */
393
    public function getXoopsHandlerLine($moduleDirname, $tableName, $t = '')
394
    {
395
        return "{$t}\${$tableName}Handler = \${$moduleDirname}->getHandler('{$tableName}');\n";
396
    }
397
398
    /**
399
     *  @public function getXoopsClearHandler
400
     *  @param $left
401
     *  @param $anchor
402
     *  @param $var
403
     * @param $t
404
     *
405
     *  @return string
406
     */
407
    public function getXoopsClearHandler($left, $anchor, $var, $t = '')
408
    {
409
        return "{$t}\${$left}Handler = \${$anchor}->getHandler('{$var}');\n";
410
    }
411
412
    /**
413
     * @public function getXoopsFormSelectExtraOptions
414
     * @param string $varSelect
415
     * @param string $caption
416
     * @param string $var
417
     * @param array  $options
418
     * @param bool   $setExtra
419
     *
420
     * @param string $t
421
     * @return string
422
     */
423
    public function getXoopsFormSelectExtraOptions($varSelect = '', $caption = '', $var = '', $options = [], $setExtra = true, $t = '')
424
    {
425
        $ret = "{$t}\${$varSelect} = new XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
426
        if (false !== $setExtra) {
427
            $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n";
428
        }
429
        foreach ($options as $key => $value) {
430
            $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n";
431
        }
432
433
        return $ret;
434
    }
435
436
    /**
437
     *  @public function getXcUnameFromId
438
     * @param        $left
439
     * @param        $value
440
     * @param string $t
441
     *
442
     * @return string
443
     */
444
    public function getXcUnameFromId($left, $value, $t = '')
445
    {
446
        return "{$t}\${$left} = XoopsUser::getUnameFromId({$value});\n";
447
    }
448
449
    /**
450
     *  @public function getXcFormatTimeStamp
451
     * @param        $left
452
     * @param        $value
453
     * @param string $format
454
     * @param string $t
455
     * @return string
456
     */
457
    public function getXcFormatTimeStamp($left, $value, $format = 's', $t = '')
458
    {
459
        return "{$t}\${$left} = formatTimeStamp({$value}, '{$format}');\n";
460
    }
461
462
    /**
463
     * @public function getXcTopicGetVar
464
     * @param        $lpFieldName
465
     * @param        $rpFieldName
466
     * @param        $tableName
467
     * @param        $tableNameTopic
468
     * @param        $fieldNameParent
469
     * @param        $fieldNameTopic
470
     * @param string $t
471
     * @return string
472
     */
473
    public function getXcTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
474
    {
475
        $pTopic = TDMCreatePhpCode::getInstance();
476
        $ret = $pTopic->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
477
        $fieldParent = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
478
        $ret .= $this->getXcGet($rpFieldName, $fieldParent, '', $tableNameTopic . 'Handler', false, $t);
479
        $ret .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
480
481
        return $ret;
482
    }
483
484
    /**
485
     * @public function getXcParentTopicGetVar
486
     * @param        $moduleDirname
487
     * @param        $lpFieldName
488
     * @param        $rpFieldName
489
     * @param        $tableName
490
     * @param        $tableSoleNameTopic
491
     * @param        $tableNameTopic
492
     * @param        $fieldNameParent
493
     * @param string $t
494
     * @return string
495
     */
496
    public function getXcParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent, $t = '')
497
    {
498
        $pParentTopic = TDMCreatePhpCode::getInstance();
499
        $parentTopic = $pParentTopic->getPhpCodeCommentLine('Get', $tableNameTopic . ' Handler', $t . "\t");
500
        $parentTopic .= $this->getXoopsHandlerLine($moduleDirname, $tableNameTopic, $t . "\t");
501
        $elseGroups = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
502
        $ret = $pParentTopic->getPhpCodeConditions("!isset(\${$tableNameTopic}Handler", '', '', $parentTopic, $elseGroups);
503
        $ret .= $this->getXcGetVarFromID("\${$lpFieldName}['{$rpFieldName}']", $tableNameTopic, $tableSoleNameTopic, $tableName, $fieldNameParent, $t);
504
505
        return $ret;
506
    }
507
508
    /**
509
     * @public function getXcGetVarFromID
510
     * @param        $left
511
     * @param        $anchor
512
     * @param        $var
513
     * @param        $tableName
514
     * @param        $fieldName
515
     * @param string $t
516
     * @return string
517
     */
518
    public function getXcGetVarFromID($left, $anchor, $var, $tableName, $fieldName, $t = '')
519
    {
520
        $pVarFromID = TDMCreatePhpCode::getInstance();
521
        $ret = $pVarFromID->getPhpCodeCommentLine('Get Var', $fieldName, $t);
522
        $getVarFromID = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, '');
523
        $rightGet = $this->getXcAnchorFunction($anchor . 'Handler', 'get' . $var . 'FromId', $getVarFromID);
524
        $ret .= $this->getXcEqualsOperator($left, $rightGet, null, false, $t);
525
526
        return $ret;
527
    }
528
529
    /**
530
     * @public function getXcUploadImageGetVar
531
     * @param        $lpFieldName
532
     * @param        $rpFieldName
533
     * @param        $tableName
534
     * @param        $fieldName
535
     * @param string $t
536
     * @return string
537
     */
538
    public function getXcUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
539
    {
540
        $pUploadImage = TDMCreatePhpCode::getInstance();
541
        $ret = $pUploadImage->getPhpCodeCommentLine('Get Var', $fieldName, $t);
542
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
543
        $ret .= $pUploadImage->getPhpCodeTernaryOperator("{$lpFieldName}['{$rpFieldName}']", "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
544
545
        return $ret;
546
    }
547
548
    /**
549
     *  @public function getXcUrlFileGetVar
550
     *  @param $lpFieldName
551
     *  @param $rpFieldName
552
     *  @param $tableName
553
     *  @param $fieldName
554
     *  @return string
555
     */
556
    public function getXcUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
557
    {
558
        return $this->getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
559
    }
560
561
    /**
562
     * @public function getXcTextAreaGetVar
563
     * @param        $lpFieldName
564
     * @param        $rpFieldName
565
     * @param        $tableName
566
     * @param        $fieldName
567
     * @param string $t
568
     * @return string
569
     */
570
    public function getXcTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
571
    {
572
        $phpCodeTextArea = TDMCreatePhpCode::getInstance();
573
        $getVar = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, '');
574
575
        return "{$t}" . $phpCodeTextArea->getPhpCodeStripTags("{$lpFieldName}['{$rpFieldName}']", $getVar, false, $t);
576
    }
577
578
    /**
579
     * @public function getXcSelectUserGetVar
580
     * @param        $lpFieldName
581
     * @param        $rpFieldName
582
     * @param        $tableName
583
     * @param        $fieldName
584
     * @param string $t
585
     * @return string
586
     */
587
    public function getXcSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
588
    {
589
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
590
    }
591
592
    /**
593
     * @public function getXcTextDateSelectGetVar
594
     * @param        $lpFieldName
595
     * @param        $rpFieldName
596
     * @param        $tableName
597
     * @param        $fieldName
598
     * @param string $t
599
     * @return string
600
     */
601
    public function getXcTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
602
    {
603
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
604
    }
605
606
    /**
607
     * @public function getXcUserHeader
608
     * @param        $moduleDirname
609
     * @param        $tableName
610
     * @param string $t
611
     * @return string
612
     */
613
    public function getXcXoopsOptionTemplateMain($moduleDirname, $tableName, $t = '')
614
    {
615
        return "{$t}\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
616
    }
617
618
    /**
619
     *  @public function getXcUserHeader
620
     *  @param $moduleDirname
621
     *  @param $tableName
622
     *  @return string
623
     */
624
    public function getXcUserHeader($moduleDirname, $tableName)
625
    {
626
        $phpCodeUserHeader = TDMCreatePhpCode::getInstance();
627
        $ret = $phpCodeUserHeader->getPhpCodeIncludeDir('__DIR__', 'header');
628
        $ret .= $this->getXcXoopsOptionTemplateMain($moduleDirname, $tableName);
629
        $ret .= $phpCodeUserHeader->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
630
631
        return $ret;
632
    }
633
634
    /**
635
     *  @public function getXcPermissionsHeader
636
     *  @param null
637
     * @return string
638
     */
639
    public function getXcPermissionsHeader()
640
    {
641
        $phpCodePHeader = TDMCreatePhpCode::getInstance();
642
        $ret = $phpCodePHeader->getPhpCodeCommentLine('Permission');
643
        $ret .= $phpCodePHeader->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
644
        $ret .= $this->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", true);
645
        $groups = $this->getXcEqualsOperator('$groups', '$xoopsUser->getGroups()');
646
        $elseGroups = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
647
        $ret .= $phpCodePHeader->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
648
649
        return $ret;
650
    }
651
652
    /**
653
     *  @public function getXcGetFieldId
654
     *
655
     *  @param $fields
656
     *
657
     *  @return string
658
     */
659
    public function getXcGetFieldId($fields)
660
    {
661
        $fieldId = 'id';
662
        foreach (array_keys($fields) as $f) {
663
            $fieldName = $fields[$f]->getVar('field_name');
664
            if (0 == $f) {
665
                $fieldId = $fieldName;
666
            }
667
        }
668
669
        return $fieldId;
670
    }
671
672
    /**
673
     *  @public function getXcGetFieldName
674
     *
675
     *  @param $fields
676
     *
677
     *  @return string
678
     */
679
    public function getXcGetFieldName($fields)
680
    {
681
        $fieldName = '';
682
        foreach (array_keys($fields) as $f) {
683
            $fieldName = $fields[$f]->getVar('field_name');
684
        }
685
686
        return $fieldName;
687
    }
688
689
    /**
690
     *  @public function getXcGetFieldParentId
691
     *
692
     *  @param $fields
693
     *
694
     *  @return string
695
     */
696
    public function getXcGetFieldParentId($fields)
697
    {
698
        $fieldPid = 'pid';
699
        foreach (array_keys($fields) as $f) {
700
            $fieldName = $fields[$f]->getVar('field_name');
701
            if (1 == $fields[$f]->getVar('field_parent')) {
702
                $fieldPid = $fieldName;
703
            }
704
        }
705
706
        return $fieldPid;
707
    }
708
709
    /**
710
     * @public function getXcUserSaveElements
711
     *
712
     * @param $moduleDirname
713
     * @param $tableName
714
     * @param $tableSoleName
715
     * @param $fields
716
     * @return string
717
     */
718
    public function getXcUserSaveElements($moduleDirname, $tableName, $tableSoleName, $fields)
719
    {
720
        $axCodeUserSave = AdminXoopsCode::getInstance();
721
        $ret = '';
722
        $fieldMain = '';
723
        foreach (array_keys($fields) as $f) {
724
            $fieldName = $fields[$f]->getVar('field_name');
725
            $fieldElement = $fields[$f]->getVar('field_element');
726
            if (1 == $fields[$f]->getVar('field_main')) {
727
                $fieldMain = $fieldName;
728
            }
729
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
730
                $ret .= $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName);
731
            } elseif (13 == $fieldElement) {
732
                $ret .= $axCodeUserSave->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
733
            } elseif (14 == $fieldElement) {
734
                $ret .= $axCodeUserSave->getXcUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXcUploadFileSetVar() does not exist on AdminXoopsCode. Did you maybe mean getAxcUploadFileSetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
735
            } elseif (15 == $fieldElement) {
736
                $ret .= $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName);
737
            } else {
738
                $ret .= $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
739
            }
740
        }
741
742
        return $ret;
743
    }
744
745
    /**
746
     * @public function getXcXoopsRequest
747
     * @param string $left
748
     * @param string $var1
749
     * @param string $var2
750
     * @param string $type
751
     * @param bool   $metod
752
     * @param string $t
753
     * @return string
754
     */
755
    public function getXcXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false, $t = '')
756
    {
757
        $ret = '';
758
        $intVars = ('' != $var2) ? "'{$var1}', {$var2}" : "'{$var1}'";
759
        if ('String' === $type) {
760
            $ret .= "{$t}\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
761
        } elseif ('Int' === $type) {
762
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars});\n";
763
        } elseif ('Int' === $type && false !== $metod) {
764
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars}, '{$metod}');\n";
765
        }
766
767
        return $ret;
768
    }
769
770
    /**
771
     * @public function getXcTplAssign
772
     *
773
     * @param        $tplString
774
     * @param        $phpRender
775
     * @param bool   $leftIsString
776
     *
777
     * @param string $t
778
     * @return string
779
     */
780
    public function getXcTplAssign($tplString, $phpRender, $leftIsString = true, $t = '')
781
    {
782
        $assign = "{$t}\$GLOBALS['xoopsTpl']->assign(";
783
        if (false === $leftIsString) {
784
            $ret = $assign . "{$tplString}, {$phpRender});\n";
785
        } else {
786
            $ret = $assign . "'{$tplString}', {$phpRender});\n";
787
        }
788
789
        return $ret;
790
    }
791
792
    /**
793
     * @public function getXcXoopsTplAppend
794
     *
795
     * @param        $tplString
796
     * @param        $phpRender
797
     *
798
     * @param string $t
799
     * @return string
800
     */
801
    public function getXcXoopsTplAppend($tplString, $phpRender, $t = '')
802
    {
803
        return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
804
    }
805
806
    /**
807
     * @public function getXcXoopsTplAppendByRef
808
     *
809
     * @param        $tplString
810
     * @param        $phpRender
811
     *
812
     * @param string $t
813
     * @return string
814
     */
815
    public function getXcXoopsTplAppendByRef($tplString, $phpRender, $t = '')
816
    {
817
        return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
818
    }
819
820
    /**
821
     * @public function getXcPath
822
     *
823
     * @param        $directory
824
     * @param        $filename
825
     * @param bool   $isParam
826
     *
827
     * @param string $t
828
     * @return string
829
     */
830
    public function getXcPath($directory, $filename, $isParam = false, $t = '')
831
    {
832
        if (!$isParam) {
833
            $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
834
        } else {
835
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
836
        }
837
838
        return $ret;
839
    }
840
841
    /**
842
     * @public function getXcTplDisplay
843
     *
844
     * @param string $displayTpl
845
     * @param string $t
846
     * @param bool   $usedoublequotes
847
     * @return string
848
     */
849
    public function getXcTplDisplay($displayTpl = '{$templateMain}', $t = '', $usedoublequotes = true)
850
    {
851
        if ($usedoublequotes) {
852
            return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n";
853
        }
854
855
        return "{$t}\$GLOBALS['xoopsTpl']->display('db:" . $displayTpl . "');\n";
856
    }
857
858
    /**
859
     * @public function getXcGetInfo
860
     *
861
     * @param        $left
862
     * @param        $string
863
     * @param bool   $isParam
864
     *
865
     * @param string $t
866
     * @return string
867
     */
868
    public function getXcGetInfo($left, $string, $isParam = false, $t = '')
869
    {
870
        if (!$isParam) {
871
            $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
872
        } else {
873
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
874
        }
875
876
        return $ret;
877
    }
878
879
    /**
880
     * @public function getXcAddRight
881
     *
882
     * @param        $anchor
883
     * @param string $permString
884
     * @param string $var
885
     * @param string $groups
886
     * @param string $mid
887
     * @param bool   $isParam
888
     *
889
     * @param string $t
890
     * @return string
891
     */
892
    public function getXcAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
893
    {
894
        if (!$isParam) {
895
            $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n";
896
        } else {
897
            $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})";
898
        }
899
900
        return $ret;
901
    }
902
903
    /**
904
     * @public function getXcCheckRight
905
     *
906
     * @param        $anchor
907
     * @param string $permString
908
     * @param string $var
909
     * @param string $groups
910
     * @param string $mid
911
     * @param bool   $isParam
912
     *
913
     * @param string $t
914
     * @return string
915
     */
916
    public function getXcCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
917
    {
918
        if (!$isParam) {
919
            $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n";
920
        } else {
921
            $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})";
922
        }
923
924
        return $ret;
925
    }
926
927
    /**
928
     * @public function getXcObjHandlerCreate
929
     *
930
     * @param        $tableName
931
     *
932
     * @param string $t
933
     * @return string
934
     */
935
    public function getXcObjHandlerCreate($tableName, $t = '')
936
    {
937
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->create();\n";
938
    }
939
940
    /**
941
     * @public function getXcObjHandlerCount
942
     *
943
     * @param        $tableName
944
     *
945
     * @param string $t
946
     * @return string
947
     */
948
    public function getXcObjHandlerCount($tableName, $t = '')
949
    {
950
        $ucfTableName = ucfirst($tableName);
951
        $ret = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
952
953
        return $ret;
954
    }
955
956
    /**
957
     *  @public function getXcClearCount
958
     * @param  $left
959
     *  @param $anchor
960
     *  @param  $params
961
     *  @param $t
962
     *
963
     *  @return string
964
     */
965
    public function getXcClearHandlerCount($left, $anchor = '', $params = '', $t = '')
966
    {
967
        $ret = "{$t}\${$left} = \${$anchor}Handler->getCount({$params});\n";
968
969
        return $ret;
970
    }
971
972
    /**
973
     * @public function getXcObjHandlerAll
974
     *
975
     * @param        $tableName
976
     * @param string $fieldMain
977
     * @param string $start
978
     * @param string $limit
979
     *
980
     * @param string $t
981
     * @return string
982
     */
983
    public function getXcObjHandlerAll($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '')
984
    {
985
        $ucfTableName = ucfirst($tableName);
986
        $startLimit = ('0' != $limit) ? "{$start}, {$limit}" : '0';
987
        $params = ('' != $fieldMain) ? "{$startLimit}, '{$fieldMain}'" : $startLimit;
988
        $ret = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n";
989
990
        return $ret;
991
    }
992
993
    /**
994
     * @public function getXcClearHandlerAll
995
     * @param        $left
996
     * @param string $anchor
997
     * @param string $params
998
     * @param string $t
999
     * @return string
1000
     */
1001
    public function getXcClearHandlerAll($left, $anchor = '', $params = '', $t = '')
1002
    {
1003
        $ret = "{$t}\${$left} = \${$anchor}Handler->getAll({$params});\n";
1004
1005
        return $ret;
1006
    }
1007
1008
    /**
1009
     * @public function getXcGetValues
1010
     *
1011
     * @param        $tableName
1012
     * @param        $tableSoleName
1013
     *
1014
     * @param string $index
1015
     * @param bool   $noArray
1016
     * @param string $t
1017
     * @return string
1018
     */
1019
    public function getXcGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '')
1020
    {
1021
        $index = '' !== $index ? $index : 'i';
1022
        $ucfTableName = ucfirst($tableName);
1023
        if (!$noArray) {
1024
            $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
1025
        } else {
1026
            $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
1027
        }
1028
1029
        return $ret;
1030
    }
1031
1032
    /**
1033
     * @public function getXcSetVarsObjects
1034
     *
1035
     * @param $moduleDirname
1036
     * @param $tableName
1037
     * @param $tableSoleName
1038
     * @param $fields
1039
     * @return string
1040
     */
1041
    public function getXcSetVarsObjects($moduleDirname, $tableName, $tableSoleName, $fields)
1042
    {
1043
        $axCode = AdminXoopsCode::getInstance();
1044
        $ret = '';
1045
        $fieldMain = '';
1046
        foreach (array_keys($fields) as $f) {
1047
            $fieldName = $fields[$f]->getVar('field_name');
1048
            $fieldElement = $fields[$f]->getVar('field_element');
1049
            if (1 == $fields[$f]->getVar('field_main')) {
1050
                $fieldMain = $fieldName;
1051
            }
1052
            if ($f > 0) { // If we want to hide field id
1053
                switch ($fieldElement) {
1054
                    case 5:
1055
                    case 6:
1056
                        $ret .= $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1057
                        break;
1058
                    case 11:
1059
                        $ret .= $axCode->getAxcImageListSetVar($moduleDirname, $tableName, $fieldName);
1060
                        break;
1061
                    case 12:
1062
                        $ret .= $axCode->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName, true);
1063
                        break;
1064
                    case 13:
1065
                        $ret .= $axCode->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
1066
                        break;
1067
                    case 14:
1068
                        $ret .= $axCode->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName);
1069
                        break;
1070
                    case 15:
1071
                        $ret .= $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName);
1072
                        break;
1073
                    default:
1074
                        $ret .= $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1075
                        break;
1076
                }
1077
            }
1078
        }
1079
1080
        return $ret;
1081
    }
1082
1083
    /**
1084
     * @public function getXcSecurity
1085
     *
1086
     * @param        $tableName
1087
     *
1088
     * @param string $t
1089
     * @return string
1090
     */
1091
    public function getXcSecurity($tableName, $t = '')
1092
    {
1093
        $phpCodeSecurity = TDMCreatePhpCode::getInstance();
1094
        $securityError = $this->getXcSecurityErrors();
1095
        $implode = $phpCodeSecurity->getPhpCodeImplode(',', $securityError);
1096
        $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, $t);
0 ignored issues
show
Documentation introduced by
$t is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1097
        $securityCheck = $this->getXcSecurityCheck();
1098
1099
        return $phpCodeSecurity->getPhpCodeConditions('!' . $securityCheck, '', '', $content, $t);
1100
    }
1101
1102
    /**
1103
     * @public function getXcInsertData
1104
     * @param        $tableName
1105
     * @param        $language
1106
     * @param string $t
1107
     * @return string
1108
     */
1109
    public function getXcInsertData($tableName, $language, $t = '')
1110
    {
1111
        $phpCodeInsertData = TDMCreatePhpCode::getInstance();
1112
        $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
1113
        $handlerInsert = $this->getXcHandler($tableName, $tableName, false, true, false, 'Obj');
1114
1115
        return $phpCodeInsertData->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
1116
    }
1117
1118
    /**
1119
     * @public function getXcRedirectHeader
1120
     * @param        $directory
1121
     * @param        $options
1122
     * @param        $numb
1123
     * @param        $var
1124
     * @param bool   $isString
1125
     *
1126
     * @param string $t
1127
     * @return string
1128
     */
1129
    public function getXcRedirectHeader($directory, $options, $numb, $var, $isString = true, $t = '')
1130
    {
1131
        $ret = '';
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1132
        if (!$isString) {
1133
            $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n";
1134
        } else {
1135
            $ret = "{$t}redirect_header('{$directory}.php{$options}', {$numb}, {$var});\n";
1136
        }
1137
1138
        return $ret;
1139
    }
1140
1141
    /**
1142
     * @public function getXcXoopsConfirm
1143
     * @param        $tableName
1144
     * @param        $language
1145
     * @param        $fieldId
1146
     * @param        $fieldMain
1147
     * @param string $options
1148
     *
1149
     * @param string $t
1150
     * @return string
1151
     */
1152
    public function getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1153
    {
1154
        $stuOptions = mb_strtoupper($options);
1155
        $ccFieldId = TDMCreateFile::getInstance()->getCamelCase($fieldId, false, true);
1156
        $phpXoopsConfirm = TDMCreatePhpCode::getInstance();
1157
        $array = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')";
1158
        $server = $phpXoopsConfirm->getPhpCodeGlobalsVariables('REQUEST_URI', 'SERVER');
1159
        $getVar = $this->getXcGetVar('', $tableName . 'Obj', $fieldMain, true, '');
1160
        $sprintf = $phpXoopsConfirm->getPhpCodeSprintf($language . 'FORM_SURE_' . $stuOptions, $getVar);
1161
        $ret = "{$t}xoops_confirm({$array}, {$server}, {$sprintf});\n";
1162
1163
        return $ret;
1164
    }
1165
1166
    /**
1167
     * @public function getXcAddStylesheet
1168
     * @param string $style
1169
     *
1170
     * @param string $t
1171
     * @return string
1172
     */
1173
    public function getXcAddStylesheet($style = 'style', $t = '')
1174
    {
1175
        return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1176
    }
1177
1178
    /**
1179
     *  @public function getXcSecurityCheck
1180
     *  @param $denial
1181
     *  @return bool
1182
     */
1183
    public function getXcSecurityCheck($denial = '')
1184
    {
1185
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
1186
    }
1187
1188
    /**
1189
     *  @public function getXcSecurityErrors
1190
     *  @param null
1191
     *  @return string
1192
     */
1193
    public function getXcSecurityErrors()
1194
    {
1195
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1196
    }
1197
1198
    /**
1199
     * @public function getXcHtmlErrors
1200
     *
1201
     * @param        $tableName
1202
     * @param bool   $isParam
1203
     * @param string $obj
1204
     *
1205
     * @param string $t
1206
     * @return string
1207
     */
1208
    public function getXcHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1209
    {
1210
        $ret = '';
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1211
        if ($isParam) {
1212
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1213
        } else {
1214
            $ret = "{$t}\${$tableName}{$obj} = \${$tableName}->getHtmlErrors();";
1215
        }
1216
1217
        return $ret;
1218
    }
1219
1220
    /**
1221
     * @public function getXcObjHandlerCount
1222
     *
1223
     * @param        $left
1224
     * @param        $tableName
1225
     * @param string $obj
1226
     *
1227
     * @param string $t
1228
     * @return string
1229
     */
1230
    public function getXcGetForm($left, $tableName, $obj = '', $t = '')
1231
    {
1232
        $ucfTableName = ucfirst($tableName);
1233
1234
        return "{$t}\${$left} = \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1235
    }
1236
1237
    /**
1238
     * @public function getXcGet
1239
     *
1240
     * @param        $left
1241
     * @param        $var
1242
     * @param string $obj
1243
     * @param string $handler
1244
     * @param bool   $isParam
1245
     *
1246
     * @param string $t
1247
     * @return string
1248
     */
1249
    public function getXcGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '')
1250
    {
1251
        $ret = '';
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1252
        if ($isParam) {
1253
            $ret = "\${$left}{$handler}->get(\${$var})";
1254
        } else {
1255
            $ret = "{$t}\${$left}{$obj} = \${$handler}->get(\${$var});\n";
1256
        }
1257
1258
        return $ret;
1259
    }
1260
1261
    /**
1262
     *  @public function getXcHandler
1263
     *
1264
     *  @param $left
1265
     *  @param $var
1266
     *  @param $obj
1267
     *  @param $handler
1268
     *
1269
     *  @return string
1270
     */
1271
    public function getXcInsert($left, $var, $obj = '', $handler = 'Handler')
1272
    {
1273
        return "\${$left}{$handler}->insert(\${$var}{$obj})";
1274
    }
1275
1276
    /**
1277
     * @public   function getXcDelete
1278
     *
1279
     * @param        $left
1280
     * @param        $var
1281
     * @param string $obj
1282
     * @param string $handler
1283
     * @return string
1284
     */
1285
    public function getXcDelete($left, $var, $obj = '', $handler = 'Handler')
1286
    {
1287
        return "\${$left}{$handler}->delete(\${$var}{$obj})";
1288
    }
1289
1290
    /**
1291
     * @public function getXcHandler
1292
     *
1293
     * @param        $left
1294
     * @param        $var
1295
     *
1296
     * @param bool   $get
1297
     * @param bool   $insert
1298
     * @param bool   $delete
1299
     * @param string $obj
1300
     * @param string $t
1301
     * @return string
1302
     */
1303
    public function getXcHandler($left, $var, $get = false, $insert = false, $delete = false, $obj = '', $t = '')
1304
    {
1305
        $ret = '';
1306
        if ($get) {
1307
            $ret = "{$t}\${$left}Handler->get(\${$var});";
1308
        } elseif ($insert && ('' != $obj)) {
1309
            $ret = "{$t}\${$left}Handler->insert(\${$var}{$obj});";
1310
        } elseif ($delete && ('' != $obj)) {
1311
            $ret = "{$t}\${$left}Handler->delete(\${$var}{$obj});";
1312
        }
1313
1314
        return $ret;
1315
    }
1316
1317
    /**
1318
     * @public function getTopicGetVar
1319
     * @param        $lpFieldName
1320
     * @param        $rpFieldName
1321
     * @param        $tableName
1322
     * @param        $tableNameTopic
1323
     * @param        $fieldNameParent
1324
     * @param        $fieldNameTopic
1325
     * @param string $t
1326
     * @return string
1327
     */
1328
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
1329
    {
1330
        $ret = TDMCreatePhpCode::getInstance()->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
1331
        $paramGet = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
1332
        $ret .= $this->getXcGet($rpFieldName, $paramGet, '', $tableNameTopic . 'Handler', false, $t);
1333
        $ret .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
1334
1335
        return $ret;
1336
    }
1337
1338
    /**
1339
     * @public function getUploadImageGetVar
1340
     * @param        $lpFieldName
1341
     * @param        $rpFieldName
1342
     * @param        $tableName
1343
     * @param        $fieldName
1344
     * @param string $t
1345
     * @return string
1346
     */
1347
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
1348
    {
1349
        $pImageGetVar = TDMCreatePhpCode::getInstance();
1350
        $ret = $pImageGetVar->getPhpCodeCommentLine('Get Var', $fieldName, $t);
1351
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
1352
        $ret .= $pImageGetVar->getPhpCodeTernaryOperator('uploadImage', "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
1353
        $ret .= $this->getXcEqualsOperator("${$lpFieldName}['{$rpFieldName}']", '$uploadImage', null, false, $t);
1354
1355
        return $ret;
1356
    }
1357
1358
    /**
1359
     *  @public function getXcSaveFieldId
1360
     *
1361
     *  @param $fields
1362
     *
1363
     *  @return string
1364
     */
1365
    public function getXcSaveFieldId($fields)
1366
    {
1367
        $fieldId = '';
1368
        foreach (array_keys($fields) as $f) {
1369
            if (0 == $f) {
1370
                $fieldId = $fields[$f]->getVar('field_name');
1371
            }
1372
        }
1373
1374
        return $fieldId;
1375
    }
1376
1377
    /**
1378
     *  @public function getXcSaveFieldMain
1379
     *
1380
     *  @param $fields
1381
     *
1382
     *  @return string
1383
     */
1384
    public function getXcSaveFieldMain($fields)
1385
    {
1386
        $fieldMain = '';
1387
        foreach (array_keys($fields) as $f) {
1388
            if (1 == $fields[$f]->getVar('field_main')) {
1389
                $fieldMain = $fields[$f]->getVar('field_name');
1390
            }
1391
        }
1392
1393
        return $fieldMain;
1394
    }
1395
1396
    /**
1397
     * @public function getXcSaveElements
1398
     *
1399
     * @param        $moduleDirname
1400
     * @param        $tableName
1401
     * @param        $tableSoleName
1402
     * @param        $tableAutoincrement
1403
     * @param        $fields
1404
     *
1405
     * @param string $t
1406
     * @return string
1407
     */
1408
    public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $t = '')
1409
    {
1410
        $axCodeSaveElements = AdminXoopsCode::getInstance();
1411
        $ret = '';
1412
        $fieldMain = '';
1413
        foreach (array_keys($fields) as $f) {
1414
            $fieldName = $fields[$f]->getVar('field_name');
1415
            $fieldElement = $fields[$f]->getVar('field_element');
1416
            if (1 == $fields[$f]->getVar('field_main')) {
1417
                $fieldMain = $fieldName;
1418
            }
1419
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1420
                $ret .= $t . $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1421
            } elseif (13 == $fieldElement) {
1422
                $ret .= $axCodeSaveElements->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
1423
            } elseif (14 == $fieldElement) {
1424
                $ret .= $axCodeSaveElements->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName);
1425
            } elseif (15 == $fieldElement) {
1426
                $ret .= $t . $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName);
1427
            } else {
1428
                if ((0 != $f) && 1 == $tableAutoincrement) {
1429
                    $ret .= $t . $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1430
                } elseif ((0 == $f) && 0 == $tableAutoincrement) {
1431
                    $ret .= $t . $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1432
                }
1433
            }
1434
        }
1435
1436
        return $ret;
1437
    }
1438
1439
    /**
1440
     * @public function getXcPageNav
1441
     * @param        $tableName
1442
     *
1443
     * @param string $t
1444
     * @return string
1445
     */
1446
    public function getXcPageNav($tableName, $t = '')
1447
    {
1448
        $phpCodePageNav = TDMCreatePhpCode::getInstance();
1449
        $classXCode = ClassXoopsCode::getInstance();
1450
        $ret = $phpCodePageNav->getPhpCodeCommentLine('Display Navigation', null, $t);
1451
        $condition = $phpCodePageNav->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t");
1452
        $condition .= $classXCode->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', 'start', "'op=list&limit=' . \$limit", false, $t . "\t");
1453
        $condition .= $this->getXcTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t");
1454
        $ret .= $phpCodePageNav->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1455
1456
        return $ret;
1457
    }
1458
}
1459