1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Helpers; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* TODO: On the future, all menu items should have a type property. We can use |
7
|
|
|
* the type property to easy distinguish the item type and avoid guessing it by |
8
|
|
|
* they properties. |
9
|
|
|
*/ |
10
|
|
|
class MenuItemHelper |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Check if a menu item is a header. |
14
|
|
|
* |
15
|
|
|
* @param mixed $item |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
52 |
|
public static function isHeader($item) |
19
|
|
|
{ |
20
|
52 |
|
return is_string($item) || isset($item['header']); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Check if a menu item is a link. |
25
|
|
|
* |
26
|
|
|
* @param mixed $item |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
4 |
|
public static function isLink($item) |
30
|
|
|
{ |
31
|
4 |
|
return isset($item['text']) && |
32
|
4 |
|
(isset($item['url']) || isset($item['route'])); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Check if a menu item is a submenu. |
37
|
|
|
* |
38
|
|
|
* @param mixed $item |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
56 |
|
public static function isSubmenu($item) |
42
|
|
|
{ |
43
|
56 |
|
return isset($item['text']) && |
44
|
56 |
|
isset($item['submenu']) && |
45
|
56 |
|
is_array($item['submenu']); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Check if a menu item is a legacy search bar. |
50
|
|
|
* |
51
|
|
|
* @param mixed $item |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
54 |
|
public static function isLegacySearch($item) |
55
|
|
|
{ |
56
|
54 |
|
return isset($item['text']) && |
57
|
54 |
|
isset($item['search']) && |
58
|
54 |
|
$item['search']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Check if a menu item is a navbar custom search bar. |
63
|
|
|
* |
64
|
|
|
* @param mixed $item |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
52 |
|
public static function isNavbarCustomSearch($item) |
68
|
|
|
{ |
69
|
52 |
|
return isset($item['text']) && |
70
|
52 |
|
isset($item['type']) && |
71
|
52 |
|
$item['type'] === 'navbar-search'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Check if a menu item is a sidebar custom search bar. |
76
|
|
|
* |
77
|
|
|
* @param mixed $item |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
50 |
|
public static function isSidebarCustomSearch($item) |
81
|
|
|
{ |
82
|
50 |
|
return isset($item['text']) && |
83
|
50 |
|
isset($item['type']) && |
84
|
50 |
|
$item['type'] === 'sidebar-custom-search'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Check if a menu item is a sidebar menu search bar. |
89
|
|
|
* |
90
|
|
|
* @param mixed $item |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
50 |
|
public static function isSidebarMenuSearch($item) |
94
|
|
|
{ |
95
|
50 |
|
return isset($item['text']) && |
96
|
50 |
|
isset($item['type']) && |
97
|
50 |
|
$item['type'] === 'sidebar-menu-search'; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Check if a menu item is a fullscreen toggle widget. |
102
|
|
|
* |
103
|
|
|
* @param mixed $item |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
20 |
|
public static function isFullscreen($item) |
107
|
|
|
{ |
108
|
20 |
|
return isset($item['type']) && |
109
|
20 |
|
$item['type'] === 'fullscreen-widget'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Check if a menu item is a navbar search item (legacy or new). |
114
|
|
|
* |
115
|
|
|
* @param mixed $item |
116
|
|
|
* @return bool |
117
|
|
|
*/ |
118
|
54 |
|
public static function isNavbarSearch($item) |
119
|
|
|
{ |
120
|
54 |
|
return self::isLegacySearch($item) || |
121
|
54 |
|
self::isNavbarCustomSearch($item); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Check if a menu item is a sidebar search item (legacy or new). |
126
|
|
|
* |
127
|
|
|
* @param mixed $item |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
50 |
|
public static function isSidebarSearch($item) |
131
|
|
|
{ |
132
|
50 |
|
return self::isLegacySearch($item) || |
133
|
50 |
|
self::isSidebarMenuSearch($item) || |
134
|
50 |
|
self::isSidebarCustomSearch($item); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Check if a menu item is allowed to be shown. |
139
|
|
|
* |
140
|
|
|
* @param mixed $item |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
56 |
|
public static function isAllowed($item) |
144
|
|
|
{ |
145
|
56 |
|
$isAllowed = ! (isset($item['restricted']) && $item['restricted']); |
146
|
|
|
|
147
|
56 |
|
return $item && $isAllowed; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Check if a menu item is valid for the sidebar section. |
152
|
|
|
* |
153
|
|
|
* @param mixed $item |
154
|
|
|
* @return bool |
155
|
|
|
*/ |
156
|
18 |
|
public static function isValidSidebarItem($item) |
157
|
|
|
{ |
158
|
18 |
|
return self::isHeader($item) || |
159
|
18 |
|
self::isSidebarSearch($item) || |
160
|
18 |
|
self::isSubmenu($item) || |
161
|
18 |
|
self::isLink($item); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Check if a menu item is valid for the navbar section. |
166
|
|
|
* |
167
|
|
|
* @param mixed $item |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
20 |
|
public static function isValidNavbarItem($item) |
171
|
|
|
{ |
172
|
20 |
|
return self::isNavbarSearch($item) || |
173
|
20 |
|
self::isFullscreen($item) || |
174
|
20 |
|
self::isSubmenu($item) || |
175
|
20 |
|
self::isLink($item); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Check if a menu item belongs to the left section of the navbar. |
180
|
|
|
* |
181
|
|
|
* @param mixed $item |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
18 |
|
public static function isNavbarLeftItem($item) |
185
|
|
|
{ |
186
|
18 |
|
return self::isValidNavbarItem($item) && |
187
|
18 |
|
isset($item['topnav']) && |
188
|
18 |
|
$item['topnav']; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Check if a menu item belongs to the right section of the navbar. |
193
|
|
|
* |
194
|
|
|
* @param mixed $item |
195
|
|
|
* @return bool |
196
|
|
|
*/ |
197
|
19 |
|
public static function isNavbarRightItem($item) |
198
|
|
|
{ |
199
|
19 |
|
return self::isValidNavbarItem($item) && |
200
|
19 |
|
isset($item['topnav_right']) && |
201
|
19 |
|
$item['topnav_right']; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Check if a menu item belongs to the user menu section of the navbar. |
206
|
|
|
* |
207
|
|
|
* @param mixed $item |
208
|
|
|
* @return bool |
209
|
|
|
*/ |
210
|
19 |
|
public static function isNavbarUserItem($item) |
211
|
|
|
{ |
212
|
19 |
|
return self::isValidNavbarItem($item) && |
213
|
19 |
|
isset($item['topnav_user']) && |
214
|
19 |
|
$item['topnav_user']; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Check if a menu item belongs to the sidebar. |
219
|
|
|
* |
220
|
|
|
* @param mixed $item |
221
|
|
|
* @return bool |
222
|
|
|
*/ |
223
|
18 |
|
public static function isSidebarItem($item) |
224
|
|
|
{ |
225
|
18 |
|
return self::isValidSidebarItem($item) && |
226
|
18 |
|
! self::isNavbarLeftItem($item) && |
227
|
18 |
|
! self::isNavbarRightItem($item) && |
228
|
18 |
|
! self::isNavbarUserItem($item); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|