Passed
Pull Request — master (#144)
by Michael
03:10
created

CreateXoopsCode::getXcXoopsTplAppendByRef()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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

738
                $ret .= $axCodeUserSave->/** @scrutinizer ignore-call */ getXcUploadFileSetVar($moduleDirname, $tableName, $fieldName);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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

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

1100
        $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, /** @scrutinizer ignore-type */ $t);
Loading history...
1101
        $securityCheck = $this->getXcSecurityCheck();
1102
1103
        return $phpCodeSecurity->getPhpCodeConditions('!' . $securityCheck, '', '', $content, $t);
1104
    }
1105
1106
    /**
1107
     * @public function getXcInsertData
1108
     * @param        $tableName
1109
     * @param        $language
1110
     * @param string $t
1111
     * @return string
1112
     */
1113
    public function getXcInsertData($tableName, $language, $t = '')
1114
    {
1115
        $phpCodeInsertData = Tdmcreate\Files\CreatePhpCode::getInstance();
1116
        $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
1117
        $handlerInsert = $this->getXcHandler($tableName, $tableName, false, true, false, 'Obj');
1118
1119
        return $phpCodeInsertData->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
1120
    }
1121
1122
    /**
1123
     * @public function getXcRedirectHeader
1124
     * @param        $directory
1125
     * @param        $options
1126
     * @param        $numb
1127
     * @param        $var
1128
     * @param bool   $isString
1129
     *
1130
     * @param string $t
1131
     * @return string
1132
     */
1133
    public function getXcRedirectHeader($directory, $options, $numb, $var, $isString = true, $t = '')
1134
    {
1135
        $ret = '';
1136
        if (!$isString) {
1137
            $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n";
1138
        } else {
1139
            $ret = "{$t}redirect_header('{$directory}.php{$options}', {$numb}, {$var});\n";
1140
        }
1141
1142
        return $ret;
1143
    }
1144
1145
    /**
1146
     * @public function getXcXoopsConfirm
1147
     * @param        $tableName
1148
     * @param        $language
1149
     * @param        $fieldId
1150
     * @param        $fieldMain
1151
     * @param string $options
1152
     *
1153
     * @param string $t
1154
     * @return string
1155
     */
1156
    public function getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1157
    {
1158
        $stuOptions = mb_strtoupper($options);
1159
        $ccFieldId = Tdmcreate\Files\CreateFile::getInstance()->getCamelCase($fieldId, false, true);
1160
        $phpXoopsConfirm = Tdmcreate\Files\CreatePhpCode::getInstance();
1161
        $array = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')";
1162
        $server = $phpXoopsConfirm->getPhpCodeGlobalsVariables('REQUEST_URI', 'SERVER');
1163
        $getVar = $this->getXcGetVar('', $tableName . 'Obj', $fieldMain, true, '');
1164
        $sprintf = $phpXoopsConfirm->getPhpCodeSprintf($language . 'FORM_SURE_' . $stuOptions, $getVar);
1165
        $ret = "{$t}xoops_confirm({$array}, {$server}, {$sprintf});\n";
1166
1167
        return $ret;
1168
    }
1169
1170
    /**
1171
     * @public function getXcAddStylesheet
1172
     * @param string $style
1173
     *
1174
     * @param string $t
1175
     * @return string
1176
     */
1177
    public function getXcAddStylesheet($style = 'style', $t = '')
1178
    {
1179
        return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1180
    }
1181
1182
    /**
1183
     *  @public function getXcSecurityCheck
1184
     *  @param $denial
1185
     *  @return bool
1186
     */
1187
    public function getXcSecurityCheck($denial = '')
1188
    {
1189
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
0 ignored issues
show
Bug Best Practice introduced by
The expression return $denial.'\$GLOBAL...opsSecurity']->check()' returns the type string which is incompatible with the documented return type boolean.
Loading history...
1190
    }
1191
1192
    /**
1193
     *  @public function getXcSecurityErrors
1194
     *  @param null
1195
     *  @return string
1196
     */
1197
    public function getXcSecurityErrors()
1198
    {
1199
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1200
    }
1201
1202
    /**
1203
     * @public function getXcHtmlErrors
1204
     *
1205
     * @param        $tableName
1206
     * @param bool   $isParam
1207
     * @param string $obj
1208
     *
1209
     * @param string $t
1210
     * @return string
1211
     */
1212
    public function getXcHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1213
    {
1214
        $ret = '';
1215
        if ($isParam) {
1216
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1217
        } else {
1218
            $ret = "{$t}\${$tableName}{$obj} = \${$tableName}->getHtmlErrors();";
1219
        }
1220
1221
        return $ret;
1222
    }
1223
1224
    /**
1225
     * @public function getXcObjHandlerCount
1226
     *
1227
     * @param        $left
1228
     * @param        $tableName
1229
     * @param string $obj
1230
     *
1231
     * @param string $t
1232
     * @return string
1233
     */
1234
    public function getXcGetForm($left, $tableName, $obj = '', $t = '')
1235
    {
1236
        $ucfTableName = ucfirst($tableName);
1237
1238
        return "{$t}\${$left} = \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1239
    }
1240
1241
    /**
1242
     * @public function getXcGet
1243
     *
1244
     * @param        $left
1245
     * @param        $var
1246
     * @param string $obj
1247
     * @param string $handler
1248
     * @param bool   $isParam
1249
     *
1250
     * @param string $t
1251
     * @return string
1252
     */
1253
    public function getXcGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '')
1254
    {
1255
        $ret = '';
1256
        if ($isParam) {
1257
            $ret = "\${$left}{$handler}->get(\${$var})";
1258
        } else {
1259
            $ret = "{$t}\${$left}{$obj} = \${$handler}->get(\${$var});\n";
1260
        }
1261
1262
        return $ret;
1263
    }
1264
1265
    /**
1266
     *  @public function getXcHandler
1267
     *
1268
     *  @param $left
1269
     *  @param $var
1270
     *  @param $obj
1271
     *  @param $handler
1272
     *
1273
     *  @return string
1274
     */
1275
    public function getXcInsert($left, $var, $obj = '', $handler = 'Handler')
1276
    {
1277
        return "\${$left}{$handler}->insert(\${$var}{$obj})";
1278
    }
1279
1280
    /**
1281
     * @public   function getXcDelete
1282
     *
1283
     * @param        $left
1284
     * @param        $var
1285
     * @param string $obj
1286
     * @param string $handler
1287
     * @return string
1288
     */
1289
    public function getXcDelete($left, $var, $obj = '', $handler = 'Handler')
1290
    {
1291
        return "\${$left}{$handler}->delete(\${$var}{$obj})";
1292
    }
1293
1294
    /**
1295
     * @public function getXcHandler
1296
     *
1297
     * @param        $left
1298
     * @param        $var
1299
     *
1300
     * @param bool   $get
1301
     * @param bool   $insert
1302
     * @param bool   $delete
1303
     * @param string $obj
1304
     * @param string $t
1305
     * @return string
1306
     */
1307
    public function getXcHandler($left, $var, $get = false, $insert = false, $delete = false, $obj = '', $t = '')
1308
    {
1309
        $ret = '';
1310
        if ($get) {
1311
            $ret = "{$t}\${$left}Handler->get(\${$var});";
1312
        } elseif ($insert && ('' != $obj)) {
1313
            $ret = "{$t}\${$left}Handler->insert(\${$var}{$obj});";
1314
        } elseif ($delete && ('' != $obj)) {
1315
            $ret = "{$t}\${$left}Handler->delete(\${$var}{$obj});";
1316
        }
1317
1318
        return $ret;
1319
    }
1320
1321
    /**
1322
     * @public function getTopicGetVar
1323
     * @param        $lpFieldName
1324
     * @param        $rpFieldName
1325
     * @param        $tableName
1326
     * @param        $tableNameTopic
1327
     * @param        $fieldNameParent
1328
     * @param        $fieldNameTopic
1329
     * @param string $t
1330
     * @return string
1331
     */
1332
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
1333
    {
1334
        $ret = Tdmcreate\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
1335
        $paramGet = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
1336
        $ret .= $this->getXcGet($rpFieldName, $paramGet, '', $tableNameTopic . 'Handler', false, $t);
1337
        $ret .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
1338
1339
        return $ret;
1340
    }
1341
1342
    /**
1343
     * @public function getUploadImageGetVar
1344
     * @param        $lpFieldName
1345
     * @param        $rpFieldName
1346
     * @param        $tableName
1347
     * @param        $fieldName
1348
     * @param string $t
1349
     * @return string
1350
     */
1351
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
1352
    {
1353
        $pImageGetVar = Tdmcreate\Files\CreatePhpCode::getInstance();
1354
        $ret = $pImageGetVar->getPhpCodeCommentLine('Get Var', $fieldName, $t);
1355
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
1356
        $ret .= $pImageGetVar->getPhpCodeTernaryOperator('uploadImage', "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
1357
        $ret .= $this->getXcEqualsOperator("${$lpFieldName}['{$rpFieldName}']", '$uploadImage', null, false, $t);
1358
1359
        return $ret;
1360
    }
1361
1362
    /**
1363
     *  @public function getXcSaveFieldId
1364
     *
1365
     *  @param $fields
1366
     *
1367
     *  @return string
1368
     */
1369
    public function getXcSaveFieldId($fields)
1370
    {
1371
        $fieldId = '';
1372
        foreach (array_keys($fields) as $f) {
1373
            if (0 == $f) {
1374
                $fieldId = $fields[$f]->getVar('field_name');
1375
            }
1376
        }
1377
1378
        return $fieldId;
1379
    }
1380
1381
    /**
1382
     *  @public function getXcSaveFieldMain
1383
     *
1384
     *  @param $fields
1385
     *
1386
     *  @return string
1387
     */
1388
    public function getXcSaveFieldMain($fields)
1389
    {
1390
        $fieldMain = '';
1391
        foreach (array_keys($fields) as $f) {
1392
            if (1 == $fields[$f]->getVar('field_main')) {
1393
                $fieldMain = $fields[$f]->getVar('field_name');
1394
            }
1395
        }
1396
1397
        return $fieldMain;
1398
    }
1399
1400
    /**
1401
     * @public function getXcSaveElements
1402
     *
1403
     * @param        $moduleDirname
1404
     * @param        $tableName
1405
     * @param        $tableSoleName
1406
     * @param        $tableAutoincrement
1407
     * @param        $fields
1408
     *
1409
     * @param string $t
1410
     * @return string
1411
     */
1412
    public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $t = '')
1413
    {
1414
        $axCodeSaveElements = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance();
1415
        $ret = '';
1416
        $fieldMain = '';
1417
        foreach (array_keys($fields) as $f) {
1418
            $fieldName = $fields[$f]->getVar('field_name');
1419
            $fieldElement = $fields[$f]->getVar('field_element');
1420
            if (1 == $fields[$f]->getVar('field_main')) {
1421
                $fieldMain = $fieldName;
1422
            }
1423
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1424
                $ret .= $t . $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1425
            } elseif (13 == $fieldElement) {
1426
                $ret .= $axCodeSaveElements->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
1427
            } elseif (14 == $fieldElement) {
1428
                $ret .= $axCodeSaveElements->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName);
1429
            } elseif (15 == $fieldElement) {
1430
                $ret .= $t . $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName);
1431
            } else {
1432
                if ((0 != $f) && 1 == $tableAutoincrement) {
1433
                    $ret .= $t . $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1434
                } elseif ((0 == $f) && 0 == $tableAutoincrement) {
1435
                    $ret .= $t . $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1436
                }
1437
            }
1438
        }
1439
1440
        return $ret;
1441
    }
1442
1443
    /**
1444
     * @public function getXcPageNav
1445
     * @param        $tableName
1446
     *
1447
     * @param string $t
1448
     * @return string
1449
     */
1450
    public function getXcPageNav($tableName, $t = '')
1451
    {
1452
        $phpCodePageNav = Tdmcreate\Files\CreatePhpCode::getInstance();
1453
        $classXCode = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
1454
        $ret = $phpCodePageNav->getPhpCodeCommentLine('Display Navigation', null, $t);
1455
        $condition = $phpCodePageNav->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t");
1456
        $condition .= $classXCode->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', 'start', "'op=list&limit=' . \$limit", false, $t . "\t");
1457
        $condition .= $this->getXcTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t");
1458
        $ret .= $phpCodePageNav->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1459
1460
        return $ret;
1461
    }
1462
}
1463