Passed
Pull Request — master (#40)
by Gino
03:41
created

TDMCreateXoopsCode   D

Complexity

Total Complexity 81

Size/Duplication

Total Lines 826
Duplicated Lines 4.48 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 81
lcom 1
cbo 1
dl 37
loc 826
rs 4.4444

45 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 9 2
A getXoopsCodeSetVar() 0 4 1
A getXoopsCodeTextDateSelectSetVar() 0 4 1
A getXoopsCodeCheckBoxOrRadioYNSetVar() 0 6 1
A getXoopsCodeGetConfig() 0 4 1
A getXoopsCodeMediaUploader() 0 6 1
A getXoopsCodeImageListSetVar() 0 18 1
A getXoopsCodeUploadImageSetVar() 0 22 1
B getXoopsCodeFileSetVar() 0 27 3
A getXoopsCodeIdGetVar() 0 4 1
A getXoopsCodeGetVarAll() 0 4 1
A getXoopsCodeTopicGetVar() 0 10 1
A getXoopsCodeParentTopicGetVar() 13 13 1
A getXoopsCodeUploadImageGetVar() 0 10 1
A getXoopsCodeUrlFileGetVar() 0 4 1
A getXoopsCodeTextAreaGetVar() 0 4 1
A getXoopsCodeSelectUserGetVar() 0 4 1
A getXoopsCodeTextDateSelectGetVar() 0 4 1
A getXoopsCodeXoopsOptionTemplateMain() 0 4 1
A getXoopsCodeUserHeader() 0 8 1
A getXoopsCodePermissionsHeader() 0 15 1
A getXoopsCodeGetFieldId() 12 12 3
A getXoopsCodeGetFieldName() 0 8 2
A getXoopsCodeGetFieldParentId() 12 12 3
C getXoopsCodeUserSaveElements() 0 24 8
B getXoopsCodeXoopsRequest() 0 12 5
A getXoopsCodeTemplateMain() 0 4 1
A getXoopsCodeTplAssign() 0 4 1
A getXoopsCodeXoopsTplAppend() 0 4 1
A getXoopsCodeXoopsTplAppendByRef() 0 4 1
A getXoopsCodeTplDisplay() 0 4 1
A getXoopsCodeItemButton() 0 15 3
A getXoopsCodeObjHandlerCreate() 0 6 1
C getXoopsCodeSetVarsObjects() 0 40 11
A getXoopsCodeSecurity() 0 9 1
A getXoopsCodeInsertData() 0 7 1
A getXoopsCodeRedirectHeader() 0 4 1
A getXoopsCodeSecurityCheck() 0 4 1
A getXoopsCodeSecurityGetError() 0 4 1
A getXoopsCodeGetFormError() 0 11 1
A getXoopsCodeGetFormId() 0 11 1
B getXoopsCodeHandler() 0 12 6
B getXoopsCodeCaseDelete() 0 32 1
A getXoopsCodeUpdate() 0 14 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TDMCreateXoopsCode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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

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

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
25
/**
26
 * Class TDMCreateXoopsCode.
27
 */
28
class TDMCreateXoopsCode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    /*
31
    * @var mixed
32
    */
33
    private $phpcode = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->phpcode = TDMCreatePhpCode::getInstance();
45
    }
46
47
    /*
48
    *  @static function &getInstance
49
    *  @param null
50
    */
51
    /**
52
     * @return TDMCreateXoopsCode
53
     */
54
    public static function &getInstance()
55
    {
56
        static $instance = false;
57
        if (!$instance) {
58
            $instance = new self();
59
        }
60
61
        return $instance;
62
    }
63
64
    /*
65
    *  @public function getXoopsCodeSetVar
66
    *  @param string $tableName
67
    *  @param string $fieldName
68
    *  @param string $var
69
    *  @return string
70
    */
71
    public function getXoopsCodeSetVar($tableName, $fieldName, $var)
72
    {
73
        return "\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
74
    }
75
76
    /*
77
    *  @public function getXoopsCodeTextDateSelectSetVar
78
    *  @param string $tableName
79
    *  @param string $fieldName
80
    *  @return string
81
    */
82
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
83
    {
84
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
85
    }
86
87
    /*
88
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
89
    *  @param $tableName
90
    *  @param $fieldName
91
    *  @return string
92
    */
93
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
94
    {
95
        $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
96
97
        return $ret;
98
    }
99
100
    /*
101
    *  @public function getXoopsCodeGetConfig
102
    *  @param $moduleDirname
103
    *  @param $name
104
    *  @return string
105
    */
106
    public function getXoopsCodeGetConfig($moduleDirname, $name)
107
    {
108
        return "\${$moduleDirname}->getConfig('{$name}')";
109
    }
110
111
    /*
112
    *  @public function getXoopsCodeGetConfig
113
    *  @param $var
114
    *  @param $dirPath
115
    *  @param $tableName
116
    *  @param $moduleDirname
117
    *  @return string
118
    */
119
    public function getXoopsCodeMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
120
    {
121
        return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}',
122
														\${$moduleDirname}->getConfig('mimetypes'),
123
                                                        \${$moduleDirname}->getConfig('maxsize'), null, null);\n";
124
    }
125
126
    /*
127
    *  @public function getXoopsCodeImageListSetVar
128
    *  @param string $moduleDirname
129
    *  @param string $tableName
130
    *  @param string $fieldName
131
    *  @return string
132
    */
133
    public function getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName)
134
    {
135
        $ret = $this->phpcode->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
136
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
137
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname);
138
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
139
        $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
140
        $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
141
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
142
        $contentIf = "\$errors = \$uploader->getErrors();\n";
143
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
144
        $ifelse .= $this->phpcode->getPhpCodeConditions("!\$uploader->upload()", '', '', $contentIf, $contentElseInt);
145
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
146
147
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
148
149
        return $ret;
150
    }
151
152
    /*
153
    *  @public function getXoopsCodeUploadImageSetVar
154
    *  @param string $moduleDirname
155
    *  @param string $tableName
156
    *  @param string $fieldName
157
    *  @return string
158
    */
159
    public function getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain)
160
    {
161
        $stuModuleDirname = strtoupper($moduleDirname);
162
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
163
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
164
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname);
165
166
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
167
        $ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n";
168
        $ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
169
        $ifelse .= "\$uploader->setPrefix(\$imgName);\n";
170
        $ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n";
171
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
172
        $contentIf = "\$errors = \$uploader->getErrors();\n";
173
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
174
        $ifelse .= $this->phpcode->getPhpCodeConditions("!\$uploader->upload()", '', '', $contentIf, $contentElseInt);
175
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
176
177
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
178
179
        return $ret;
180
    }
181
182
    /*
183
    *  @public function getXoopsCodeFileSetVar
184
    *  @param $moduleDirname
185
    *  @param $tableName
186
    *  @param $fieldName
187
    *  @param $formatUrl
188
    *  @return string
189
    */
190
    public function getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false)
191
    {
192
        $stuModuleDirname = strtoupper($moduleDirname);
193
        if ($formatUrl) {
194
            $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])");
195
            $ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
196
        } else {
197
            $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
198
        }
199
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
200
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname);
201
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
202
        if ($formatUrl) {
203
            $ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
204
        } else {
205
            $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
206
            $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
207
        }
208
        $contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
209
        $contentIf = "\$errors = \$uploader->getErrors();\n";
210
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
211
        $ifelse .= $this->phpcode->getPhpCodeConditions("!\$uploader->upload()", '', '', $contentIf, $contentElse);
212
213
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse);
214
215
        return $ret;
216
    }
217
218
    /*
219
    *  @public function getXoopsCodeIdGetVar
220
    *  @param string $lpFieldName
221
    *  @return string
222
    */
223
    public function getXoopsCodeIdGetVar($lpFieldName)
224
    {
225
        return "\${$lpFieldName}['id'] = \$i;\n";
226
    }
227
228
    /*
229
    *  @public function getXoopsCodeGetVarAll
230
    *  @param string $lpFieldName
231
    *  @param string $rpFieldName
232
    *  @param string $tableName
233
    *  @param string $fieldName
234
    *  @return string
235
    */
236
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName)
237
    {
238
        return "\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
239
    }
240
241
    /*
242
    *  @public function getXoopsCodeTopicGetVar
243
    *  @param string $lpFieldName
244
    *  @param string $rpFieldName
245
    *  @param string $tableName
246
    *  @param string $tableNameTopic
247
    *  @param string $fieldNameParent
248
    *  @param string $fieldNameTopic
249
    *  @return string
250
    */
251
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
252
    {
253
        $ret = <<<EOT
254
\t\t\t\t// Get Var {$fieldNameParent}
255
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
256
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
257
EOT;
258
259
        return $ret;
260
    }
261
262
    /*
263
    *  @public function getXoopsCodeParentTopicGetVar
264
    *  @param string $moduleDirname
265
    *  @param string $lpFieldName
266
    *  @param string $rpFieldName
267
    *  @param string $tableName
268
    *  @param string $tableSoleNameTopic
269
    *  @param string $tableNameTopic
270
    *  @param string $fieldNameParent
271
    *  @return string
272
    */
273 View Code Duplication
    public function getXoopsCodeParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
    {
275
        $ret = <<<EOT
276
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
277
\t\t\t\t\t// Get {$tableNameTopic} Handler
278
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
279
\t\t\t\t}
280
\t\t\t\t// Get Var {$fieldNameParent}
281
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
282
EOT;
283
284
        return $ret;
285
    }
286
287
    /*
288
    *  @public function getXoopsCodeUploadImageGetVar
289
    *  @param string $lpFieldName
290
    *  @param string $rpFieldName
291
    *  @param string $tableName
292
    *  @param string $fieldName
293
    *  @return string
294
    */
295
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
296
    {
297
        $ret = <<<EOT
298
\t\t\t\t// Get Var {$fieldName}
299
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
300
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
301
EOT;
302
303
        return $ret;
304
    }
305
    /*
306
    *  @public function getXoopsCodeUrlFileGetVar
307
    *  @param string $lpFieldName
308
    *  @param string $rpFieldName
309
    *  @param string $tableName
310
    *  @param string $fieldName
311
    *  @return string
312
    */
313
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
314
    {
315
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
316
    }
317
    /*
318
    *  @public function getXoopsCodeTextAreaGetVar
319
    *  @param string $lpFieldName
320
    *  @param string $rpFieldName
321
    *  @param string $tableName
322
    *  @param string $fieldName
323
    *  @return string
324
    */
325
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
326
    {
327
        return "\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
328
    }
329
330
    /*
331
    *  @public function getXoopsCodeSelectUserGetVar
332
    *  @param string $lpFieldName
333
    *  @param string $rpFieldName
334
    *  @param string $tableName
335
    *  @param string $fieldName
336
    * @return string
337
    */
338
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
339
    {
340
        return "\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
341
    }
342
343
    /*
344
    *  @public function getXoopsCodeTextDateSelectGetVar
345
    *  @param string $lpFieldName
346
    *  @param string $rpFieldName
347
    *  @param string $tableName
348
    *  @param string $fieldName
349
    *  @return string
350
    */
351
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
352
    {
353
        return "\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
354
    }
355
356
    /*
357
    *  @public function getXoopsCodeUserHeader
358
    *  @param string $moduleDirname
359
    *  @param string $tableName
360
    *  @return string
361
    */
362
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName)
363
    {
364
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
365
    }
366
367
    /*
368
    *  @public function getXoopsCodeUserHeader
369
    *  @param string $moduleDirname
370
    *  @param string $tableName
371
    *  @return string
372
    */
373
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
374
    {
375
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
376
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
377
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
378
379
        return $ret;
380
    }
381
382
    /*
383
    *  @public function getXoopsCodePermissionsHeader
384
    *  @param null
385
    */
386
    /**
387
     * @return string
388
     */
389
    public function getXoopsCodePermissionsHeader()
390
    {
391
        $ret = <<<EOT
392
// Permission
393
include_once XOOPS_ROOT_PATH.'/class/xoopsform/grouppermform.php';
394
\$gperm_handler =& xoops_gethandler('groupperm');
395
if (is_object(\$xoopsUser)) {
396
    \$groups = \$xoopsUser->getGroups();
397
} else {
398
    \$groups = XOOPS_GROUP_ANONYMOUS;
399
}
400
EOT;
401
402
        return $ret;
403
    }
404
405
    /**
406
     *  @public function getXoopsCodeGetFieldId
407
     *
408
     *  @param $fields
409
     *
410
     *  @return string
411
     */
412 View Code Duplication
    public function getXoopsCodeGetFieldId($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
    {
414
        $fieldId = 'id';
415
        foreach (array_keys($fields) as $f) {
416
            $fieldName = $fields[$f]->getVar('field_name');
417
            if (0 == $f) {
418
                $fieldId = $fieldName;
419
            }
420
        }
421
422
        return $fieldId;
423
    }
424
425
    /**
426
     *  @public function getXoopsCodeGetFieldName
427
     *
428
     *  @param $fields
429
     *
430
     *  @return string
431
     */
432
    public function getXoopsCodeGetFieldName($fields)
433
    {
434
        foreach (array_keys($fields) as $f) {
435
            $fieldName = $fields[$f]->getVar('field_name');
436
        }
437
438
        return $fieldName;
0 ignored issues
show
Bug introduced by
The variable $fieldName does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
439
    }
440
441
    /**
442
     *  @public function getXoopsCodeGetFieldParentId
443
     *
444
     *  @param $fields
445
     *
446
     *  @return string
447
     */
448 View Code Duplication
    public function getXoopsCodeGetFieldParentId($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
449
    {
450
        $fieldPid = 'pid';
451
        foreach (array_keys($fields) as $f) {
452
            $fieldName = $fields[$f]->getVar('field_name');
453
            if (1 == $fields[$f]->getVar('field_parent')) {
454
                $fieldPid = $fieldName;
455
            }
456
        }
457
458
        return $fieldPid;
459
    }
460
461
    /**
462
     *  @public function getXoopsCodeUserSaveElements
463
     *
464
     *  @param $moduleDirname
465
     *  @param $tableName
466
     *  @param $fields
467
     *
468
     *  @return string
469
     */
470
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
471
    {
472
        $ret = '';
473
        foreach (array_keys($fields) as $f) {
474
            $fieldName = $fields[$f]->getVar('field_name');
475
            $fieldElement = $fields[$f]->getVar('field_element');
476
            if (1 == $fields[$f]->getVar('field_main')) {
477
                $fieldMain = $fieldName;
478
            }
479
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
480
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
481
            } elseif (13 == $fieldElement) {
482
                $ret .= $this->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
483
            } elseif (14 == $fieldElement) {
484
                $ret .= $this->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUploadFileSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

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...
485
            } elseif (15 == $fieldElement) {
486
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
487
            } else {
488
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
489
            }
490
        }
491
492
        return $ret;
493
    }
494
495
    /*
496
    *  @public function getXoopsCodeXoopsRequest
497
    *  @param $left
498
    *  @param $var1
499
    *  @param $var2
500
    *  @param $type
501
    *  @param $metod
502
    *  @return string
503
    */
504
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false)
505
    {
506
        if ($type == 'String') {
507
            $ret = "\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
508
        } elseif ($type == 'Int') {
509
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2});\n";
510
        } elseif ($type == 'Int' && $metod !== false) {
511
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2}, '{$metod}');\n";
512
        }
513
514
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
515
    }
516
517
    /*
518
    *  @public function getXoopsCodeTemplateMain
519
    *  @param $moduleDirname
520
    *  @param $filename
521
    *  @return string
522
    */
523
    public function getXoopsCodeTemplateMain($moduleDirname, $filename)
524
    {
525
        return "\$templateMain = '{$moduleDirname}_admin_{$filename}.tpl';\n";
526
    }
527
528
    /**
529
     *  @public function getXoopsCodeTplAssign
530
     *
531
     *  @param string $tplString
532
     *  @param string $phpRender
533
     *
534
     *  @return string
535
     */
536
    public function getXoopsCodeTplAssign($tplString, $phpRender)
537
    {
538
        return "\$GLOBALS['xoopsTpl']->assign('{$tplString}', {$phpRender});\n";
539
    }
540
541
    /**
542
     *  @public function getXoopsCodeXoopsTplAppend
543
     *
544
     *  @param string $tplString
545
     *  @param string $phpRender
546
     *
547
     *  @return string
548
     */
549
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender)
550
    {
551
        return "\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
552
    }
553
554
    /**
555
     *  @public function getXoopsCodeXoopsTplAppendByRef
556
     *
557
     *  @param string $tplString
558
     *  @param string $phpRender
559
     *
560
     *  @return string
561
     */
562
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender)
563
    {
564
        return "\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
565
    }
566
	
567
	/**
568
     *  @public function getXoopsCodeTplDisplay
569
     *
570
     *  @param null
571
     *
572
     *  @return string
573
     */
574
    public function getXoopsCodeTplDisplay()
575
    {
576
        return "\$GLOBALS['xoopsTpl']->display(\"db:{\$templateMain}\");\n";
577
    }
578
579
    /*
580
    *  @public function getXoopsCodeItemButton
581
    *  @param $language
582
    *  @param $tableName
583
    *  @param $admin
584
    *  @return string
585
    */
586
    public function getXoopsCodeItemButton($language, $tableName, $tableSoleName, $op = '?op=new', $type = 'add')
587
    {
588
        $stuTableName = strtoupper($tableName);
589
        $stuTableSoleName = strtoupper($tableSoleName);
590
        $stuType = strtoupper($type);
591
        if ($type = 'add') {
592
            $ret = "\$adminMenu->addItemButton({$language}{$stuType}_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
593
        } elseif ($type = 'list') {
594
            $ret = "\$adminMenu->addItemButton({$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
595
        } else {
596
            $ret = "\$adminMenu->addItemButton({$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
597
        }
598
599
        return $ret;
600
    }
601
602
    /**
603
     *  @public function getXoopsCodeObjHandlerCreate
604
     *
605
     *  @param string $tableName
606
     *
607
     *  @return string
608
     */
609
    public function getXoopsCodeObjHandlerCreate($tableName)
610
    {
611
        $ret = "\${$tableName}Obj =& \${$tableName}Handler->create();\n";
612
613
        return $ret;
614
    }
615
616
    /**
617
     *  @public function getXoopsCodeSetVarsObjects
618
     *
619
     *  @param $moduleDirname
620
     *  @param $tableName
621
     *  @param $fields
622
     *
623
     *  @return string
624
     */
625
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
626
    {
627
        $ret = '';
628
629
        foreach (array_keys($fields) as $f) {
630
            $fieldName = $fields[$f]->getVar('field_name');
631
            $fieldElement = $fields[$f]->getVar('field_element');
632
            if (1 == $fields[$f]->getVar('field_main')) {
633
                $fieldMain = $fieldName;
634
            }
635
            if ($f > 0) { // If we want to hide field id
636
                switch ($fieldElement) {
637
                    case 5:
638
                    case 6:
639
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
640
                        break;
641
                    case 11:
642
                        $ret .= $this->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
643
                        break;
644
                    case 12:
645
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, true);
646
                        break;
647
                    case 13:
648
                        $ret .= $this->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
649
                        break;
650
                    case 14:
651
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName);
652
                        break;
653
                    case 15:
654
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
655
                        break;
656
                    default:
657
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
658
                        break;
659
                }
660
            }
661
        }
662
663
        return $ret;
664
    }
665
666
    /**
667
     *  @public function getXoopsCodeSecurity
668
     *
669
     *  @param $tableName
670
     *
671
     *  @return string
672
     */
673
    public function getXoopsCodeSecurity($tableName)
674
    {
675
        $securityError = $this->getXoopsCodeSecurityGetError();
676
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
677
        $content = $this->getXoopsCodeRedirectHeader($tableName, '', 3, $implode);
678
        $securityCheck = $this->getXoopsCodeSecurityCheck();
679
680
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
681
    }
682
683
    /*
684
    *  @public function getXoopsCodeInsertData
685
    *  @param $tableName
686
    *  @param $language
687
    *  @return string
688
    */
689
    public function getXoopsCodeInsertData($tableName, $language)
690
    {
691
        $content = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
692
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
693
694
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
695
    }
696
697
    /*
698
    *  @public function getXoopsCodeRedirectHeader
699
    *  @param $tableName
700
    *  @param $options
701
    *  @param $numb
702
    *  @param $var
703
    *  @return string
704
    */
705
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = 2, $var)
706
    {
707
        return "redirect_header('{$tableName}.php{$options}', {$numb}, {$var});\n";
708
    }
709
710
    /*
711
    *  @public function getXoopsCodeSecurityCheck
712
    *  @param null
713
    *  @return boolean
714
    */
715
    public function getXoopsCodeSecurityCheck()
716
    {
717
        return "\$GLOBALS['xoopsSecurity']->check()";
718
    }
719
720
    /*
721
    *  @public function getXoopsCodeSecurityGetError
722
    *  @param null
723
    *  @return string
724
    */
725
    public function getXoopsCodeSecurityGetError()
726
    {
727
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
728
    }
729
730
    /**
731
     *  @public function getXoopsCodeGetFormError
732
     *
733
     *  @param $tableName
734
     *
735
     *  @return string
736
     */
737
    public function getXoopsCodeGetFormError($tableName)
738
    {
739
        $ret = <<<EOT
740
        // Get Form
741
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
742
        \$form =& \${$tableName}Obj->getForm();
743
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
744
EOT;
745
746
        return $ret;
747
    }
748
749
    /**
750
     *  @public function getXoopsCodeGetFormId
751
     *
752
     *  @param string $tableName
753
     *  @param string $fieldId
754
     *
755
     *  @return string
756
     */
757
    public function getXoopsCodeGetFormId($tableName, $fieldId)
758
    {
759
        $ret = <<<EOT
760
        // Get Form
761
        \${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});
762
        \$form = \${$tableName}Obj->getForm();
763
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
764
EOT;
765
766
        return $ret;
767
    }
768
769
    /**
770
     *  @public function getXoopsCodeHandler
771
     *
772
     *  @param string $tableName
773
     *  @param string $var
774
     *
775
     *  @return string
776
     */
777
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
778
    {
779
        if ($get) {
780
            $ret = "\${$tableName}Handler->get(\${$var});";
781
        } elseif ($insert && ($obj != '')) {
782
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
783
        } elseif ($delete && ($obj != '')) {
784
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
785
        }
786
787
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
788
    }
789
790
    /*
791
    *  @public function getXoopsCodeCaseDelete
792
    *  @param string $tableName
793
    *  @param string $language
794
    *  @param string $fieldId
795
    *  @param string $fieldMain
796
    *  @return string
797
    */
798
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
799
    {
800
        $content = <<<EOT
801
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
802
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
803
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
804
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
805
            }
806
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
807
                redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK);
808
            } else {
809
                echo \${$tableName}Obj->getHtmlErrors();
810
            }
811
        } else {
812
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}')));
813
        }\n
814
EOT;
815
        /*$isset = $this->phpcode->getPhpCodeIsset($fieldId);
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
816
        $if1 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
817
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
818
        $if2 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
819
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
820
        //$content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
821
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
822
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '', 2, "{$language}FORM_DELETE_OK");
823
824
        $else = $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
825
826
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect, $else);*/
827
828
        return $this->phpcode->getPhpCodeCaseSwitch('delete', $content);
829
    }
830
831
    /*
832
    *  @public function getXoopsCodeUpdate
833
    *  @param $language
834
    *  @param $tableName
835
    *  @param $fieldId
836
    *  @param $fieldName
837
    *  @return string
838
    */
839
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
840
    {
841
        $isset = $this->phpcode->getPhpCodeIsset($fieldId);
842
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
843
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
844
        $content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
845
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
846
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
847
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
848
849
        $content .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
850
851
        return $this->phpcode->getPhpCodeCaseSwitch('update', $content);
852
    }
853
}
854