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

TemplatesUserSearch::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 15
nc 2
nop 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: TemplatesUserSearch.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserSearch.
27
 */
28
class TemplatesUserSearch 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 TemplatesUserSearch
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 getTemplatesUserSearchHeader
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 getTemplatesUserSearchHeader($moduleDirname, $table, $language)
90
    {
91
        $ret = <<<EOT
92
<{include file="db:{$moduleDirname}_header.tpl"}>
93
<table class="{$moduleDirname}">
94
    <thead class="outer">
95
        <tr class="head">\n
96
EOT;
97
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
98
        foreach (array_keys($fields) as $f) {
99
            $fieldName = $fields[$f]->getVar('field_name');
100
            $langStuFieldName = $language.strtoupper($fieldName);
101
            if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
102
                $ret .= <<<EOT
103
            <th class="center"><{\$smarty.const.{$langStuFieldName}}></th>\n
104
EOT;
105
            }
106
        }
107
        $ret .= <<<EOT
108
        </tr>
109
    </thead>\n
110
EOT;
111
112
        return $ret;
113
    }
114
115
    /*
116
    *  @private function getTemplatesUserSearchBody
117
    *  @param string $moduleDirname
118
    *  @param string $table
119
    *  @param string $language
120
    */
121
    /**
122
     * @param $moduleDirname
123
     * @param $table
124
     * @param $language
125
     *
126
     * @return string
127
     */
128
    private function getTemplatesUserSearchBody($moduleDirname, $table, $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...
129
    {
130
        $tableName = $table->getVar('table_name');
131
        $ret = <<<EOT
132
    <tbody>
133
        <{foreach item=list from=\${$tableName}}>
134
            <tr class="<{cycle values='odd, even'}>">\n
135
EOT;
136
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
137
        foreach (array_keys($fields) as $f) {
138
            $fieldName = $fields[$f]->getVar('field_name');
139
            $fieldElement = $fields[$f]->getVar('field_element');
140
            $rpFieldName = $this->getRightString($fieldName);
141
            if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
142
                switch ($fieldElement) {
143
                    case 9:
144
                        $ret .= <<<EOT
145
                <td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;">\t\t</span></td>\n
146
EOT;
147
                        break;
148
                    case 10:
149
                        $ret .= <<<EOT
150
                <td class="center"><img src="<{xoModuleIcons32}><{\$list.{$rpFieldName}}>" alt="{$tableName}"></td>\n
151
EOT;
152
                        break;
153
                    case 13:
154
                        $ret .= <<<EOT
155
                <td class="center"><img src="<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\$list.{$rpFieldName}}>" alt="{$tableName}"></td>\n
156
EOT;
157
                        break;
158
                    default:
159
                        $ret .= <<<EOT
160
                <td class="center"><{\$list.{$rpFieldName}}></td>\n
161
EOT;
162
                        break;
163
                }
164
            }
165
        }
166
        $ret .= <<<EOT
167
            </tr>
168
        <{/foreach}>
169
    </tbody>
170
</table>\n
171
EOT;
172
173
        return $ret;
174
    }
175
176
    /*
177
    *  @private function getTemplatesUserSearchBodyFieldnameEmpty
178
    *  @param string $moduleDirname
179
    *  @param string $table
180
    *  @param string $language
181
    */
182
    /**
183
     * @param $moduleDirname
184
     * @param $table
185
     * @param $language
186
     *
187
     * @return string
188
     */
189
    private function getTemplatesUserSearchBodyFieldnameEmpty($moduleDirname, $table, $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...
190
    {
191
        $tableName = $table->getVar('table_name');
192
        $ret = <<<EOT
193
    <tbody>
194
        <{foreach item=list from=\${$tableName}}>
195
            <tr class="<{cycle values='odd, even'}>">\n
196
EOT;
197
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
198
        foreach (array_keys($fields) as $f) {
199
            $fieldName = $fields[$f]->getVar('field_name');
200
            $fieldElement = $fields[$f]->getVar('field_element');
201
            if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
202
                switch ($fieldElement) {
203
                    case 9:
204
                        $ret .= <<<EOT
205
            <td class="center"><span style="background-color: #<{\$list.{$fieldName}}>;"></span></td>\n
206
EOT;
207
                        break;
208
                    case 13:
209
                        $ret .= <<<EOT
210
            <td class="center"><img src="<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\$list.{$fieldName}}>" alt="{$tableName}"></td>\n
211
EOT;
212
                        break;
213
                    default:
214
                        $ret .= <<<EOT
215
            <td class="center"><{\$list.{$fieldName}}></td>\n
216
EOT;
217
                        break;
218
                }
219
            }
220
        }
221
        $ret .= <<<EOT
222
            </tr>
223
        <{/foreach}>
224
    </tbody>
225
</table>\n
226
EOT;
227
228
        return $ret;
229
    }
230
231
    /*
232
    *  @private function getTemplatesUserSearchFooter
233
    *  @param string $moduleDirname
234
    */
235
    /**
236
     * @param $moduleDirname
237
     *
238
     * @return string
239
     */
240
    private function getTemplatesUserSearchFooter($moduleDirname)
241
    {
242
        $ret = <<<EOT
243
<{include file="db:{$moduleDirname}_footer.tpl"}>
244
EOT;
245
246
        return $ret;
247
    }
248
249
    /*
250
    *  @public function renderFile
251
    *  @param null
252
    */
253
    /**
254
     * @param null
255
     *
256
     * @return bool|string
257
     */
258
    public function render()
259
    {
260
        $module = $this->getModule();
261
        $table = $this->getTable();
262
        $moduleDirname = $module->getVar('mod_dirname');
263
		$filename = $this->getFileName();
264
        $tableFieldname = $table->getVar('table_fieldname');
265
        $language = $this->getLanguage($moduleDirname, 'MA');
266
        $content = $this->getTemplatesUserSearchHeader($moduleDirname, $table, $language);
267
        // Verify if table_fieldname is not empty
268
        if (!empty($tableFieldname)) {
269
            $content .= $this->getTemplatesUserSearchBody($moduleDirname, $table, $language);
270
        } else {
271
            $content .= $this->getTemplatesUserSearchBodyFieldnameEmpty($moduleDirname, $table, $language);
272
        }
273
        $content .= $this->getTemplatesUserSearchFooter($moduleDirname);
274
        //
275
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
276
277
        return $this->renderFile();
278
    }
279
}
280