Passed
Push — master ( 7189e5...87f978 )
by
unknown
18:09 queued 12:26
created

SystemMenuHandler   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 167
rs 10
c 0
b 0
f 0
wmc 25

10 Methods

Rating   Name   Duplication   Size   Complexity  
A breadcrumb_nav() 0 21 4
A __construct() 0 4 1
A addHeader() 0 3 1
A addMenuTop() 0 6 2
A addMenuTabsArray() 0 10 5
A addMenuTopArray() 0 10 5
A addMenuTabs() 0 6 2
A addSubHeader() 0 3 1
A getAddon() 0 3 1
A render() 0 24 3
1
<?php
2
/**
3
 * Class for tab navigation
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @author              John Neill (AKA Catzwolf)
15
 * @author              Andricq Nicolas (AKA MusS)
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
19
20
/**
21
 * Class SystemMenuHandler
22
 */
23
class SystemMenuHandler
24
{
25
    /**
26
     *
27
     * @var string
28
     */
29
    public $_menutop  = [];
30
    public $_menutabs = [];
31
    public $_obj;
32
    public $_header;
33
    public $_subheader;
34
35
    /**
36
     * Constructor
37
     */
38
    public function __construct()
39
    {
40
        global $xoopsModule;
41
        $this->_obj = $xoopsModule;
42
    }
43
44
    /**
45
     * @param $addon
46
     */
47
    public function getAddon($addon)
48
    {
49
        $this->_obj =& $addon;
50
    }
51
52
    /**
53
     * @param        $value
54
     * @param string $name
55
     */
56
    public function addMenuTop($value, $name = '')
57
    {
58
        if ($name !== '') {
59
            $this->_menutop[$value] = $name;
60
        } else {
61
            $this->_menutop[$value] = $value;
62
        }
63
    }
64
65
    /**
66
     * @param      $options
67
     * @param bool $multi
68
     */
69
    public function addMenuTopArray($options, $multi = true)
70
    {
71
        if (is_array($options)) {
72
            if ($multi === true) {
73
                foreach ($options as $k => $v) {
74
                    $this->addOptionTop($k, $v);
0 ignored issues
show
Bug introduced by
The method addOptionTop() does not exist on SystemMenuHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
                    $this->/** @scrutinizer ignore-call */ 
75
                           addOptionTop($k, $v);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
                }
76
            } else {
77
                foreach ($options as $k) {
78
                    $this->addOptiontop($k, $k);
0 ignored issues
show
Bug introduced by
The method addOptiontop() does not exist on SystemMenuHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
                    $this->/** @scrutinizer ignore-call */ 
79
                           addOptiontop($k, $k);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
                }
80
            }
81
        }
82
    }
83
84
    /**
85
     * @param        $value
86
     * @param string $name
87
     */
88
    public function addMenuTabs($value, $name = '')
89
    {
90
        if ($name !== '') {
91
            $this->_menutabs[$value] = $name;
92
        } else {
93
            $this->_menutabs[$value] = $value;
94
        }
95
    }
96
97
    /**
98
     * @param      $options
99
     * @param bool $multi
100
     */
101
    public function addMenuTabsArray($options, $multi = true)
102
    {
103
        if (is_array($options)) {
104
            if ($multi === true) {
105
                foreach ($options as $k => $v) {
106
                    $this->addMenuTabsTop($k, $v);
0 ignored issues
show
Bug introduced by
The method addMenuTabsTop() does not exist on SystemMenuHandler. Did you maybe mean addMenuTabs()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
                    $this->/** @scrutinizer ignore-call */ 
107
                           addMenuTabsTop($k, $v);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
                }
108
            } else {
109
                foreach ($options as $k) {
110
                    $this->addMenuTabsTop($k, $k);
111
                }
112
            }
113
        }
114
    }
115
116
    /**
117
     * @param $value
118
     */
119
    public function addHeader($value)
120
    {
121
        $this->_header = $value;
122
    }
123
124
    /**
125
     * @param $value
126
     */
127
    public function addSubHeader($value)
128
    {
129
        $this->_subheader = $value;
130
    }
131
132
    /**
133
     * @param string $basename
134
     *
135
     * @return string
136
     */
137
    public function breadcrumb_nav($basename = 'Home')
138
    {
139
        global $bc_site, $bc_label;
140
        $site       = $bc_site;
141
        $return_str = "<a href=\"/\">$basename</a>";
142
        $str        = substr(dirname(xoops_getenv('PHP_SELF')), 1);
143
144
        $arr = explode('/', $str);
145
        $num = count($arr);
146
147
        if ($num > 1) {
148
            foreach ($arr as $val) {
149
                $return_str .= ' &gt; <a href="' . $site . $val . '/">' . $bc_label[$val] . '</a>';
150
                $site .= $val . '/';
151
            }
152
        } elseif ($num == 1) {
153
            $arr = $str;
154
            $return_str .= ' &gt; <a href="' . $bc_site . $arr . '/">' . $bc_label[$arr] . '</a>';
155
        }
156
157
        return $return_str;
158
    }
159
160
    /**
161
     * @param int  $currentoption
162
     * @param bool $display
163
     *
164
     * @return string
165
     */
166
    public function render($currentoption = 1, $display = true)
0 ignored issues
show
Unused Code introduced by
The parameter $display is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

166
    public function render($currentoption = 1, /** @scrutinizer ignore-unused */ $display = true)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
167
    {
168
        global $modversion, $xoopsTpl;
169
        $_dirname = $this->_obj->getVar('dirname');
0 ignored issues
show
Unused Code introduced by
The assignment to $_dirname is dead and can be removed.
Loading history...
170
        $i        = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
171
172
        /**
173
         * Select current menu tab, sets id names for menu tabs
174
         */
175
        $j=0;
176
        foreach ($this->_menutabs as $k => $menus) {
177
            if ($j == $currentoption) {
178
                $breadcrumb = $menus;
179
            }
180
            $menuItems[] = 'modmenu_' . $j++;
181
        }
182
183
        $xoopsTpl->assign('module_name', $this->_obj->getVar('name'));
184
        $xoopsTpl->assign('module_dirname', $this->_obj->getVar('dirname'));
185
        $xoopsTpl->assign('page', $breadcrumb);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $breadcrumb does not seem to be defined for all execution paths leading up to this point.
Loading history...
186
        $xoopsTpl->assign('menutop', $this->_menutop);
187
        $xoopsTpl->assign('menutabs', $this->_menutabs);
188
        // Display Module Menu
189
        $xoopsTpl->display('db:system_modules_menu.tpl');
190
    }
191
}
192