Passed
Push — master ( d71037...1531a2 )
by Goffy
03:41
created

PagesList::getElement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 2
nop 6
dl 0
loc 21
rs 9.7333
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 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 */
28
29
/**
30
 * class PagesList.
31
 */
32
class PagesList extends Files\CreateFile
33
{
34
    /**
35
     * @public function constructor
36
     * @param null
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * @static function getInstance
45
     * @param null
46
     * @return PagesList
47
     */
48
    public static function getInstance()
49
    {
50
        static $instance = false;
51
        if (!$instance) {
52
            $instance = new self();
53
        }
54
55
        return $instance;
56
    }
57
58
    /**
59
     * @public function write
60
     * @param string $module
61
     * @param string $table
62
     * @param string $filename
63
     * @param        $tables
64
     */
65
    public function write($module, $table, $tables, $filename)
66
    {
67
        $this->setModule($module);
68
        $this->setTable($table);
69
        $this->setTables($tables);
70
        $this->setFileName($filename);
71
    }
72
73
    /**
74
     * @private function getTemplatesUserPagesListPanel
75
     * @param string $moduleDirname
76
     * @param        $tableId
77
     * @param        $tableMid
78
     * @param        $tableName
79
     * @param        $tableSoleName
80
     * @param        $language
81
     * @return string
82
     */
83
    private function getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language)
84
    {
85
        $hc      = Modulebuilder\Files\CreateHtmlCode::getInstance();
86
        $sc      = Modulebuilder\Files\CreateSmartyCode::getInstance();
87
        $fields  = $this->getTableFields($tableMid, $tableId);
88
        $ret     = '';
89
        $retNumb = '';
90
        foreach (array_keys($fields) as $f) {
91
            $fieldElement = $fields[$f]->getVar('field_element');
92
            if (1 == $fields[$f]->getVar('field_user')) {
93
                if (1 == $fields[$f]->getVar('field_ihead')) {
94
                    switch ($fieldElement) {
95
                        default:
96
                        //case 2:
97
                            $fieldName   = $fields[$f]->getVar('field_name');
98
                            $rpFieldName = $this->getRightString($fieldName);
99
                            $doubleVar   = $sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
100
                            $retNumb     .= $hc->getHtmlHNumb($doubleVar, '3', 'panel-title', "\t");
101
                            break;
102
                    }
103
                }
104
            }
105
        }
106
        $ret     .= $hc->getHtmlDiv($retNumb, 'panel-heading');
107
        $retElem   = '';
108
        $fieldId   = '';
109
        $keyDouble = '';
110
        foreach (array_keys($fields) as $f) {
111
            if (0 == $f) {
112
                $fieldId = $fields[$f]->getVar('field_name');
113
                $keyDouble = $sc->getSmartyDoubleVar($tableSoleName, $fieldId);
114
            }
115
            $fieldElement = $fields[$f]->getVar('field_element');
116
            if (1 == $fields[$f]->getVar('field_user')) {
117
                if (1 == $fields[$f]->getVar('field_ibody')) {
118
                    switch ($fieldElement) {
119
                        default:
120
                        //case 3:
121
                        //case 4:
122
                            $fieldName   = $fields[$f]->getVar('field_name');
123
                            $rpFieldName = $this->getRightString($fieldName);
124
                            $doubleVar   = $sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
125
                            $retElem     .= $hc->getHtmlSpan($doubleVar, 'col-sm-9 justify', "\t");
126
                            break;
127
                        case 10:
128
                            $fieldName   = $fields[$f]->getVar('field_name');
129
                            $rpFieldName = $this->getRightString($fieldName);
130
                            $singleVar   = $sc->getSmartySingleVar('xoops_icons32_url');
131
                            $doubleVar   = $sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
132
                            $img         = $hc->getHtmlImage($singleVar . '/' . $doubleVar, (string)$tableName);
133
                            $retElem     .= $hc->getHtmlSpan($img, 'col-sm-3', "\t");
134
                            unset($img);
135
                            break;
136
                        case 13:
137
                            $fieldName   = $fields[$f]->getVar('field_name');
138
                            $rpFieldName = $this->getRightString($fieldName);
139
                            $singleVar   = $sc->getSmartySingleVar($moduleDirname . '_upload_url');
140
                            $doubleVar   = $sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
141
                            $img         = $hc->getHtmlImage($singleVar . "/images/{$tableName}/" . $doubleVar, (string)$tableName);
142
                            $retElem     .= $hc->getHtmlSpan($img, 'col-sm-3',"\t");
143
                            unset($img);
144
                            break;
145
                    }
146
                }
147
            }
148
        }
149
150
151
        $ret     .= $hc->getHtmlDiv($retElem, 'panel-body');
152
        $retFoot = '';
153
        foreach (array_keys($fields) as $f) {
154
            if (1 == $fields[$f]->getVar('field_user')) {
155
                if (1 == $fields[$f]->getVar('field_ifoot')) {
156
                    $fieldName   = $fields[$f]->getVar('field_name');
157
                    $rpFieldName = $this->getRightString($fieldName);
158
                    $langConst   = mb_strtoupper($tableSoleName) . '_' . mb_strtoupper($rpFieldName);
159
                    $lang        = $sc->getSmartyConst($language, $langConst);
160
                    $doubleVar   = $sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
161
                    $retFoot     .= $hc->getHtmlSpan($lang . ': ' . $doubleVar, 'block-pie justify',"\t");
162
                }
163
            }
164
        }
165
        $lang        = $sc->getSmartyConst($language, 'DETAILS');
166
        $anchor =  $hc->getHtmlAnchor($tableName . ".php?op=show&amp;{$fieldId}=" . $keyDouble, $lang, $lang, '', 'btn btn-primary', '', '', '');
167
        $retFoot     .= $hc->getHtmlSpan($anchor, 'col-sm-12',"\t");
168
        $ret .= $hc->getHtmlDiv($retFoot, 'panel-foot');
169
170
        return $ret;
171
    }
172
173
    /**
174
     * @public function render
175
     * @param null
176
     * @return bool|string
177
     */
178
    public function render()
179
    {
180
        $module = $this->getModule();
181
        $table  = $this->getTable();
182
        //$tables = $this->getTables();
183
        //$tables        = $this->getTableTables($module->getVar('mod_id'), 'table_order');
184
        $moduleDirname = $module->getVar('mod_dirname');
185
        $filename      = $this->getFileName();
186
        $language      = $this->getLanguage($moduleDirname, 'MA');
187
        $content       = '';
188
        $tableId         = $table->getVar('table_id');
189
        $tableMid        = $table->getVar('table_mid');
190
        $tableName       = $table->getVar('table_name');
191
        $tableSoleName   = $table->getVar('table_solename');
192
        $tableCategory[] = $table->getVar('table_category');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$tableCategory was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableCategory = array(); before regardless.
Loading history...
193
        //$tableIndex      = $table->getVar('table_index');
194
        if (in_array(0, $tableCategory)) {
195
            $content .= $this->getTemplatesUserPagesListPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language);
196
        }
197
198
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED);
199
200
        return $this->renderFile();
201
    }
202
}
203