Passed
Push — master ( 09f9f5...606015 )
by Michael
16s
created

TemplatesUserPages   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 2
cbo 2
dl 0
loc 213
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 9 2
A write() 0 6 1
A getTemplatesUserPagesHeader() 0 5 1
A getTemplatesUserPagesTable() 0 10 1
A getTemplatesUserPagesTableThead() 0 11 1
A getTemplatesUserPagesTableTbody() 0 14 1
A getTemplatesUserPagesTableTfoot() 0 8 1
A getTemplatesUserPages() 0 8 1
A getTemplatesUserPagesFooter() 0 5 1
A render() 0 17 1
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: TemplatesUserPages.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserPages.
27
 */
28
class TemplatesUserPages 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
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
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 TemplatesUserPages
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 getTemplatesUserPagesHeader
78
    *  @param string $moduleDirname
79
    */
80
    /**
81
     * @param $moduleDirname
82
     *
83
     * @return string
84
     */
85
    private function getTemplatesUserPagesHeader($moduleDirname)
86
    {
87
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
88
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'header').PHP_EOL;
89
    }
90
91
    /*
92
    *  @private function getTemplatesUserPagesTable
93
    *  @param string $moduleDirname
94
    *  @param string $tableName
95
    *  @param string $fields
0 ignored issues
show
Bug introduced by
There is no parameter named $fields. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
96
    *  @param string $language
97
    *  @return string
98
    */
99
    private function getTemplatesUserPagesTable($moduleDirname, $tableName, $tableSolename, $language)
100
    {
101
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
102
		$tbody = $this->getTemplatesUserPagesTableThead($tableName, $language);
103
        $tbody .= $this->getTemplatesUserPagesTableTbody($moduleDirname, $tableName, $tableSolename, $language);
104
        $tbody .= $this->getTemplatesUserPagesTableTfoot();
105
        $single = $htmlcode->getSmartySingleVar('table_type');
106
107
        return $htmlcode->getHtmlTable($tbody, 'table table-'.$single).PHP_EOL;
108
    }
109
110
    /*
111
    *  @private function getTemplatesUserPagesThead
112
    *  @param string $language
113
    */
114
    /**
115
     * @param $language
116
     *
117
     * @return string
118
     */
119
    private function getTemplatesUserPagesTableThead($tableName, $language)
120
    {
121
        $stuTableName = strtoupper($tableName);
122
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
123
		$single = $htmlcode->getSmartySingleVar('divideby');
124
        $lang = $htmlcode->getSmartyConst($language, $stuTableName.'_TITLE');
125
        $th = $htmlcode->getHtmlTableHead($lang, '', $single).PHP_EOL;
126
        $tr = $htmlcode->getHtmlTableRow($th, 'head').PHP_EOL;
127
128
        return $htmlcode->getHtmlTableThead($tr).PHP_EOL;
129
    }
130
131
    /*
132
    *  @private function getTemplatesUserPagesTbody
133
    *  @param string $moduleDirname
134
    *  @param string $table
135
    *  @param string $language
136
    */
137
    /**
138
     * @param $moduleDirname
139
     * @param $table
140
     * @param $language
141
     *
142
     * @return string
143
     */
144
    private function getTemplatesUserPagesTableTbody($moduleDirname, $tableName, $tableSolename, $language)
0 ignored issues
show
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...
145
    {
146
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
147
		$single = $htmlcode->getSmartySingleVar('panel_type');
148
        $include = $htmlcode->getSmartyIncludeFileListForeach($moduleDirname, $tableName, $tableSolename);
149
        $div = $htmlcode->getHtmlDiv($include, 'panel panel-'.$single);
150
        $cont = $htmlcode->getHtmlTableData($div).PHP_EOL;
151
        $html = $htmlcode->getHtmlEmpty('</tr><tr>').PHP_EOL;
152
        $cont   .= $htmlcode->getSmartyConditions($tableSolename.'.count', ' is div by ', '$divideby', $html).PHP_EOL;
153
        $foreach = $htmlcode->getSmartyForeach($tableSolename, $tableName, $cont).PHP_EOL;
154
        $tr = $htmlcode->getHtmlTableRow($foreach).PHP_EOL;
155
156
        return $htmlcode->getHtmlTableTbody($tr).PHP_EOL;
157
    }
158
159
    /*
160
    *  @private function getTemplatesUserPagesTfoot
161
    *  @param string $moduleDirname
162
    *  @param string $table
163
    *  @param string $language
164
    */
165
    /**
166
     * @param $moduleDirname
167
     * @param $table
168
     * @param $language
169
     *
170
     * @return string
171
     */
172
    private function getTemplatesUserPagesTableTfoot()
173
    {
174
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
175
		$td = $htmlcode->getHtmlTableData('&nbsp;').PHP_EOL;
176
        $tr = $htmlcode->getHtmlTableRow($td).PHP_EOL;
177
178
        return $htmlcode->getHtmlTableTfoot($tr).PHP_EOL;
179
    }
180
181
    /*
182
    *  @private function getTemplatesUserPages
183
    *  @param string $language
184
    */
185
    /**
186
     * @param $language
187
     *
188
     * @return string
189
     */
190
    private function getTemplatesUserPages($moduleDirname, $tableName, $tableSolename, $language)
191
    {
192
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
193
		$table = $this->getTemplatesUserPagesTable($moduleDirname, $tableName, $tableSolename, $language).PHP_EOL;
194
        $div = $htmlcode->getHtmlDiv($table, 'table-responsive').PHP_EOL;
195
196
        return $htmlcode->getSmartyConditions($tableName, ' gt ', '0', $div, false, true).PHP_EOL;
197
    }
198
199
    /*
200
    *  @private function getTemplatesUserPagesFooter
201
    *  @param string $moduleDirname
202
    */
203
    /**
204
     * @param $moduleDirname
205
     *
206
     * @return string
207
     */
208
    private function getTemplatesUserPagesFooter($moduleDirname)
209
    {
210
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
211
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'footer');
212
    }
213
214
    /*
215
    *  @public function renderFile
216
    *  @param null
217
    */
218
    /**
219
     * @param null
220
     *
221
     * @return bool|string
222
     */
223
    public function render()
224
    {
225
        $module = $this->getModule();
226
        $table = $this->getTable();
227
        $moduleDirname = $module->getVar('mod_dirname');
228
		$filename = $this->getFileName();
229
        $tableName = $table->getVar('table_name');
230
        $tableSolename = $table->getVar('table_solename');
231
        $language = $this->getLanguage($moduleDirname, 'MA');
232
        $content = $this->getTemplatesUserPagesHeader($moduleDirname);
233
        $content      .= $this->getTemplatesUserPages($moduleDirname, $tableName, $tableSolename, $language);
234
        $content      .= $this->getTemplatesUserPagesFooter($moduleDirname);
235
        //
236
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
237
238
        return $this->renderFile();
239
    }
240
}
241