Completed
Pull Request — master (#126)
by Gino
03:40
created

TemplatesUserCategories::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 20
rs 9.4285
c 1
b 1
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: TemplatesUserCategories.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserCategories.
27
 */
28
class TemplatesUserCategories 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
     *
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /*
43
    *  @static function getInstance
44
    *  @param null
45
    */
46
    /**
47
     * @return TemplatesUserCategories
48
     */
49
    public static function getInstance()
50
    {
51
        static $instance = false;
52
        if (!$instance) {
53
            $instance = new self();
54
        }
55
56
        return $instance;
57
    }
58
59
    /*
60
    *  @public function write
61
    *  @param string $module
62
    *  @param string $table
63
    *  @param string $filename
64
    */
65
    /**
66
     * @param $module
67
     * @param $table
68
     */
69
    public function write($module, $table, $filename)
70
    {
71
        $this->setModule($module);
72
        $this->setTable($table);
73
        $this->setFileName($filename);
74
    }
75
76
    /*
77
    *  @private function getTemplatesUserCategoriesHeader
78
    *  @param string $moduleDirname
79
    *  @param string $table
80
    *  @param string $language
81
    */
82
    /**
83
     * @param $moduleDirname
84
     * @param $table
85
     * @param $language
86
     *
87
     * @return string
88
     */
89
    private function getTemplatesUserCategoriesHeader($moduleDirname)
90
    {
91
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
92
93
        return $hc->getSmartyIncludeFile($moduleDirname, 'header').PHP_EOL;
94
    }
95
96
    /*
97
    *  @private function getTemplatesUserCategoriesTable
98
    *  @param string $language
99
    */
100
    /**
101
     * @param $language
102
     *
103
     * @return string
104
     */
105
    private function getTemplatesUserCategoriesTable($moduleDirname, $tableName, $tableSolename, $language)
106
    {
107
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
108
        $single = $hc->getSmartySingleVar('table_type');
109
        $table = $this->getTemplatesAdminPagesTableThead($tableName, $language);
0 ignored issues
show
Bug introduced by
The method getTemplatesAdminPagesTableThead() does not seem to exist on object<TemplatesUserCategories>.

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...
110
        $table .= $this->getTemplatesAdminPagesTableTBody($moduleDirname, $tableName, $tableSolename, $language);
0 ignored issues
show
Bug introduced by
The method getTemplatesAdminPagesTableTBody() does not seem to exist on object<TemplatesUserCategories>.

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...
111
112
        return $hc->getHtmlTable($table, 'table table-'.$single).PHP_EOL;
113
    }
114
115
    /*
116
    *  @private function getTemplatesUserCategoriesThead
117
    *  @param string $language
118
    */
119
    /**
120
     * @param $language
121
     *
122
     * @return string
123
     */
124
    private function getTemplatesUserCategoriesThead($tableName, $language)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
125
    {
126
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
127
        $stuTableName = strtoupper($tableName);
128
        $lang = $hc->getSmartyConst($language, $stuTableName.'_TITLE');
129
        $single = $hc->getSmartySingleVar('numb_col');
130
        $th = $hc->getHtmlTableHead($lang, '', $single).PHP_EOL;
131
        $tr = $hc->getHtmlTableRow($th, 'head').PHP_EOL;
132
133
        return $hc->getHtmlTableThead($tr).PHP_EOL;
134
    }
135
136
    /*
137
    *  @private function getTemplatesUserCategoriesTbody
138
    *  @param string $moduleDirname
139
    *  @param string $table
140
    *  @param string $language
141
    */
142
    /**
143
     * @param $moduleDirname
144
     * @param $table
145
     * @param $language
146
     *
147
     * @return string
148
     */
149
    private function getTemplatesUserCategoriesTbody($moduleDirname, $tableName, $tableSolename, $language)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $language is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
150
    {
151
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
152
        $single = $hc->getSmartySingleVar('panel_type');
153
        $include = $hc->getSmartyIncludeFileListForeach($moduleDirname, $tableName, $tableSolename);
154
        $div = $hc->getHtmlDiv($include, 'panel panel-'.$single);
155
        $cont = $hc->getHtmlTableData($div).PHP_EOL;
156
        $html = $hc->getHtmlEmpty('</tr><tr>').PHP_EOL;
157
        $cont   .= $hc->getSmartyConditions($tableSoleName.'.count', ' is div by ', '$divideby', $html).PHP_EOL;
0 ignored issues
show
Bug introduced by
The variable $tableSoleName does not exist. Did you mean $tableSolename?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
158
        $foreach = $hc->getSmartyForeach($tableSoleName, $tableName, $cont).PHP_EOL;
0 ignored issues
show
Bug introduced by
The variable $tableSoleName does not exist. Did you mean $tableSolename?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
159
        $tr = $hc->getHtmlTableRow($foreach).PHP_EOL;
160
161
        return $hc->getHtmlTableTbody($tr).PHP_EOL;
162
    }
163
164
    /*
165
    *  @private function getTemplatesUserCategoriesTfoot
166
    *  @param string $moduleDirname
167
    *  @param string $table
168
    *  @param string $language
169
    */
170
    /**
171
     * @param $moduleDirname
172
     * @param $table
173
     * @param $language
174
     *
175
     * @return string
176
     */
177
    private function getTemplatesUserCategoriesTfoot()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
178
    {
179
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
180
        $td = $hc->getHtmlTableData('&nbsp;').PHP_EOL;
181
        $tr = $hc->getHtmlTableRow($td).PHP_EOL;
182
183
        return $hc->getHtmlTableTfoot($tr).PHP_EOL;
184
    }
185
186
    /*
187
    *  @private function getTemplatesUserCategories
188
    *  @param null
189
    */
190
    /**
191
     * @param null
192
     *
193
     * @return string
194
     */
195
    private function getTemplatesUserCategories($moduleDirname, $tableName, $tableSolename, $language)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
196
    {
197
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
198
        $tab = $this->getTemplatesUserCategoriesTable($moduleDirname, $tableName, $tableSolename, $language).PHP_EOL;
199
        $div = $hc->getHtmlDiv($tab, 'table-responsive').PHP_EOL;
200
201
        return $hc->getSmartyConditions($tableName, ' gt ', '0', $div, false, true).PHP_EOL;
202
    }
203
204
    /*
205
    *  @private function getTemplatesUserCategoriesPanel
206
    *  @param string $moduleDirname
207
    *  @param string $table
208
    *  @param string $language
209
    */
210
    /**
211
     * @param $moduleDirname
212
     * @param $table
213
     * @param $language
214
     *
215
     * @return string
216
     */
217
    private function getTemplatesUserCategoriesPanel($moduleDirname, $tableName, $tableSoleName, $language)
218
    {
219
        $stuTableName = strtoupper($tableName);
220
        /*$ret = <<<EOT
221
<div class="panel panel-<{\$panel_type}>">
222
    <div class="panel-heading"><{\$smarty.const.{$language}{$stuTableName}_TITLE}></div>
223
        <{foreach item={$tableSolename} from=\${$tableName}}>
224
            <div class="panel panel-body">
225
                <{include file="db:{$moduleDirname}_{$tableName}_list.tpl" {$tableSolename}=\${$tableSolename}}>
226
                <{if \${$tableSolename}.count is div by \$numb_col}>
227
                    <br />
228
                <{/if}>
229
            </div>
230
        <{/foreach}>
231
</div>\n
232
EOT;*/
233
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
234
        $incl = $hc->getSmartyIncludeFileListForeach($moduleDirname, $tableName, $tableSoleName).PHP_EOL;
235
        $html = $hc->getHtmlEmpty('<br />').PHP_EOL;
236
        $incl     .= $hc->getSmartyConditions($tableSoleName.'.count', ' is div by ', '$numb_col', $html).PHP_EOL;
237
        $const = $hc->getSmartyConst($language, $stuTableName.'_TITLE');
238
        $div = $hc->getHtmlDiv($const, 'panel-heading').PHP_EOL;
239
        $cont = $hc->getHtmlDiv($incl, 'panel panel-body').PHP_EOL;
240
        $div      .= $hc->getSmartyForeach($tableSoleName, $tableName, $cont).PHP_EOL;
241
        $panelType = $hc->getSmartySingleVar('panel_type');
242
243
        return $hc->getHtmlDiv($div, 'panel panel-'.$panelType).PHP_EOL;
244
    }
245
246
    /*
247
    *  @private function getTemplatesUserCategoriesFooter
248
    *  @param string $moduleDirname
249
    */
250
    /**
251
     * @param $moduleDirname
252
     *
253
     * @return string
254
     */
255
    private function getTemplatesUserCategoriesFooter($moduleDirname)
256
    {
257
        $hc = TDMCreateHtmlSmartyCodes::getInstance();
258
259
        return $hc->getSmartyIncludeFile($moduleDirname, 'footer');
260
    }
261
262
    /*
263
    *  @public function render
264
    *  @param string $filename
265
    */
266
    /**
267
     * @param $filename
268
     *
269
     * @return bool|string
270
     */
271
    public function render()
272
    {
273
        $module = $this->getModule();
274
        $table = $this->getTable();
275
        $filename = $this->getFileName();
276
        $moduleDirname = $module->getVar('mod_dirname');
277
        $tableName = $table->getVar('table_name');
278
        $tableSolename = $table->getVar('table_solename');
279
        $tableFieldname = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
$tableFieldname 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...
280
        $language = $this->getLanguage($moduleDirname, 'MA');
281
        $content = $this->getTemplatesUserCategoriesHeader($moduleDirname);
282
        $content .= $this->getTemplatesUserCategoriesPanel($moduleDirname, $tableName, $tableSolename, $language);
283
        /*
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...
284
        $content .= $this->getTemplatesUserCategories($moduleDirname, $tableName, $tableSolename, $language);*/
285
        $content .= $this->getTemplatesUserCategoriesFooter($moduleDirname);
286
        //
287
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
288
289
        return $this->renderFile();
290
    }
291
}
292