Completed
Push — master ( ade801...9022cf )
by
unknown
02:53 queued 26s
created

Menu   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 215
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 215
rs 10
c 2
b 0
f 0
wmc 16
lcom 1
cbo 1

13 Methods

Rating   Name   Duplication   Size   Complexity  
A sub() 0 5 1
A subWithCheckStatus() 0 8 2
A icon() 0 5 1
A tag() 0 5 1
A title() 0 4 1
A newTab() 0 4 1
A routeName() 0 4 1
A link() 0 5 1
A selected() 0 4 1
A openChildOnClick() 0 4 1
A className() 0 4 1
B make() 0 28 3
A isNew() 0 4 1
1
<?php
2
3
/**
4
 * @author Alireza Josheghani <[email protected]>
5
 * @version 1.0
6
 * @package SideNav
7
 * @since 20 Sep 2016
8
 * SideNav Menu class
9
 */
10
11
namespace Anetwork\SideNav;
12
13
class Menu
14
{
15
16
    // the route name
17
    protected $route;
18
19
    // the title option
20
    protected $title;
21
22
    // the url option
23
    protected $link = [
24
        'new_tab' => false,
25
        'value' => null
26
    ];
27
28
    // the class-name option
29
    protected $class;
30
31
    // the icon option
32
    protected $icon = [
33
        'tag' => 'i',
34
        'value' => null
35
    ];
36
37
    // is_new icon option : boolean
38
    protected $isNew = false;
39
40
    // selected option
41
    protected $selected = false;
42
43
    // open child when item is active : boolean
44
    protected $openChildOnClick = true;
45
46
    // the sub menu array
47
    protected $submenu = [];
48
49
    /**
50
     * Attach sub menu array
51
     * @author Alireza Josheghani <[email protected]>
52
     * @since 20 Sep 2016
53
     * @param $route
54
     * @param $callback
55
     */
56
    public function sub($route, $callback)
57
    {
58
        $sub = SideNav::addSub($route, $callback);
59
        array_push($this->submenu,$sub);
60
    }
61
62
    /**
63
     * Attach sub menu array with checking status of item
64
     * @author Alireza Josheghani <[email protected]>
65
     * @since 20 Sep 2016
66
     * @param $route
67
     * @param $callback
68
     */
69
    public function subWithCheckStatus($route, $callback)
70
    {
71
        if(SideNav::checkStatus($route) === true)
72
        {
73
            $sub = SideNav::addSub($route, $callback);
74
            array_push($this->submenu,$sub);
75
        }
76
    }
77
78
    /**
79
     * Set the icon option
80
     * @author Alireza Josheghani <[email protected]>
81
     * @since 20 Sep 2016
82
     * @param $icon
83
     */
84
    public function icon($icon)
85
    {
86
        $this->icon['value'] = $icon;
87
        return $this;
88
    }
89
90
    /**
91
     * Set the icon tag option
92
     * @author Alireza Josheghani <[email protected]>
93
     * @since 20 Sep 2016
94
     * @param $icon
95
     */
96
    public function tag($tag)
97
    {
98
        $this->icon['tag'] = $tag;
99
        return $this;
100
    }
101
102
    /**
103
     * Set the title option
104
     * @author Alireza Josheghani <[email protected]>
105
     * @since 20 Sep 2016
106
     * @param $title
107
     */
108
    public function title($title)
109
    {
110
        $this->title = $title;
111
    }
112
113
    /**
114
     * Set the class-name option
115
     * @author Alireza Josheghani <[email protected]>
116
     * @since 20 Sep 2016
117
     * @param $class_name
118
     */
119
    public function className($className)
120
    {
121
        $this->class = $className;
122
    }
123
124
    /**
125
     * Set the newTab option
126
     * @author Alireza Josheghani <[email protected]>
127
     * @since 20 Sep 2016
128
     * @param $newtab : boolean
129
     */
130
    public function newTab($newtab)
131
    {
132
        $this->link['new_tab'] = $newtab;
133
    }
134
135
    /**
136
     * Set route name
137
     * @author Alireza Josheghani <[email protected]>
138
     * @since 20 Sep 2016
139
     * @param $route
140
     */
141
    public function routeName($route)
142
    {
143
        $this->route = $route;
144
    }
145
146
    /**
147
     * Set the link of menu
148
     * @author Alireza Josheghani <[email protected]>
149
     * @since 20 Sep 2016
150
     * @param $link
151
     * @return $this
152
     */
153
    public function link($link)
154
    {
155
        $this->link['value'] = $link;
156
        return $this;
157
    }
158
159
    /**
160
     * Set target link of item
161
     * @author Alireza Josheghani <[email protected]>
162
     * @since 20 Sep 2016
163
     * @param $isNew
164
     */
165
    public function isNew($isNew)
166
    {
167
        $this->isNew = $isNew;
168
    }
169
170
    /**
171
     * Set item is selected
172
     * @author Alireza Josheghani <[email protected]>
173
     * @since 20 Sep 2016
174
     * @param $type
175
     */
176
    public function selected($type)
177
    {
178
        $this->selected = $type;
179
    }
180
181
    /**
182
     * Set open child when item is active
183
     * @author Alireza Josheghani <[email protected]>
184
     * @since 20 Sep 2016
185
     * @param $type
186
     */
187
    public function openChildOnClick($type)
188
    {
189
        $this->openChildOnClick = $type;
190
    }
191
192
    /**
193
     * make the return item array
194
     * @author Alireza Josheghani <[email protected]>
195
     * @since 20 Sep 2016
196
     * @return array
197
     */
198
    public function make($route)
199
    {
200
        // set route name of menu
201
        $this->routeName($route);
202
203
        $submenu = null;
204
205
        if(!empty($this->submenu))
206
            $submenu = $this->submenu;
207
208
        $result = [
209
            'name' => $this->route,
210
            'title' => $this->title,
211
            'class' => $this->class,
212
            'icon' => $this->icon,
213
            'link' => $this->link,
214
            'selected' => $this->selected,
215
            'is_new' => $this->isNew,
216
            'open_child_on_click' => $this->openChildOnClick,
217
            'sub' => $submenu
218
        ];
219
220
        if(empty($this->submenu))
221
            unset($result['sub']);
222
223
        return $result;
224
225
    }
226
227
}
228