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
|
|
|
* |
52
|
|
|
* @author Alireza Josheghani <[email protected]> |
53
|
|
|
* @since 20 Sep 2016 |
54
|
|
|
* @param $route |
55
|
|
|
* @param $callback |
56
|
|
|
*/ |
57
|
|
|
public function sub($route, $callback) |
58
|
|
|
{ |
59
|
|
|
$sub = SideNav::addSub($route, $callback); |
60
|
|
|
array_push($this->submenu, $sub); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Attach sub menu array with checking status of item |
65
|
|
|
* |
66
|
|
|
* @author Alireza Josheghani <[email protected]> |
67
|
|
|
* @since 20 Sep 2016 |
68
|
|
|
* @param $route |
69
|
|
|
* @param $callback |
70
|
|
|
*/ |
71
|
|
|
public function subWithCheck($route, $callback) |
72
|
|
|
{ |
73
|
|
|
if(SideNav::checkStatus($route) === true) { |
74
|
|
|
$sub = SideNav::addSub($route, $callback); |
75
|
|
|
array_push($this->submenu, $sub); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set the icon option |
81
|
|
|
* |
82
|
|
|
* @author Alireza Josheghani <[email protected]> |
83
|
|
|
* @since 20 Sep 2016 |
84
|
|
|
* @param $icon |
85
|
|
|
*/ |
86
|
|
|
public function icon($icon) |
87
|
|
|
{ |
88
|
|
|
$this->icon['value'] = $icon; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set the icon tag option |
94
|
|
|
* |
95
|
|
|
* @author Alireza Josheghani <[email protected]> |
96
|
|
|
* @since 20 Sep 2016 |
97
|
|
|
* @param $icon |
98
|
|
|
*/ |
99
|
|
|
public function tag($tag) |
100
|
|
|
{ |
101
|
|
|
$this->icon['tag'] = $tag; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Set the title option |
107
|
|
|
* |
108
|
|
|
* @author Alireza Josheghani <[email protected]> |
109
|
|
|
* @since 20 Sep 2016 |
110
|
|
|
* @param $title |
111
|
|
|
*/ |
112
|
|
|
public function title($title) |
113
|
|
|
{ |
114
|
|
|
$this->title = $title; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set the class-name option |
119
|
|
|
* |
120
|
|
|
* @author Alireza Josheghani <[email protected]> |
121
|
|
|
* @since 20 Sep 2016 |
122
|
|
|
* @param $class_name |
123
|
|
|
*/ |
124
|
|
|
public function className($className) |
125
|
|
|
{ |
126
|
|
|
$this->class = $className; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Set the newTab option |
131
|
|
|
* |
132
|
|
|
* @author Alireza Josheghani <[email protected]> |
133
|
|
|
* @since 20 Sep 2016 |
134
|
|
|
* @param $newtab : boolean |
135
|
|
|
*/ |
136
|
|
|
public function newTab($newtab) |
137
|
|
|
{ |
138
|
|
|
$this->link['new_tab'] = $newtab; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set route name |
143
|
|
|
* |
144
|
|
|
* @author Alireza Josheghani <[email protected]> |
145
|
|
|
* @since 20 Sep 2016 |
146
|
|
|
* @param $route |
147
|
|
|
*/ |
148
|
|
|
public function routeName($route) |
149
|
|
|
{ |
150
|
|
|
$this->route = $route; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set the link of menu |
155
|
|
|
* |
156
|
|
|
* @author Alireza Josheghani <[email protected]> |
157
|
|
|
* @since 20 Sep 2016 |
158
|
|
|
* @param $link |
159
|
|
|
* @return $this |
160
|
|
|
*/ |
161
|
|
|
public function link($link) |
162
|
|
|
{ |
163
|
|
|
$this->link['value'] = $link; |
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set target link of item |
169
|
|
|
* |
170
|
|
|
* @author Alireza Josheghani <[email protected]> |
171
|
|
|
* @since 20 Sep 2016 |
172
|
|
|
* @param $isNew |
173
|
|
|
*/ |
174
|
|
|
public function isNew($isNew) |
175
|
|
|
{ |
176
|
|
|
$this->isNew = $isNew; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set item is selected |
181
|
|
|
* |
182
|
|
|
* @author Alireza Josheghani <[email protected]> |
183
|
|
|
* @since 20 Sep 2016 |
184
|
|
|
* @param $type |
185
|
|
|
*/ |
186
|
|
|
public function selected($type) |
187
|
|
|
{ |
188
|
|
|
$this->selected = $type; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set open child when item is active |
193
|
|
|
* |
194
|
|
|
* @author Alireza Josheghani <[email protected]> |
195
|
|
|
* @since 20 Sep 2016 |
196
|
|
|
* @param $type |
197
|
|
|
*/ |
198
|
|
|
public function openChildOnClick($type) |
199
|
|
|
{ |
200
|
|
|
$this->openChildOnClick = $type; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* make the return item array |
205
|
|
|
* |
206
|
|
|
* @author Alireza Josheghani <[email protected]> |
207
|
|
|
* @since 20 Sep 2016 |
208
|
|
|
* @return array |
209
|
|
|
*/ |
210
|
|
|
public function make($route) |
211
|
|
|
{ |
212
|
|
|
// set route name of menu |
213
|
|
|
$this->routeName($route); |
214
|
|
|
|
215
|
|
|
$submenu = null; |
216
|
|
|
|
217
|
|
|
if(!empty($this->submenu)) { |
218
|
|
|
$submenu = $this->submenu; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
$result = [ |
222
|
|
|
'name' => $this->route, |
223
|
|
|
'title' => $this->title, |
224
|
|
|
'class' => $this->class, |
225
|
|
|
'icon' => $this->icon, |
226
|
|
|
'link' => $this->link, |
227
|
|
|
'selected' => $this->selected, |
228
|
|
|
'is_new' => $this->isNew, |
229
|
|
|
'open_child_on_click' => $this->openChildOnClick, |
230
|
|
|
'sub' => $submenu |
231
|
|
|
]; |
232
|
|
|
|
233
|
|
|
if(empty($this->submenu)) { |
234
|
|
|
unset($result['sub']); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
return $result; |
238
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
} |
242
|
|
|
|