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

class/Files/Templates/User/Defstyle/PagesList.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\{
7
    Files,
8
    Constants
9
};
10
11
/*
12
 You may not change or alter any portion of this comment or credits
13
 of supporting developers from this source code or any supporting source code
14
 which is considered copyrighted (c) material of the original comment or credit authors.
15
16
 This program is distributed in the hope that it will be useful,
17
 but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
 */
20
/**
21
 * modulebuilder module.
22
 *
23
 * @copyright       XOOPS Project (https://xoops.org)
24
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
25
 *
26
 * @since           2.5.0
27
 *
28
 * @author          Txmod Xoops https://xoops.org 
29
 *                  Goffy https://myxoops.org
30
 *
31
 */
32
33
/**
34
 * class PagesList.
35
 */
36
class PagesList extends Files\CreateFile
37
{
38
    /**
39
     * @var mixed
40
     */
41
    private $hc = null;
42
43
    /**
44
     * @var mixed
45
     */
46
    private $sc = null;
47
48
    /**
49
     * @public function constructor
50
     * @param null
51
     */
52
    public function __construct()
53
    {
54
        parent::__construct();
55
        $this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance();
56
        $this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance();
57
    }
58
59
    /**
60
     * @static function getInstance
61
     * @param null
62
     * @return PagesList
63
     */
64
    public static function getInstance()
65
    {
66
        static $instance = false;
67
        if (!$instance) {
68
            $instance = new self();
69
        }
70
71
        return $instance;
72
    }
73
74
    /**
75
     * @public function write
76
     * @param        $module
77
     * @param        $table
78
     * @param string $filename
79
     * @param        $tables
80
     */
81
    public function write($module, $table, $tables, $filename)
82
    {
83
        $this->setModule($module);
84
        $this->setTable($table);
85
        $this->setTables($tables);
86
        $this->setFileName($filename);
87
    }
88
89
    /**
90
     * @private function getTemplatesUserPagesListPanel
91
     * @param string $moduleDirname
92
     * @param        $tableId
93
     * @param        $tableMid
94
     * @param        $tableName
95
     * @param        $tableSoleName
96
     * @param        $language
97
     * @return string
98
     */
99
    private function getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language)
100
    {
101
        $fields  = $this->getTableFields($tableMid, $tableId);
102
        $ret     = '';
103
        $retNumb = '';
104
        foreach (\array_keys($fields) as $f) {
105
            $fieldElement = $fields[$f]->getVar('field_element');
106
            if (1 == $fields[$f]->getVar('field_user')) {
107
                if (1 == $fields[$f]->getVar('field_ihead')) {
108
                    switch ($fieldElement) {
109
                        default:
110
                        //case 2:
111
                            $fieldName   = $fields[$f]->getVar('field_name');
112
                            $rpFieldName = $this->getRightString($fieldName);
113
                            $doubleVar   = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
114
                            $retNumb     .= $this->hc->getHtmlHNumb($doubleVar, '3', 'panel-title', "\t");
115
                            break;
116
                    }
117
                }
118
            }
119
        }
120
        $ret     .= $this->hc->getHtmlDiv($retNumb, 'panel-heading');
121
        $retElem   = '';
122
        $fieldId   = '';
123
        $keyDouble = '';
124
        foreach (\array_keys($fields) as $f) {
125
            if (0 == $f) {
126
                $fieldId = $fields[$f]->getVar('field_name');
127
                $keyDouble = $this->sc->getSmartyDoubleVar($tableSoleName, $fieldId);
128
            }
129
            $fieldElement = $fields[$f]->getVar('field_element');
130
            if (1 == $fields[$f]->getVar('field_user')) {
131
                if (1 == $fields[$f]->getVar('field_ibody')) {
132
                    switch ($fieldElement) {
133
                        default:
134
                        //case 3:
135
                        //case 4:
136
                            $fieldName   = $fields[$f]->getVar('field_name');
137
                            $rpFieldName = $this->getRightString($fieldName);
138
                            $doubleVar   = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
139
                            $retElem     .= $this->hc->getHtmlSpan($doubleVar, 'col-sm-9 justify', "\t");
140
                            break;
141
                        case Constants::FIELD_ELE_IMAGELIST:
142
                            $fieldName   = $fields[$f]->getVar('field_name');
143
                            $rpFieldName = $this->getRightString($fieldName);
144
                            $singleVar   = $this->sc->getSmartySingleVar('xoops_icons32_url');
145
                            $doubleVar   = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
146
                            $img         = $this->hc->getHtmlImage($singleVar . '/' . $doubleVar, (string)$tableName);
147
                            $retElem     .= $this->hc->getHtmlSpan($img, 'col-sm-3', "\t");
148
                            unset($img);
149
                            break;
150
                        case Constants::FIELD_ELE_UPLOADIMAGE:
151
                            $fieldName   = $fields[$f]->getVar('field_name');
152
                            $rpFieldName = $this->getRightString($fieldName);
153
                            $singleVar   = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url');
154
                            $doubleVar   = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
155
                            $img         = $this->hc->getHtmlImage($singleVar . "/images/{$tableName}/" . $doubleVar, (string)$tableName);
156
                            $retElem     .= $this->hc->getHtmlSpan($img, 'col-sm-3',"\t");
157
                            unset($img);
158
                            break;
159
                    }
160
                }
161
            }
162
        }
163
164
165
        $ret     .= $this->hc->getHtmlDiv($retElem, 'panel-body');
166
        $retFoot = '';
167
        foreach (\array_keys($fields) as $f) {
168
            if (1 == $fields[$f]->getVar('field_user')) {
169
                if (1 == $fields[$f]->getVar('field_ifoot')) {
170
                    $fieldName   = $fields[$f]->getVar('field_name');
171
                    $rpFieldName = $this->getRightString($fieldName);
172
                    $langConst   = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName);
173
                    $lang        = $this->sc->getSmartyConst($language, $langConst);
174
                    $doubleVar   = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
175
                    $retFoot     .= $this->hc->getHtmlSpan($lang . ': ' . $doubleVar, 'block-pie justify',"\t");
176
                }
177
            }
178
        }
179
        $lang        = $this->sc->getSmartyConst($language, 'DETAILS');
180
        $anchor =  $this->hc->getHtmlAnchor($tableName . ".php?op=show&amp;{$fieldId}=" . $keyDouble, $lang, $lang, '', 'btn btn-primary', '', '', '');
181
        $retFoot     .= $this->hc->getHtmlSpan($anchor, 'col-sm-12',"\t");
182
        $ret .= $this->hc->getHtmlDiv($retFoot, 'panel-foot');
183
184
        return $ret;
185
    }
186
187
    /**
188
     * @public function render
189
     * @param null
190
     * @return bool|string
191
     */
192
    public function render()
193
    {
194
        $module = $this->getModule();
195
        $table  = $this->getTable();
196
        $moduleDirname = $module->getVar('mod_dirname');
197
        $filename      = $this->getFileName();
198
        $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

198
        $language      = $this->getLanguage($moduleDirname, 'MA', '', /** @scrutinizer ignore-type */ false);
Loading history...
199
        $content       = '';
200
        $tableId         = $table->getVar('table_id');
201
        $tableMid        = $table->getVar('table_mid');
202
        $tableName       = $table->getVar('table_name');
203
        $tableSoleName   = $table->getVar('table_solename');
204
        $tableCategory[] = $table->getVar('table_category');
205
        if (\in_array(0, $tableCategory)) {
206
            $content .= $this->getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language);
207
        }
208
209
        $this->create($moduleDirname, 'templates', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
210
211
        return $this->renderFile();
212
    }
213
}
214