|
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'], $item['submenu']) && |
|
44
|
56 |
|
is_array($item['submenu']); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Check if a menu item is a legacy search bar. |
|
49
|
|
|
* |
|
50
|
|
|
* @param mixed $item |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
54 |
|
public static function isLegacySearch($item) |
|
54
|
|
|
{ |
|
55
|
54 |
|
return isset($item['text'], $item['search']) && |
|
56
|
54 |
|
$item['search']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Check if a menu item is a navbar custom search bar. |
|
61
|
|
|
* |
|
62
|
|
|
* @param mixed $item |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
52 |
|
public static function isNavbarCustomSearch($item) |
|
66
|
|
|
{ |
|
67
|
52 |
|
return isset($item['text'], $item['type']) && |
|
68
|
52 |
|
$item['type'] === 'navbar-search'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Check if a menu item is a sidebar custom search bar. |
|
73
|
|
|
* |
|
74
|
|
|
* @param mixed $item |
|
75
|
|
|
* @return bool |
|
76
|
|
|
*/ |
|
77
|
50 |
|
public static function isSidebarCustomSearch($item) |
|
78
|
|
|
{ |
|
79
|
50 |
|
return isset($item['text'], $item['type']) && |
|
80
|
50 |
|
$item['type'] === 'sidebar-custom-search'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Check if a menu item is a sidebar menu search bar. |
|
85
|
|
|
* |
|
86
|
|
|
* @param mixed $item |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
50 |
|
public static function isSidebarMenuSearch($item) |
|
90
|
|
|
{ |
|
91
|
50 |
|
return isset($item['text'], $item['type']) && |
|
92
|
50 |
|
$item['type'] === 'sidebar-menu-search'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Check if a menu item is a fullscreen toggle widget. |
|
97
|
|
|
* |
|
98
|
|
|
* @param mixed $item |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
20 |
|
public static function isFullscreen($item) |
|
102
|
|
|
{ |
|
103
|
20 |
|
return isset($item['type']) && |
|
104
|
20 |
|
$item['type'] === 'fullscreen-widget'; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Check if a menu item is a notification link. |
|
109
|
|
|
* |
|
110
|
|
|
* @param mixed $item |
|
111
|
|
|
* @return bool |
|
112
|
|
|
*/ |
|
113
|
20 |
|
public static function isNotificationLink($item) |
|
114
|
|
|
{ |
|
115
|
20 |
|
return isset($item['id'], $item['icon'], $item['type']) && |
|
116
|
20 |
|
(isset($item['url']) || isset($item['route'])) && |
|
117
|
20 |
|
$item['type'] === 'notification-link'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Check if a menu item is a navbar search item (legacy or new). |
|
122
|
|
|
* |
|
123
|
|
|
* @param mixed $item |
|
124
|
|
|
* @return bool |
|
125
|
|
|
*/ |
|
126
|
54 |
|
public static function isNavbarSearch($item) |
|
127
|
|
|
{ |
|
128
|
54 |
|
return self::isLegacySearch($item) || |
|
129
|
54 |
|
self::isNavbarCustomSearch($item); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Check if a menu item is a sidebar search item (legacy or new). |
|
134
|
|
|
* |
|
135
|
|
|
* @param mixed $item |
|
136
|
|
|
* @return bool |
|
137
|
|
|
*/ |
|
138
|
50 |
|
public static function isSidebarSearch($item) |
|
139
|
|
|
{ |
|
140
|
50 |
|
return self::isLegacySearch($item) || |
|
141
|
50 |
|
self::isSidebarMenuSearch($item) || |
|
142
|
50 |
|
self::isSidebarCustomSearch($item); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Check if a menu item is allowed to be shown. |
|
147
|
|
|
* |
|
148
|
|
|
* @param mixed $item |
|
149
|
|
|
* @return bool |
|
150
|
|
|
*/ |
|
151
|
56 |
|
public static function isAllowed($item) |
|
152
|
|
|
{ |
|
153
|
56 |
|
$isAllowed = ! (isset($item['restricted']) && $item['restricted']); |
|
154
|
|
|
|
|
155
|
56 |
|
return $item && $isAllowed; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Check if a menu item is valid for the sidebar section. |
|
160
|
|
|
* |
|
161
|
|
|
* @param mixed $item |
|
162
|
|
|
* @return bool |
|
163
|
|
|
*/ |
|
164
|
18 |
|
public static function isValidSidebarItem($item) |
|
165
|
|
|
{ |
|
166
|
18 |
|
return self::isHeader($item) || |
|
167
|
18 |
|
self::isSidebarSearch($item) || |
|
168
|
18 |
|
self::isSubmenu($item) || |
|
169
|
18 |
|
self::isLink($item); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Check if a menu item is valid for the navbar section. |
|
174
|
|
|
* |
|
175
|
|
|
* @param mixed $item |
|
176
|
|
|
* @return bool |
|
177
|
|
|
*/ |
|
178
|
20 |
|
public static function isValidNavbarItem($item) |
|
179
|
|
|
{ |
|
180
|
20 |
|
return self::isNavbarSearch($item) || |
|
181
|
20 |
|
self::isNotificationLink($item) || |
|
182
|
20 |
|
self::isFullscreen($item) || |
|
183
|
20 |
|
self::isSubmenu($item) || |
|
184
|
20 |
|
self::isLink($item); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Check if a menu item belongs to the left section of the navbar. |
|
189
|
|
|
* |
|
190
|
|
|
* @param mixed $item |
|
191
|
|
|
* @return bool |
|
192
|
|
|
*/ |
|
193
|
18 |
|
public static function isNavbarLeftItem($item) |
|
194
|
|
|
{ |
|
195
|
18 |
|
return self::isValidNavbarItem($item) && |
|
196
|
18 |
|
isset($item['topnav']) && |
|
197
|
18 |
|
$item['topnav']; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Check if a menu item belongs to the right section of the navbar. |
|
202
|
|
|
* |
|
203
|
|
|
* @param mixed $item |
|
204
|
|
|
* @return bool |
|
205
|
|
|
*/ |
|
206
|
19 |
|
public static function isNavbarRightItem($item) |
|
207
|
|
|
{ |
|
208
|
19 |
|
return self::isValidNavbarItem($item) && |
|
209
|
19 |
|
isset($item['topnav_right']) && |
|
210
|
19 |
|
$item['topnav_right']; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Check if a menu item belongs to the user menu section of the navbar. |
|
215
|
|
|
* |
|
216
|
|
|
* @param mixed $item |
|
217
|
|
|
* @return bool |
|
218
|
|
|
*/ |
|
219
|
19 |
|
public static function isNavbarUserItem($item) |
|
220
|
|
|
{ |
|
221
|
19 |
|
return self::isValidNavbarItem($item) && |
|
222
|
19 |
|
isset($item['topnav_user']) && |
|
223
|
19 |
|
$item['topnav_user']; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Check if a menu item belongs to the sidebar. |
|
228
|
|
|
* |
|
229
|
|
|
* @param mixed $item |
|
230
|
|
|
* @return bool |
|
231
|
|
|
*/ |
|
232
|
18 |
|
public static function isSidebarItem($item) |
|
233
|
|
|
{ |
|
234
|
18 |
|
return self::isValidSidebarItem($item) && |
|
235
|
18 |
|
! self::isNavbarLeftItem($item) && |
|
236
|
18 |
|
! self::isNavbarRightItem($item) && |
|
237
|
18 |
|
! self::isNavbarUserItem($item); |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
|