1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Helpers; |
4
|
|
|
|
5
|
|
|
class MenuItemHelper |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Check if a menu item is a header. |
9
|
|
|
* |
10
|
|
|
* @param mixed $item |
11
|
|
|
* @return bool |
12
|
|
|
*/ |
13
|
48 |
|
public static function isHeader($item) |
14
|
|
|
{ |
15
|
48 |
|
return is_string($item) || isset($item['header']); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Check if a menu item is a link. |
20
|
|
|
* |
21
|
|
|
* @param mixed $item |
22
|
|
|
* @return bool |
23
|
|
|
*/ |
24
|
4 |
|
public static function isLink($item) |
25
|
|
|
{ |
26
|
4 |
|
return isset($item['text']) && |
27
|
4 |
|
(isset($item['url']) || isset($item['route'])); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Check if a menu item is a search bar. |
32
|
|
|
* |
33
|
|
|
* @param mixed $item |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
48 |
|
public static function isSearchBar($item) |
37
|
|
|
{ |
38
|
48 |
|
return isset($item['text']) && |
39
|
48 |
|
isset($item['search']) && |
40
|
48 |
|
$item['search']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Check if a menu item is a submenu. |
45
|
|
|
* |
46
|
|
|
* @param mixed $item |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
49 |
|
public static function isSubmenu($item) |
50
|
|
|
{ |
51
|
49 |
|
return isset($item['text']) && |
52
|
49 |
|
isset($item['submenu']) && |
53
|
49 |
|
is_array($item['submenu']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Check if a menu item is allowed to be shown. |
58
|
|
|
* |
59
|
|
|
* @param mixed $item |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
49 |
|
public static function isAllowed($item) |
63
|
|
|
{ |
64
|
49 |
|
$isAllowed = ! (isset($item['restricted']) && $item['restricted']); |
65
|
|
|
|
66
|
49 |
|
return $item && $isAllowed; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Check if a menu item is valid for the sidebar section. |
71
|
|
|
* |
72
|
|
|
* @param mixed $item |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
14 |
|
public static function isValidSidebarItem($item) |
76
|
|
|
{ |
77
|
14 |
|
return self::isHeader($item) || |
78
|
14 |
|
self::isSearchBar($item) || |
79
|
14 |
|
self::isSubmenu($item) || |
80
|
14 |
|
self::isLink($item); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Check if a menu item is valid for the navbar section. |
85
|
|
|
* |
86
|
|
|
* @param mixed $item |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
14 |
|
public static function isValidNavbarItem($item) |
90
|
|
|
{ |
91
|
14 |
|
return self::isValidSidebarItem($item) && ! self::isHeader($item); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Check if a menu item belongs to the left section of the navbar. |
96
|
|
|
* |
97
|
|
|
* @param mixed $item |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
12 |
|
public static function isNavbarLeftItem($item) |
101
|
|
|
{ |
102
|
12 |
|
return self::isValidNavbarItem($item) && |
103
|
12 |
|
isset($item['topnav']) && |
104
|
12 |
|
$item['topnav']; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Check if a menu item belongs to the right section of the navbar. |
109
|
|
|
* |
110
|
|
|
* @param mixed $item |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
13 |
|
public static function isNavbarRightItem($item) |
114
|
|
|
{ |
115
|
13 |
|
return self::isValidNavbarItem($item) && |
116
|
13 |
|
isset($item['topnav_right']) && |
117
|
13 |
|
$item['topnav_right']; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Check if a menu item belongs to the user menu section of the navbar. |
122
|
|
|
* |
123
|
|
|
* @param mixed $item |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
13 |
|
public static function isNavbarUserItem($item) |
127
|
|
|
{ |
128
|
13 |
|
return self::isValidNavbarItem($item) && |
129
|
13 |
|
isset($item['topnav_user']) && |
130
|
13 |
|
$item['topnav_user']; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Check if a menu item belongs to the sidebar. |
135
|
|
|
* |
136
|
|
|
* @param mixed $item |
137
|
|
|
* @return bool |
138
|
|
|
*/ |
139
|
12 |
|
public static function isSidebarItem($item) |
140
|
|
|
{ |
141
|
12 |
|
return self::isValidSidebarItem($item) && |
142
|
12 |
|
! self::isNavbarLeftItem($item) && |
143
|
12 |
|
! self::isNavbarRightItem($item) && |
144
|
12 |
|
! self::isNavbarUserItem($item); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|