1 | <?php |
||
14 | class SideNav |
||
15 | { |
||
16 | use SideNavHelpers; |
||
17 | |||
18 | /** |
||
19 | * group route |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private static $group; |
||
24 | |||
25 | /** |
||
26 | * current position of route |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private static $currentItem; |
||
31 | |||
32 | /** |
||
33 | * All routes registered |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private static $routes = []; |
||
38 | |||
39 | /** |
||
40 | * render array |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private static $menu = []; |
||
45 | |||
46 | /** |
||
47 | * Make the SideNav group |
||
48 | * |
||
49 | * @author Alireza Josheghani <[email protected]> |
||
50 | * @since 19 Sep 2016 |
||
51 | * @param $group |
||
52 | * @param $callback |
||
53 | */ |
||
54 | public static function group($group, $callback) |
||
65 | |||
66 | /** |
||
67 | * Register a new menu item |
||
68 | * |
||
69 | * @author Alireza Josheghani <[email protected]> |
||
70 | * @since 19 Sep 2016 |
||
71 | * @param $route |
||
72 | * @param $callback |
||
73 | */ |
||
74 | public static function register($route, $callback) |
||
75 | { |
||
76 | // set current route |
||
77 | self::$currentItem = $route; |
||
78 | |||
79 | // register route |
||
80 | self::$routes[self::$currentItem] = []; |
||
81 | |||
82 | // make menu array |
||
83 | $array = self::add($route, $callback); |
||
84 | |||
85 | if (self::checkGroupName(self::$group)) { |
||
86 | // add to the group render array |
||
87 | return array_push(self::$menu[self::$group], $array); |
||
88 | } |
||
89 | |||
90 | // add to the single render array |
||
91 | return array_push(self::$menu, $array); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Register a new menu item |
||
96 | * |
||
97 | * @author Alireza Josheghani <[email protected]> |
||
98 | * @since 19 Sep 2016 |
||
99 | * @param $route |
||
100 | * @param $callback |
||
101 | * @param $checkCallback |
||
102 | */ |
||
103 | public static function registerWithCheck($route , $callback , $check) |
||
104 | { |
||
105 | // check status of route |
||
106 | if ($check()) { |
||
107 | self::register($route, $callback); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Add the submenu to item |
||
113 | * |
||
114 | * @author Alireza Josheghani <[email protected]> |
||
115 | * @since 19 Sep 2016 |
||
116 | * @param $route |
||
117 | * @param $callback |
||
118 | * @return array |
||
119 | */ |
||
120 | public static function addSub($route, $callback) |
||
121 | { |
||
122 | // register route name |
||
123 | array_push(self::$routes[self::$currentItem], $route); |
||
124 | |||
125 | // return submenu array |
||
126 | return self::add($route, $callback); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Add the menu item |
||
131 | * |
||
132 | * @author Alireza Josheghani <[email protected]> |
||
133 | * @since 19 Sep 2016 |
||
134 | * @param $route |
||
135 | * @param $callback |
||
136 | * @return array |
||
137 | */ |
||
138 | private static function add($route,$callback) |
||
149 | |||
150 | /** |
||
151 | * Get all routes |
||
152 | * |
||
153 | * @author Alireza Josheghani <[email protected]> |
||
154 | * @since 19 Sep 2016 |
||
155 | * @return array |
||
156 | */ |
||
157 | public static function routes($index = null) |
||
166 | |||
167 | |||
168 | /** |
||
169 | * Render the menu items |
||
170 | * |
||
171 | * @author Alireza Josheghani <[email protected]> |
||
172 | * @since 19 Sep 2016 |
||
173 | * @param $type |
||
174 | * @return mixed |
||
175 | */ |
||
176 | public static function render($type = null) |
||
187 | |||
188 | /** |
||
189 | * Check group id |
||
190 | * |
||
191 | * @author Alireza Josheghani <[email protected]> |
||
192 | * @since 19 Sep 2016 |
||
193 | * @return bool |
||
194 | */ |
||
195 | private static function checkGroupName($type) |
||
203 | |||
204 | } |
||
205 |