Completed
Push — master ( aa4794...6b7a6d )
by Gino
19s
created

getTemplatesUserPagesListTbody()   C

Complexity

Conditions 9
Paths 9

Size

Total Lines 48
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 39
nc 9
nop 3
dl 0
loc 48
rs 5.5102
c 0
b 0
f 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       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: TemplatesUserPagesList.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserPagesList.
27
 */
28
class TemplatesUserPagesList extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

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

namespace YourVendor;

class YourClass { }

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

Loading history...
29
{
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
35
    public function __construct()
36
    {
37
        parent::__construct();
38
    }
39
40
    /*
41
    *  @static function getInstance
42
    *  @param null
43
    */
44
    /**
45
     * @return TemplatesUserPagesList
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance = false;
50
        if (!$instance) {
51
            $instance = new self();
52
        }
53
54
        return $instance;
55
    }
56
57
    /*
58
    *  @public function write
59
    *  @param string $module
60
    *  @param string $table
61
    *  @param string $filename
62
    */
63
    /**
64
     * @param $module
65
     * @param $table
66
     */
67
    public function write($module, $table, $tables, $filename)
68
    {
69
        $this->setModule($module);
70
        $this->setTable($table);
71
        $this->setTables($tables);
72
        $this->setFileName($filename);
73
    }
74
75
    /*
76
    *  @private function getTemplatesUserPagesListPanel
77
    *  @param string $moduleDirname
78
    *  @param string $table
79
    *  @param string $language
80
    */
81
    /**
82
     * @param $moduleDirname
83
     * @param $table
84
     * @param $language
85
     *
86
     * @return string
87
     */
88
    private function getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language)
89
    {
90
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
91
        $fields = $this->getTableFields($tableMid, $tableId);
92
        $ret = '';
93
        $retNumb = '';
94
        foreach (array_keys($fields) as $f) {
95
            $fieldElement = $fields[$f]->getVar('field_element');
96
            if (1 == $fields[$f]->getVar('field_user')) {
97
                if (1 == $fields[$f]->getVar('field_thead')) {
98
                    switch ($fieldElement) {
99
                        default:
100
                        case 2:
101
                            $fieldName = $fields[$f]->getVar('field_name');
102
                            $rpFieldName = $this->getRightString($fieldName);
103
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
104
                            $retNumb = $hc->getHtmlHNumb($doubleVar, '3', 'panel-title');
105
                            break;
106
                    }
107
                }
108
            }
109
        }
110
        $ret .= $hc->getHtmlDiv($retNumb, 'panel-heading').PHP_EOL;
111
        $retElem = '';
112
        foreach (array_keys($fields) as $f) {
113
            $fieldElement = $fields[$f]->getVar('field_element');
114
            if (1 == $fields[$f]->getVar('field_user')) {
115
                if (1 == $fields[$f]->getVar('field_tbody')) {
116
                    switch ($fieldElement) {
117
                        default:
118
                        case 3:
119
                        case 4:
120
                            $fieldName = $fields[$f]->getVar('field_name');
121
                            $rpFieldName = $this->getRightString($fieldName);
122
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
123
                            $retElem .= $hc->getHtmlSpan($doubleVar, 'col-sm-9 justify').PHP_EOL;
124
                            break;
125
                        case 10:
126
                            $fieldName = $fields[$f]->getVar('field_name');
127
                            $rpFieldName = $this->getRightString($fieldName);
128
                            $singleVar = $hc->getSmartySingleVar('xoops_icons32_url');
129
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
130
                            $img = $hc->getHtmlImage($singleVar.'/'.$doubleVar, "{$tableName}");
131
                            $retElem .= $hc->getHtmlSpan($img, 'col-sm-3').PHP_EOL;
132
                            unset($img);
133
                            break;
134
                        case 13:
135
                            $fieldName = $fields[$f]->getVar('field_name');
136
                            $rpFieldName = $this->getRightString($fieldName);
137
                            $singleVar = $hc->getSmartySingleVar($moduleDirname.'_upload_url');
138
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
139
                            $img = $hc->getHtmlImage($singleVar."/images/{$tableName}/".$doubleVar, "{$tableName}");
140
                            $retElem .= $hc->getHtmlSpan($img, 'col-sm-3').PHP_EOL;
141
                            unset($img);
142
                            break;
143
                    }
144
                }
145
            }
146
        }
147
        $ret .= $hc->getHtmlDiv($retElem, 'panel-body').PHP_EOL;
148
        $retFoot = '';
149
        foreach (array_keys($fields) as $f) {
150
            if (1 == $fields[$f]->getVar('field_user')) {
151
                if (1 == $fields[$f]->getVar('field_tfoot')) {
152
                    $fieldName = $fields[$f]->getVar('field_name');
153
                    $rpFieldName = $this->getRightString($fieldName);
154
                    $langConst = strtoupper($tableSoleName).'_'.strtoupper($rpFieldName);
155
                    $lang = $hc->getSmartyConst($language, $langConst);
156
                    $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
157
                    $retFoot .= $hc->getHtmlSpan($lang.': '.$doubleVar, 'block-pie justify').PHP_EOL;
158
                }
159
            }
160
        }
161
        $ret .= $hc->getHtmlDiv($retFoot, 'panel-foot').PHP_EOL;
162
163
        return $ret;
164
    }
165
166
    /*
167
    *  @public function render
168
    *  @param string $filename
169
    */
170
    /**
171
     * @param $filename
172
     *
173
     * @return bool|string
174
     */
175
    public function render()
176
    {
177
        $module = $this->getModule();
178
        $table = $this->getTable();
179
        //$tables = $this->getTables();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
180
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
0 ignored issues
show
Unused Code introduced by
$tables is not used, you could remove the assignment.

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

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

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

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

Loading history...
181
        $moduleDirname = $module->getVar('mod_dirname');
182
        $filename = $this->getFileName();
183
        $language = $this->getLanguage($moduleDirname, 'MA');
184
        $content = '';
185
        //foreach (array_keys($tables) as $t) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
186
            $tableId = $table/*s[$t]*/->getVar('table_id');
187
        $tableMid = $table/*s[$t]*/->getVar('table_mid');
188
        $tableName = $table/*s[$t]*/->getVar('table_name');
189
        $tableSoleName = $table/*s[$t]*/->getVar('table_solename');
190
        $tableCategory[] = $table/*s[$t]*/->getVar('table_category');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tableCategory was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableCategory = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
191
        $tableIndex = $table/*s[$t]*/->getVar('table_index');
0 ignored issues
show
Unused Code introduced by
$tableIndex is not used, you could remove the assignment.

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

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

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

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

Loading history...
192
        if (in_array(0, $tableCategory)) {
193
            $content .= $this->getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language);
194
        }
195
        //}
196
        //$content = $this->getTemplatesUserPagesListPanel($moduleDirname, $table);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
197
198
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
199
200
        return $this->renderFile();
201
    }
202
}
203