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

Files/Templates/Admin/TemplatesAdminBroken.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\Templates\Admin;
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 TemplatesAdminBroken.
32
 */
33
class TemplatesAdminBroken 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 TemplatesAdminBroken
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 string $module
74
     * @param $tables
75
     * @param        $filename
76
     */
77
    public function write($module, $tables, $filename)
78
    {
79
        $this->setModule($module);
80
        $this->setTables($tables);
81
        $this->setFileName($filename);
82
    }
83
84
    /**
85
     * @private function getTemplatesAdminBrokenHeader
86
     * @param string $moduleDirname
87
     * @return string
88
     */
89
    private function getTemplatesAdminBrokenHeader($moduleDirname)
90
    {
91
        $ret = $this->hc->getHtmlComment('Header', '',"\n");
92
        $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'header', true, '', '', "\n\n");
93
94
        return $ret;
95
    }
96
97
    /**
98
     * @private  function getTemplatesAdminBrokenTableThead
99
     * @param string $language
100
     * @param $t
101
     * @return string
102
     */
103
    private function getTemplatesAdminBrokenTableThead($language, $t)
104
    {
105
        $th   = '';
106
        $lang = $this->sc->getSmartyConst($language, 'BROKEN_TABLE');
107
        $th   .= $this->hc->getHtmlTableHead($lang, 'center', '', $t . "\t\t");
108
        $lang = $this->sc->getSmartyConst($language, 'BROKEN_MAIN');
109
        $th   .= $this->hc->getHtmlTableHead($lang, 'center', '', $t . "\t\t");
110
        $lang = $this->sc->getSmartyConst($language, 'FORM_ACTION');
111
        $th   .= $this->hc->getHtmlTableHead($lang, 'center width5', '', $t . "\t\t");
112
        $tr   = $this->hc->getHtmlTableRow($th, 'head', $t . "\t");
113
        $ret  = $this->hc->getHtmlTableThead($tr, '', $t);
114
115
        return $ret;
116
    }
117
118
    /**
119
     * @private  function getTemplatesAdminBrokenTableTBody
120
     * @param string $tableName
121
     * @param        $tableSoleName
122
     * @param $t
123
     * @return string
124
     * @internal param string $language
125
     */
126
    private function getTemplatesAdminBrokenTableTBody($tableName, $tableSoleName, $t)
127
    {
128
        $td        = '';
129
        $doubleKey = $this->sc->getSmartyDoubleVar($tableSoleName, 'key');
130
        $doubleVal = $this->sc->getSmartyDoubleVar($tableSoleName, 'keyval');
131
132
        $double  = $this->sc->getSmartyDoubleVar($tableSoleName, 'table');
133
        $td      .= $this->hc->getHtmlTableData($double, 'center', '', $t . "\t\t");
134
        $double  = $this->sc->getSmartyDoubleVar($tableSoleName, 'main');
135
        $td      .= $this->hc->getHtmlTableData($double, 'center', '', $t . "\t\t");
136
        $lang    = $this->sc->getSmartyConst('', '_EDIT');
137
        $src     = $this->sc->getSmartyNoSimbol('xoModuleIcons16 edit.png');
138
        $img     = $this->hc->getHtmlImage($src, $tableName, '', '', '');
139
        $anchor  = $this->hc->getHtmlAnchor($tableName . ".php?op=edit&amp;{$doubleKey}=" . $doubleVal, $img, $lang, '', '', '', $t . "\t\t\t", "\n");
140
        $lang    = $this->sc->getSmartyConst('', '_DELETE');
141
        $src     = $this->sc->getSmartyNoSimbol('xoModuleIcons16 delete.png');
142
        $img     = $this->hc->getHtmlImage($src, $tableName, '', '', '');
143
        $anchor  .= $this->hc->getHtmlAnchor($tableName . ".php?op=delete&amp;{$doubleKey}=" . $doubleVal, $img, $lang, '', '', '', $t . "\t\t\t", "\n");
144
        $td      .= $this->hc->getHtmlTableData($anchor, 'center width5', '', $t . "\t\t", "\n", true);
145
        $cycle   = $this->sc->getSmartyNoSimbol('cycle values=\'odd, even\'');
146
        $tr      = $this->hc->getHtmlTableRow($td, $cycle, $t . "\t");
147
        $foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName . '_list', $tr, '','', $t . "\t");
148
        $tbody   = $this->hc->getHtmlTableTbody($foreach,'' , $t);
149
150
        return $tbody;
151
    }
152
153
    /**
154
     * @private function getTemplatesAdminBrokenTable
155
     * @param string $tableName
156
     * @param        $tableSoleName
157
     * @param string $language
158
     * @return string
159
     */
160
    private function getTemplatesAdminBrokenTable($tableName, $tableSoleName, $language)
161
    {
162
        $tbody = $this->getTemplatesAdminBrokenTableThead($language, "\t\t");
163
        $tbody .= $this->getTemplatesAdminBrokenTableTBody($tableName, $tableSoleName, "\t\t");
164
        $ret   = $this->hc->getHtmlTable($tbody, 'table table-bordered', "\t");
165
166
        return $ret;
167
    }
168
169
    /**
170
     * @private function getTemplatesAdminBrokenList
171
     * @param $table
172
     * @param string $language
173
     * @param string $t
174
     * @return string
175
     */
176
    private function getTemplatesAdminBrokenList($table, $language, $t = '')
177
    {
178
        $tableName     = $table->getVar('table_name');
179
        $tableSoleName = $table->getVar('table_solename');
180
        $ucfTableName  = \ucfirst($tableName);
181
        $double    = $this->sc->getSmartySingleVar($tableName . '_result');
182
        $ret       = $this->hc->getHtmlHNumb($double, 3, '');
183
        $htmlTable = $this->getTemplatesAdminBrokenTable($tableName, $tableSoleName, $language);
184
        $htmlTable .= $this->hc->getHtmlDiv('&nbsp;', 'clear', $t, "\n", false);
185
        $single    = $this->sc->getSmartySingleVar('pagenav');
186
        $div       = $this->hc->getHtmlDiv($single, 'xo-pagenav floatright', $t . "\t", "\n", false);
187
        $div       .= $this->hc->getHtmlDiv('', 'clear spacer', $t . "\t" , "\n", false);
188
        $htmlTable .= $this->sc->getSmartyConditions('pagenav', '', '', $div, '', '', '', $t );
189
        $noData    = $this->sc->getSmartySingleVar('nodata' . $ucfTableName, $t . "\t\t");
190
        $src       = $this->sc->getSmartyNoSimbol('xoModuleIcons32 button_ok.png');
191
        $noData    .= $this->hc->getHtmlImage($src, $tableName,'','',"\n");
192
        $div       = $this->hc->getHtmlDiv($noData, '', $t . "\t", "\n", true);
193
        $div       .= $this->hc->getHtmlDiv('', 'clear spacer', $t . "\t" , "\n", false);
194
        $div       .= $this->hc->getHtmlBr('2', '', $t . "\t");
195
        $contElse  = $this->sc->getSmartyConditions('nodata' . $ucfTableName, '', '', $div, false, '', '', $t);
196
        $ret       .= $this->sc->getSmartyConditions($tableName . '_count', '', '', $htmlTable, $contElse);
197
        $ret       .= $this->hc->getHtmlBr('3');
198
199
        return $ret;
200
    }
201
202
    /**
203
     * @private function getTemplatesAdminBrokenFooter
204
     * @param string $moduleDirname
205
     * @return string
206
     */
207
    private function getTemplatesAdminBrokenFooter($moduleDirname)
208
    {
209
        $single = $this->sc->getSmartySingleVar('error');
210
        $strong = $this->hc->getHtmlTag('strong', [], $single, false, '', '');
211
        $div    = $this->hc->getHtmlDiv($strong, 'errorMsg', "\t", "\n");
212
        $ret    = $this->sc->getSmartyConditions('error', '', '', $div);
213
        $ret    .= $this->hc->getHtmlEmpty('', '', "\n");
214
        $ret    .= $this->hc->getHtmlComment('Footer', '', "\n");
215
        $ret    .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', true);
216
217
        return $ret;
218
    }
219
220
    /**
221
     * @public function render
222
     * @param null
223
     * @return bool|string
224
     */
225
    public function render()
226
    {
227
        $module        = $this->getModule();
228
        $tables         = $this->getTables();
229
        $filename      = $this->getFileName();
230
        $moduleDirname = $module->getVar('mod_dirname');
231
        $language      = $this->getLanguage($moduleDirname, 'AM', '', 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

231
        $language      = $this->getLanguage($moduleDirname, 'AM', '', /** @scrutinizer ignore-type */ false);
Loading history...
232
        $content       = $this->getTemplatesAdminBrokenHeader($moduleDirname);
233
        foreach ($tables as $table) {
234
            if (1 === (int)$table->getVar('table_broken')) {
235
                $content .= $this->getTemplatesAdminBrokenList($table, $language, "\t");
236
            }
237
        }
238
        $content .= $this->getTemplatesAdminBrokenFooter($moduleDirname);
239
240
        $this->create($moduleDirname, 'templates/admin', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
241
242
        return $this->renderFile();
243
    }
244
}
245