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

TemplatesUserBroken::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3142
cc 1
eloc 17
nc 1
nop 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: TemplatesUserBroken.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserBroken.
27
 */
28
class TemplatesUserBroken 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 TemplatesUserBroken
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 getTemplatesUserBrokenFileHeader
78
    *  @param string $moduleDirname
79
    */
80
    /**
81
     * @param $moduleDirname
82
     *
83
     * @return string
84
     */
85
    private function getTemplatesUserBrokenFileHeader($moduleDirname)
86
    {
87
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
88
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'header');
89
    }
90
91
    /*
92
    *  @private function getTemplatesUserBrokenTableHead
93
    *  @param string $moduleDirname
94
    *  @param string $table
95
    *  @param string $language
96
    */
97
    /**
98
     * @param $moduleDirname
99
     * @param $table
100
     * @param $language
101
     *
102
     * @return string
103
     */
104
    private function getTemplatesUserBrokenTableHead($tableMid, $tableId, $tableAutoincrement, $language)
105
    {
106
        $th = '';
107
		$htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
108
        $fields = $this->getTableFields($tableMid, $tableId);
109
        foreach (array_keys($fields) as $f) {
110
            $fieldName = $fields[$f]->getVar('field_name');
111
            $stuFieldName = strtoupper($fieldName);
112
            if ((1 == $tableAutoincrement) || (1 == $fields[$f]->getVar('field_user'))) {
113
                $const = $htmlcode->getSmartyConst($language, $stuFieldName);
114
                $th .= $htmlcode->getHtmlTag('th', array('class' => 'center'), $const).PHP_EOL;
115
            }
116
        }
117
        $tr = $htmlcode->getHtmlTag('tr', array('class' => 'head'), $th).PHP_EOL;
118
119
        return $htmlcode->getHtmlTag('thead', array('class' => 'outer'), $tr).PHP_EOL;
120
    }
121
122
    /*
123
    *  @private function getTemplatesUserBrokenBody
124
    *  @param string $moduleDirname
125
    *  @param string $table
126
    *  @param string $language
127
    */
128
    /**
129
     * @param $moduleDirname
130
     * @param $table
131
     * @param $language
132
     *
133
     * @return string
134
     */
135
    private function getTemplatesUserBrokenBody($moduleDirname, $tableMid, $tableId, $tableName, $tableSolename, $tableAutoincrement, $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...
136
    {
137
        $ret = '';
138
		$htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
139
		$fields = $this->getTableFields($tableMid, $tableId);
140
        foreach (array_keys($fields) as $f) {
141
            $fieldName = $fields[$f]->getVar('field_name');
142
            $fieldElement = $fields[$f]->getVar('field_element');
143
            $rpFieldName = $this->getRightString($fieldName);
144
            if ((1 == $tableAutoincrement) || (1 == $fields[$f]->getVar('field_user'))) {
145
                switch ($fieldElement) {
146
                    case 9:
147
                        $span = $htmlcode->getHtmlSpan("<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\${$tableSolename}.{$rpFieldName}}>", "#<{\${$tableSolename}.{$rpFieldName}}>").PHP_EOL;
148
                        $ret .= $htmlcode->getHtmlTableData($span, 'center').PHP_EOL;
149
                        break;
150
                    case 10:
151
                        $img = $htmlcode->getHtmlImage("<{xoModuleIcons32}><{\${$tableSolename}.{$rpFieldName}}>", $tableName);
152
                        $ret .= $htmlcode->getHtmlTableData($img, 'center').PHP_EOL;
153
                        break;
154
                    case 13:
155
                        $img = $htmlcode->getHtmlImage("<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\${$tableSolename}.{$rpFieldName}}>", $tableName);
156
                        $ret .= $htmlcode->getHtmlTableData($img, 'center').PHP_EOL;
157
                        break;
158
                    default:
159
                        $ret .= $htmlcode->getHtmlTableData("<{\${$tableSolename}.{$rpFieldName}}>", 'center').PHP_EOL;
160
                        break;
161
                }
162
            }
163
        }
164
        $row = $htmlcode->getHtmlTableRow($ret, '<{cycle values="odd, even"}>').PHP_EOL;
165
        $foreach = $htmlcode->getSmartyForeach($tableSolename, $tableName, $row).PHP_EOL;
166
167
        return $htmlcode->getHtmlTableTbody($foreach).PHP_EOL;
168
    }
169
170
    /*
171
    *  @private function getTemplatesUserBrokenFileFooter
172
    *  @param string $moduleDirname
173
    */
174
    /**
175
     * @param $moduleDirname
176
     *
177
     * @return string
178
     */
179
    private function getTemplatesUserBrokenFileFooter($moduleDirname)
180
    {
181
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
182
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'footer');
183
    }
184
185
    /*
186
    *  @public function renderFile
187
    *  @param string $filename
188
    */
189
    /**
190
     * @param null
191
     *
192
     * @return bool|string
193
     */
194
    public function render()
195
    {
196
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
197
		$module = $this->getModule();
198
        $table = $this->getTable();
199
        $moduleDirname = $module->getVar('mod_dirname');
200
		$filename = $this->getFileName();
201
        $tableId = $table->getVar('table_id');
202
        $tableMid = $table->getVar('table_mid');
203
        $tableName = $table->getVar('table_name');
204
        $tableSolename = $table->getVar('table_solename');
205
        $tableAutoincrement = $table->getVar('table_autoincrement');
206
        $language = $this->getLanguage($moduleDirname, 'MA');
207
        $content = $this->getTemplatesUserBrokenFileHeader($moduleDirname).PHP_EOL;
208
        $contentTable = $this->getTemplatesUserBrokenTableHead($tableMid, $tableId, $tableAutoincrement, $language);
209
        $contentTable .= $this->getTemplatesUserBrokenBody($moduleDirname, $tableMid, $tableId, $tableName, $tableSolename, $tableAutoincrement, $language);
210
        $content .= $htmlcode->getHtmlTable($contentTable, 'table table-bordered').PHP_EOL;
211
        $content .= $this->getTemplatesUserBrokenFileFooter($moduleDirname);
212
        //
213
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
214
215
        return $this->renderFile();
216
    }
217
}
218