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

TemplatesUserBroken::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

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