UserPrint::getTemplatesUserPrintFooter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\Templates\User\Defstyle;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\Files;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * modulebuilder module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops https://xoops.org 
26
 *                  Goffy https://myxoops.org
27
 *
28
 */
29
30
/**
31
 * class UserPrint.
32
 */
33
class UserPrint extends Files\CreateFile
34
{
35
    /**
36
     * @var mixed
37
     */
38
    private $hc = null;
39
    /**
40
     * @var mixed
41
     */
42
    private $sc = null;
43
44
    /**
45
     * @public function constructor
46
     * @param null
47
     */
48
    public function __construct()
49
    {
50
        parent::__construct();
51
        $this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance();
52
        $this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance();
53
    }
54
55
    /**
56
     * @static function getInstance
57
     * @param null
58
     * @return UserPrint
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /**
71
     * @public function write
72
     * @param        $module
73
     * @param        $table
74
     * @param string $filename
75
     */
76
    public function write($module, $table, $filename)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
        $this->setFileName($filename);
81
    }
82
83
    /**
84
     * @private function getTemplatesUserPrintHeader
85
     * @param string $moduleDirname
86
     * @return string
87
     */
88
    private function getTemplatesUserPrintHeader($moduleDirname)
89
    {
90
        $ret = $this->hc->getHtmlComment('Header', '', "\n");
91
        $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'header', false, '', '', "\n\n");
92
93
        return $ret;
94
    }
95
96
    /**
97
     * @private  function getTemplatesUserPrintTableThead
98
     * @param        $tableSoleName
99
     * @param        $tableAutoincrement
100
     * @param array  $fields
101
     * @param string $language
102
     * @return string
103
     */
104
    private function getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language)
105
    {
106
        $th         = '';
107
        $langHeadId = \mb_strtoupper($tableSoleName) . '_ID';
108
        if (1 == $tableAutoincrement) {
109
            $lang = $this->sc->getSmartyConst($language, $langHeadId);
110
            $th   .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t");
111
        }
112
        foreach (\array_keys($fields) as $f) {
113
            $fieldName     = $fields[$f]->getVar('field_name');
114
            $rpFieldName   = $this->getRightString($fieldName);
115
            $langFieldName = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName);
116
            if (1 == $fields[$f]->getVar('field_user')) {
117
                $lang = $this->sc->getSmartyConst($language, $langFieldName);
118
                $th   .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t");
119
            }
120
        }
121
122
        $tr  = $this->hc->getHtmlTableRow($th, 'head', "\t\t");
123
        $ret = $this->hc->getHtmlTableThead($tr, '', "\t");
124
125
        return $ret;
126
    }
127
128
    /**
129
     * @private  function getTemplatesUserPrintTableTBody
130
     * @param string $moduleDirname
131
     * @param string $tableName
132
     * @param        $tableSoleName
133
     * @param        $tableAutoincrement
134
     * @param array  $fields
135
     * @return string
136
     * @internal param string $language
137
     */
138
    private function getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields)
139
    {
140
        $td = '';
141
        if (1 == $tableAutoincrement) {
142
            $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id');
143
            $td     .= $this->hc->getHtmlTableData($double, 'center', '', "\t\t\t");
144
        }
145
        foreach (\array_keys($fields) as $f) {
146
            $fieldName    = $fields[$f]->getVar('field_name');
147
            $fieldElement = $fields[$f]->getVar('field_element');
148
            $rpFieldName  = $this->getRightString($fieldName);
149
            if (1 == $fields[$f]->getVar('field_user')) {
150
                switch ($fieldElement) {
151
                    case 3:
152
                    case 4:
153
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName . '_short');
154
                        $td     .= $this->hc->getHtmlTableData($double, 'center', '', "\t\t\t");
155
                        break;
156
                    case 5:
157
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
158
                        $src    = $this->sc->getSmartyNoSimbol('xoModuleIcons16') . $double . '.png';
159
                        $img    = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true, '', '');
160
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '', "\t\t\t");
161
                        break;
162
                    case 9:
163
                        // This is to be reviewed, as it was initially to style = "backgroung-color: #"
164
                        // Now with HTML5 is not supported inline style in the parameters of the HTML tag
165
                        // Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">...
166
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
167
                        $color  = "<span style='background-color:{$double};'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
168
                        $td     .= $this->hc->getHtmlTableData($color, 'center', '', "\t\t\t");
169
                        break;
170
                    case 10:
171
                        $src = $this->sc->getSmartyNoSimbol('xoModuleIcons32');
172
                        $src .= $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
173
                        $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true, '', '');
174
                        $td  .= $this->hc->getHtmlTableData($img, 'center', '', "\t\t\t");
175
                        break;
176
                    case 13:
177
                        $single = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url');
178
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
179
                        $img    = $this->hc->getHtmlTag('img', ['src' => $single . "/images/{$tableName}/" . $double, 'alt' => $tableName, 'style' => 'max-width:100px'], '', true, '', '');
180
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '', "\t\t\t");
181
                        break;
182
                    case 16:
183
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
184
                        $src    = $this->sc->getSmartyNoSimbol('$modPathIcon16') . 'status' . $double . '.png';
185
                        $imgAlt = $this->sc->getSmartyDoubleVar($tableSoleName, 'status_text');
186
                        $img    = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $imgAlt, 'title' => $imgAlt], '', true, '', '');
187
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '', "\t\t\t");
188
                        break;
189
                    default:
190
                        if (0 != $f) {
191
                            $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
192
                            $td     .= $this->hc->getHtmlTableData($double, 'center', '', "\t\t\t");
193
                        }
194
                        break;
195
                }
196
            }
197
        }
198
        $cycle   = $this->sc->getSmartyNoSimbol('cycle values=\'odd, even\'');
199
        $tr      = $this->hc->getHtmlTableRow($td, $cycle, "\t\t");
200
        $foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName . '_list', $tr, '', '', "\t\t");
201
        $tbody   = $this->hc->getHtmlTableTbody($foreach, '', "\t");
202
203
        return $tbody;
204
    }
205
206
    /**
207
     * @private function getTemplatesUserPrintTable
208
     * @param string $moduleDirname
209
     * @param string $tableName
210
     * @param        $tableSoleName
211
     * @param        $tableAutoincrement
212
     * @param        $fields
213
     * @param string $language
214
     * @return string
215
     */
216
    private function getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language)
217
    {
218
        $tbody = $this->getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language);
219
        $tbody .= $this->getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields);
220
221
        return $this->hc->getHtmlTable($tbody, 'table table-bordered', '');
222
    }
223
224
    /**
225
     * @private function getTemplatesUserPrint
226
     * @param string $moduleDirname
227
     * @param string $tableName
228
     * @param        $tableSoleName
229
     * @param        $tableAutoincrement
230
     * @param        $fields
231
     * @param string $language
232
     * @return string
233
     */
234
    private function getTemplatesUserPrint($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language)
235
    {
236
        $htmlTable = $this->getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language);
237
238
        return $htmlTable;
239
    }
240
241
    /**
242
     * @private function getTemplatesUserPrintFooter
243
     * @param string $moduleDirname
244
     * @return string
245
     */
246
    private function getTemplatesUserPrintFooter($moduleDirname)
247
    {
248
        $ret = $this->hc->getHtmlComment('Footer', '', "\n");
249
        $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', false);
250
251
        return $ret;
252
    }
253
254
    /**
255
     * @public function render
256
     * @param null
257
     * @return bool|string
258
     */
259
    public function render()
260
    {
261
        $module        = $this->getModule();
262
        $table         = $this->getTable();
263
        $filename      = $this->getFileName();
264
        $moduleDirname = $module->getVar('mod_dirname');
265
        $language      = $this->getLanguage($moduleDirname, 'MA', '', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $addFq of XoopsModules\Modulebuild...eateFile::getLanguage(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

265
        $language      = $this->getLanguage($moduleDirname, 'MA', '', /** @scrutinizer ignore-type */ false);
Loading history...
266
        $fields        = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order');
267
        $content       = $this->getTemplatesUserPrintHeader($moduleDirname);
268
        $content       .= $this->getTemplatesUserPrint($moduleDirname, $table->getVar('table_name'), $table->getVar('table_solename'), $table->getVar('table_autoincrement'), $fields, $language);
269
        $content       .= $this->getTemplatesUserPrintFooter($moduleDirname);
270
271
        $this->create($moduleDirname, 'templates', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
272
273
        return $this->renderFile();
274
    }
275
}
276