1 | <?php namespace Arcanesoft\Sidebar; |
||
14 | class Manager implements ManagerContract |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * The view name. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $view; |
||
27 | |||
28 | /** |
||
29 | * The current name. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $currentName; |
||
34 | |||
35 | /** |
||
36 | * The sidebar items collection. |
||
37 | * |
||
38 | * @var \Arcanesoft\Sidebar\Entities\ItemCollection |
||
39 | */ |
||
40 | protected $items; |
||
41 | |||
42 | /** |
||
43 | * The authenticated user. |
||
44 | * |
||
45 | * @var \Arcanesoft\Contracts\Auth\Models\User |
||
46 | */ |
||
47 | protected $user; |
||
48 | |||
49 | /* ----------------------------------------------------------------- |
||
50 | | Constructor |
||
51 | | ----------------------------------------------------------------- |
||
52 | */ |
||
53 | |||
54 | /** |
||
55 | * Manager constructor. |
||
56 | */ |
||
57 | 21 | public function __construct() |
|
61 | |||
62 | /* ----------------------------------------------------------------- |
||
63 | | Getters & Setters |
||
64 | | ----------------------------------------------------------------- |
||
65 | */ |
||
66 | |||
67 | /** |
||
68 | * Set the view name. |
||
69 | * |
||
70 | * @param string $view |
||
71 | * |
||
72 | * @return self |
||
73 | */ |
||
74 | 6 | public function setView($view) |
|
75 | { |
||
76 | 6 | if ( ! is_null($view)) |
|
77 | 6 | $this->view = $view; |
|
78 | |||
79 | 6 | return $this; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get the current item name. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 3 | public function getCurrent() |
|
88 | { |
||
89 | 3 | return $this->currentName; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Set the current item name. |
||
94 | * |
||
95 | * @param string $currentName |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | 3 | public function setCurrent($currentName) |
|
100 | { |
||
101 | 3 | $this->currentName = $currentName; |
|
102 | |||
103 | 3 | return $this; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Get the sidebar items. |
||
108 | * |
||
109 | * @return \Arcanesoft\Sidebar\Entities\ItemCollection |
||
110 | */ |
||
111 | 18 | public function getItems() |
|
115 | |||
116 | /* ----------------------------------------------------------------- |
||
117 | | Main Methods |
||
118 | | ----------------------------------------------------------------- |
||
119 | */ |
||
120 | |||
121 | /** |
||
122 | * Add a routed item. |
||
123 | * |
||
124 | * @param string $name |
||
125 | * @param string $title |
||
126 | * @param string $route |
||
127 | * @param array $parameters |
||
128 | * @param string|null $icon |
||
129 | * |
||
130 | * @return self |
||
131 | */ |
||
132 | 3 | public function addRouteItem($name, $title, $route, array $parameters = [], $icon = null) |
|
133 | { |
||
134 | 3 | return $this->addItem($name, $title, route($route, $parameters), $icon); |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * Add an item. |
||
139 | * |
||
140 | * @param string $name |
||
141 | * @param string $title |
||
142 | * @param string $url |
||
143 | * @param string|null $icon |
||
144 | * |
||
145 | * @return self |
||
146 | */ |
||
147 | 9 | public function addItem($name, $title, $url = '#', $icon = null) |
|
151 | |||
152 | /** |
||
153 | * Add an item from array. |
||
154 | * |
||
155 | * @param array $array |
||
156 | * |
||
157 | * @return self |
||
158 | */ |
||
159 | 12 | public function add(array $array) |
|
168 | |||
169 | /** |
||
170 | * Load items from multiple config keys. |
||
171 | * |
||
172 | * @param string $key |
||
173 | * |
||
174 | * @return self |
||
175 | */ |
||
176 | 3 | public function loadItemsFromConfig($key) |
|
189 | |||
190 | /** |
||
191 | * Render the sidebar. |
||
192 | * |
||
193 | * @param string|null $view |
||
194 | * @param array|null $data |
||
195 | * |
||
196 | * @return \Illuminate\Support\HtmlString |
||
197 | */ |
||
198 | 6 | public function render($view = '_includes.sidebar.default', array $data = []) |
|
206 | |||
207 | /* ----------------------------------------------------------------- |
||
208 | | Check Methods |
||
209 | | ----------------------------------------------------------------- |
||
210 | */ |
||
211 | |||
212 | /** |
||
213 | * Check if the sidebar has items. |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | 9 | public function hasItems() |
|
221 | |||
222 | /* ----------------------------------------------------------------- |
||
223 | | Other Methods |
||
224 | | ----------------------------------------------------------------- |
||
225 | */ |
||
226 | |||
227 | /** |
||
228 | * Sync the current name wih the sidebar items. |
||
229 | * |
||
230 | * @return self |
||
231 | */ |
||
232 | 6 | private function syncCurrentName() |
|
238 | } |
||
239 |