AdminMenu::getAdminMenuImagesPath()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 2
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\Admin;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\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
 * tdmcreate 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 AdminMenu.
31
 */
32
class AdminMenu 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 AdminMenu
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 $filename
62
     */
63
    public function write($module, $filename)
64
    {
65
        $this->setModule($module);
66
        $this->setFileName($filename);
67
    }
68
69
    /**
70
     * @private function getAdminMenuArray
71
     * @param array $param
72
     * @param bool $adminObject
73
     * @return string
74
     */
75
    private function getAdminMenuArray($param = [], $adminObject = false)
76
    {
77
        $xc  = Tdmcreate\Files\CreateXoopsCode::getInstance();
78
        $ret = '';
79
        if ($adminObject) {
80
            $ret .= $this->getSimpleString("\$adminmenu[] = [");
81
            foreach ($param as $key => $value) {
82
                $ret .= $this->getSimpleString("\t'{$key}' => {$value},");
83
            }
84
            $ret .= $this->getSimpleString("];");
85
        } else {
86
            foreach ($param as $key => $value) {
87
                $ret .= $xc->getXcEqualsOperator((string)$key, (string)$value);
88
            }
89
        }
90
91
        return $ret;
92
    }
93
94
    /**
95
     * @private function getAdminMenuHeader
96
     * @param null
97
     * @return string
98
     */
99
    private function getAdminMenuHeader()
100
    {
101
        $ret = $this->getSimpleString('');
102
        $mod     = [
103
            '$dirname      ' => 'basename(dirname(__DIR__))',
104
            '$moduleHandler' => "xoops_getHandler('module')",
105
            '$xoopsModule  '   => 'XoopsModule::getByDirname($dirname)',
106
            '$moduleInfo   '    => "\$moduleHandler->get(\$xoopsModule->getVar('mid'))",
107
            '$sysPathIcon32' => "\$moduleInfo->getInfo('sysicons32')",
108
        ];
109
        $ret .= $this->getAdminMenuArray($mod);
110
        $ret .= $this->getSimpleString('');
111
112
        return $ret;
113
    }
114
115
    /**
116
     * @private function getAdminMenuDashboard
117
     * @param string $language
118
     * @param int    $menu
119
     *
120
     * @return string
121
     */
122
    private function getAdminMenuDashboard($language, $menu)
123
    {
124
        $param = ['title' => "{$language}{$menu}", 'link' => "'admin/index.php'", 'icon' => "\$sysPathIcon32.'/dashboard.png'"];
125
        $ret   = $this->getAdminMenuArray($param, true);
126
127
        return $ret;
128
    }
129
130
    /**
131
     * @private function getAdminMenuImagesPath
132
     * @param array $tables
133
     * @param int   $t
134
     *
135
     * @return string
136
     */
137
    private function getAdminMenuImagesPath($tables, $t)
0 ignored issues
show
Unused Code introduced by
The method getAdminMenuImagesPath() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
138
    {
139
        $xc     = Tdmcreate\Files\CreateXoopsCode::getInstance();
140
        $ret    = '';
141
        $fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id'));
142
        foreach (array_keys($fields) as $f) {
143
            $fieldElement = $fields[$f]->getVar('field_element');
144
            switch ($fieldElement) {
145
                case 13:
146
                    $ret = $xc->getXcEqualsOperator("\$adminmenu[\$i]['icon']", "'assets/icons/32/{$tables[$t]->getVar('table_image')}'");
147
                    break;
148
                default:
149
                    $ret = $xc->getXcEqualsOperator("\$adminmenu[\$i]['icon']", "\$sysPathIcon32.'/{$tables[$t]->getVar('table_image')}'");
150
                    break;
151
            }
152
        }
153
154
        return $ret;
155
    }
156
157
    /**
158
     * @private function getAdminMenuList
159
     * @param string $module
160
     * @param string $language
161
     * @param string $langAbout
162
     * @param int    $menu
163
     *
164
     * @return string
165
     */
166
    private function getAdminMenuList($module, $language, $langAbout, $menu)
167
    {
168
        $ret    = '';
169
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
170
        $tablePermissions = [];
171
        foreach (array_keys($tables) as $t) {
172
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
173
            if (1 == $tables[$t]->getVar('table_admin')) {
174
                ++$menu;
175
                $param1 = ['title' => "{$language}{$menu}", 'link' => "'admin/{$tables[$t]->getVar('table_name')}.php'", 'icon' => "'assets/icons/32/{$tables[$t]->getVar('table_image')}'"];
176
                $ret    .= $this->getAdminMenuArray($param1, true);
177
            }
178
        }
179
        if (in_array(1, $tablePermissions)) {
180
            ++$menu;
181
            $param2 = ['title' => "{$language}{$menu}", 'link' => "'admin/permissions.php'", 'icon' => "\$sysPathIcon32.'/permissions.png'"];
182
            $ret    .= $this->getAdminMenuArray($param2, true);
183
        }
184
        ++$menu;
185
        $param3 = ['title' => "{$language}{$menu}", 'link' => "'admin/feedback.php'", 'icon' => "\$sysPathIcon32.'/mail_foward.png'"];
186
        $ret    .= $this->getAdminMenuArray($param3, true);
187
        unset($menu);
188
        $param3 = ['title' => (string)$langAbout, 'link' => "'admin/about.php'", 'icon' => "\$sysPathIcon32.'/about.png'"];
189
        $ret    .= $this->getAdminMenuArray($param3, true);
190
191
        return $ret;
192
    }
193
194
    /**
195
     * @public function render
196
     * @param null
197
     * @return bool|string
198
     */
199
    public function render()
200
    {
201
        $module        = $this->getModule();
202
        $filename      = $this->getFileName();
203
        $moduleDirname = $module->getVar('mod_dirname');
204
        $language      = $this->getLanguage($moduleDirname, 'MI', 'ADMENU');
205
        $langAbout     = $this->getLanguage($moduleDirname, 'MI', 'ABOUT');
206
        $menu          = 1;
207
        $content       = $this->getHeaderFilesComments($module);
208
        $content       .= $this->getAdminMenuHeader();
209
        $content       .= $this->getAdminMenuDashboard($language, $menu);
210
        $content       .= $this->getAdminMenuList($module, $language, $langAbout, $menu);
211
212
        $this->create($moduleDirname, 'admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
213
214
        return $this->renderFile();
215
    }
216
}
217