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

CreateXoopsCode::getXcParentTopicGetVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 8
dl 0
loc 10
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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

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

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