Passed
Push — master ( 7331d1...59e477 )
by Goffy
05:28
created

class/Files/Templates/User/Defstyle/UserPrint.php (1 issue)

Labels
Severity
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
    /**
41
     * @var mixed
42
     */
43
    private $sc = null;
44
45
    /**
46
     * @public function constructor
47
     * @param null
48
     */
49
    public function __construct()
50
    {
51
        parent::__construct();
52
        $this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance();
53
        $this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance();
54
    }
55
56
    /**
57
     * @static function getInstance
58
     * @param null
59
     * @return UserPrint
60
     */
61
    public static function getInstance()
62
    {
63
        static $instance = false;
64
        if (!$instance) {
65
            $instance = new self();
66
        }
67
68
        return $instance;
69
    }
70
71
    /**
72
     * @public function write
73
     * @param        $module
74
     * @param        $table
75
     * @param string $filename
76
     */
77
    public function write($module, $table, $filename)
78
    {
79
        $this->setModule($module);
80
        $this->setTable($table);
81
        $this->setFileName($filename);
82
    }
83
84
    /**
85
     * @private function getTemplatesUserPrintHeader
86
     * @param string $moduleDirname
87
     * @return string
88
     */
89
    private function getTemplatesUserPrintHeader($moduleDirname)
90
    {
91
        $ret = $this->hc->getHtmlComment('Header', '',"\n");
92
        $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'header', false, '', '', "\n\n");
93
94
        return $ret;
95
    }
96
97
    /**
98
     * @private  function getTemplatesUserPrintTableThead
99
     * @param        $tableSoleName
100
     * @param        $tableAutoincrement
101
     * @param array $fields
102
     * @param string $language
103
     * @return string
104
     */
105
    private function getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language)
106
    {
107
        $th         = '';
108
        $langHeadId = \mb_strtoupper($tableSoleName) . '_ID';
109
        if (1 == $tableAutoincrement) {
110
            $lang = $this->sc->getSmartyConst($language, $langHeadId);
111
            $th   .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t");
112
        }
113
        foreach (\array_keys($fields) as $f) {
114
            $fieldName     = $fields[$f]->getVar('field_name');
115
            $rpFieldName   = $this->getRightString($fieldName);
116
            $langFieldName = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName);
117
            if (1 == $fields[$f]->getVar('field_user')) {
118
                $lang = $this->sc->getSmartyConst($language, $langFieldName);
119
                $th   .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t");
120
            }
121
        }
122
123
        $tr   = $this->hc->getHtmlTableRow($th, 'head', "\t\t");
124
        $ret  = $this->hc->getHtmlTableThead($tr, '', "\t");
125
126
        return $ret;
127
    }
128
129
    /**
130
     * @private  function getTemplatesUserPrintTableTBody
131
     * @param string $moduleDirname
132
     * @param string $tableName
133
     * @param        $tableSoleName
134
     * @param        $tableAutoincrement
135
     * @param array $fields
136
     * @return string
137
     * @internal param string $language
138
     */
139
    private function getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields)
140
    {
141
        $td = '';
142
        if (1 == $tableAutoincrement) {
143
            $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id');
144
            $td     .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t");
145
        }
146
        foreach (\array_keys($fields) as $f) {
147
            $fieldName    = $fields[$f]->getVar('field_name');
148
            $fieldElement = $fields[$f]->getVar('field_element');
149
            $rpFieldName  = $this->getRightString($fieldName);
150
            if (1 == $fields[$f]->getVar('field_user')) {
151
                switch ($fieldElement) {
152
                    case 3:
153
                    case 4:
154
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName . '_short');
155
                        $td     .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t");
156
                        break;
157
                    case 5:
158
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
159
                        $src    = $this->sc->getSmartyNoSimbol('xoModuleIcons16') . $double . '.png';
160
                        $img    = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'','');
161
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t");
162
                        break;
163
                    case 9:
164
                        // This is to be reviewed, as it was initially to style = "backgroung-color: #"
165
                        // Now with HTML5 is not supported inline style in the parameters of the HTML tag
166
                        // Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">...
167
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
168
                        $color  = "<span style='background-color:{$double};'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
169
                        $td     .= $this->hc->getHtmlTableData($color, 'center', '',"\t\t\t");
170
                        break;
171
                    case 10:
172
                        $src = $this->sc->getSmartyNoSimbol('xoModuleIcons32');
173
                        $src .= $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
174
                        $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'','');
175
                        $td  .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t");
176
                        break;
177
                    case 13:
178
                        $single = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url');
179
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
180
                        $img    = $this->hc->getHtmlTag('img', ['src' => $single . "/images/{$tableName}/" . $double, 'alt' => $tableName, 'style' => 'max-width:100px'], '', true, '', '');
181
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t");
182
                        break;
183
                    case 16:
184
                        $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
185
                        $src    = $this->sc->getSmartyNoSimbol('$modPathIcon16') . 'status' . $double . '.png';
186
                        $imgAlt = $this->sc->getSmartyDoubleVar($tableSoleName, 'status_text');
187
                        $img    = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $imgAlt, 'title' => $imgAlt], '', true,'','');
188
                        $td     .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t");
189
                        break;
190
                    default:
191
                        if (0 != $f) {
192
                            $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
193
                            $td     .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t");
194
                        }
195
                        break;
196
                }
197
            }
198
        }
199
        $cycle   = $this->sc->getSmartyNoSimbol('cycle values=\'odd, even\'');
200
        $tr      = $this->hc->getHtmlTableRow($td, $cycle, "\t\t");
201
        $foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName . '_list', $tr, '','', "\t\t");
202
        $tbody   = $this->hc->getHtmlTableTbody($foreach,'' , "\t");
203
204
        return $tbody;
205
    }
206
207
    /**
208
     * @private function getTemplatesUserPrintTable
209
     * @param string $moduleDirname
210
     * @param string $tableName
211
     * @param        $tableSoleName
212
     * @param        $tableAutoincrement
213
     * @param        $fields
214
     * @param string $language
215
     * @return string
216
     */
217
    private function getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language)
218
    {
219
        $tbody = $this->getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language);
220
        $tbody .= $this->getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields);
221
222
        return $this->hc->getHtmlTable($tbody, 'table table-bordered', '');
223
    }
224
225
    /**
226
     * @private function getTemplatesUserPrint
227
     * @param string $moduleDirname
228
     * @param string $tableName
229
     * @param        $tableSoleName
230
     * @param        $tableAutoincrement
231
     * @param        $fields
232
     * @param string $language
233
     * @return string
234
     */
235
    private function getTemplatesUserPrint($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language)
236
    {
237
        $htmlTable = $this->getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language);
238
239
        return $htmlTable;
240
    }
241
242
    /**
243
     * @private function getTemplatesUserPrintFooter
244
     * @param string $moduleDirname
245
     * @return string
246
     */
247
    private function getTemplatesUserPrintFooter($moduleDirname)
248
    {
249
        $ret = $this->hc->getHtmlComment('Footer', '', "\n");
250
        $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', false);
251
252
        return $ret;
253
    }
254
255
    /**
256
     * @public function render
257
     * @param null
258
     * @return bool|string
259
     */
260
    public function render()
261
    {
262
        $module        = $this->getModule();
263
        $table         = $this->getTable();
264
        $filename      = $this->getFileName();
265
        $moduleDirname = $module->getVar('mod_dirname');
266
        $language      = $this->getLanguage($moduleDirname, 'MA', '', false);
0 ignored issues
show
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

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