PagesList::getTemplatesUserPagesListPanel()   C
last analyzed

Complexity

Conditions 15
Paths 160

Size

Total Lines 76
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
eloc 62
nc 160
nop 6
dl 0
loc 76
rs 5.4166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace XoopsModules\Tdmcreate\Files\Templates\User;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: TemplatesUserPagesList.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * class PagesList.
30
 */
31
class PagesList extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     *  @static function getInstance
44
     *  @param null
45
     * @return PagesList
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
     * @param $tables
63
     */
64
    public function write($module, $table, $tables, $filename)
65
    {
66
        $this->setModule($module);
67
        $this->setTable($table);
68
        $this->setTables($tables);
69
        $this->setFileName($filename);
70
    }
71
72
    /**
73
     * @private function getTemplatesUserPagesListPanel
74
     * @param string $moduleDirname
75
     * @param        $tableId
76
     * @param        $tableMid
77
     * @param        $tableName
78
     * @param        $tableSoleName
79
     * @param        $language
80
     * @return string
81
     */
82
    private function getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language)
83
    {
84
        $hc = Tdmcreate\Files\CreateHtmlSmartyCodes::getInstance();
85
        $fields = $this->getTableFields($tableMid, $tableId);
86
        $ret = '';
87
        $retNumb = '';
88
        foreach (array_keys($fields) as $f) {
89
            $fieldElement = $fields[$f]->getVar('field_element');
90
            if (1 == $fields[$f]->getVar('field_user')) {
91
                if (1 == $fields[$f]->getVar('field_thead')) {
92
                    switch ($fieldElement) {
93
                        default:
94
                        case 2:
95
                            $fieldName = $fields[$f]->getVar('field_name');
96
                            $rpFieldName = $this->getRightString($fieldName);
97
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
98
                            $retNumb = $hc->getHtmlHNumb($doubleVar, '3', 'panel-title');
99
                            break;
100
                    }
101
                }
102
            }
103
        }
104
        $ret .= $hc->getHtmlDiv($retNumb, 'panel-heading') . PHP_EOL;
105
        $retElem = '';
106
        foreach (array_keys($fields) as $f) {
107
            $fieldElement = $fields[$f]->getVar('field_element');
108
            if (1 == $fields[$f]->getVar('field_user')) {
109
                if (1 == $fields[$f]->getVar('field_tbody')) {
110
                    switch ($fieldElement) {
111
                        default:
112
                        case 3:
113
                        case 4:
114
                            $fieldName = $fields[$f]->getVar('field_name');
115
                            $rpFieldName = $this->getRightString($fieldName);
116
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
117
                            $retElem .= $hc->getHtmlSpan($doubleVar, 'col-sm-9 justify') . PHP_EOL;
118
                            break;
119
                        case 10:
120
                            $fieldName = $fields[$f]->getVar('field_name');
121
                            $rpFieldName = $this->getRightString($fieldName);
122
                            $singleVar = $hc->getSmartySingleVar('xoops_icons32_url');
123
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
124
                            $img = $hc->getHtmlImage($singleVar . '/' . $doubleVar, (string)$tableName);
125
                            $retElem .= $hc->getHtmlSpan($img, 'col-sm-3') . PHP_EOL;
126
                            unset($img);
127
                            break;
128
                        case 13:
129
                            $fieldName = $fields[$f]->getVar('field_name');
130
                            $rpFieldName = $this->getRightString($fieldName);
131
                            $singleVar = $hc->getSmartySingleVar($moduleDirname . '_upload_url');
132
                            $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
133
                            $img = $hc->getHtmlImage($singleVar . "/images/{$tableName}/" . $doubleVar, (string)$tableName);
134
                            $retElem .= $hc->getHtmlSpan($img, 'col-sm-3') . PHP_EOL;
135
                            unset($img);
136
                            break;
137
                    }
138
                }
139
            }
140
        }
141
        $ret .= $hc->getHtmlDiv($retElem, 'panel-body') . PHP_EOL;
142
        $retFoot = '';
143
        foreach (array_keys($fields) as $f) {
144
            if (1 == $fields[$f]->getVar('field_user')) {
145
                if (1 == $fields[$f]->getVar('field_tfoot')) {
146
                    $fieldName = $fields[$f]->getVar('field_name');
147
                    $rpFieldName = $this->getRightString($fieldName);
148
                    $langConst = mb_strtoupper($tableSoleName) . '_' . mb_strtoupper($rpFieldName);
149
                    $lang = $hc->getSmartyConst($language, $langConst);
150
                    $doubleVar = $hc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
151
                    $retFoot .= $hc->getHtmlSpan($lang . ': ' . $doubleVar, 'block-pie justify') . PHP_EOL;
152
                }
153
            }
154
        }
155
        $ret .= $hc->getHtmlDiv($retFoot, 'panel-foot') . PHP_EOL;
156
157
        return $ret;
158
    }
159
160
    /**
161
     *  @public function render
162
     *  @param null
163
     * @return bool|string
164
     */
165
    public function render()
166
    {
167
        $module = $this->getModule();
168
        $table = $this->getTable();
169
        //$tables = $this->getTables();
170
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
0 ignored issues
show
Unused Code introduced by
The assignment to $tables is dead and can be removed.
Loading history...
171
        $moduleDirname = $module->getVar('mod_dirname');
172
        $filename = $this->getFileName();
173
        $language = $this->getLanguage($moduleDirname, 'MA');
174
        $content = '';
175
        //foreach (array_keys($tables) as $t) {
176
        $tableId = $table/*s[$t]*/->getVar('table_id');
177
        $tableMid = $table/*s[$t]*/->getVar('table_mid');
178
        $tableName = $table/*s[$t]*/->getVar('table_name');
179
        $tableSoleName = $table/*s[$t]*/->getVar('table_solename');
180
        $tableCategory[] = $table/*s[$t]*/->getVar('table_category');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$tableCategory was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableCategory = array(); before regardless.
Loading history...
181
        $tableIndex = $table/*s[$t]*/->getVar('table_index');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableIndex is dead and can be removed.
Loading history...
182
        if (in_array(0, $tableCategory)) {
183
            $content .= $this->getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language);
184
        }
185
        //}
186
        //$content = $this->getTemplatesUserPagesListPanel($moduleDirname, $table);
187
188
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
189
190
        return $this->renderFile();
191
    }
192
}
193