1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Navigation\Node; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Node\AbstractNode; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract navigation node. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Navigation\Node |
21
|
|
|
* @abstract |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractNavigationNode extends AbstractNode { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Active ? |
27
|
|
|
* |
28
|
|
|
* @var boolean |
29
|
|
|
*/ |
30
|
|
|
private $active; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Enable ? |
34
|
|
|
* |
35
|
|
|
* @var boolean |
36
|
|
|
*/ |
37
|
|
|
private $enable; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Icon. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $icon; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Route. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $route; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Target. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
private $target; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* URL. |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
private $url; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Visible ? |
69
|
|
|
* |
70
|
|
|
* @var boolean |
71
|
|
|
*/ |
72
|
|
|
private $visible; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Constructor. |
76
|
|
|
* |
77
|
|
|
* @param string $name The name. |
78
|
|
|
* @param string $icon The icon. |
79
|
|
|
* @param string $route The route. |
80
|
|
|
*/ |
81
|
|
|
protected function __construct($name, $icon = null, $route = null) { |
82
|
|
|
parent::__construct($name); |
83
|
|
|
$this->active = false; |
84
|
|
|
$this->enable = false; |
85
|
|
|
$this->icon = $icon; |
86
|
|
|
$this->route = $route; |
87
|
|
|
$this->target = null; |
88
|
|
|
$this->url = null; |
89
|
|
|
$this->visible = true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the active. |
94
|
|
|
* |
95
|
|
|
* @return boolean Returns the active. |
96
|
|
|
*/ |
97
|
|
|
final public function getActive() { |
98
|
|
|
return $this->active; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the enable. |
103
|
|
|
* |
104
|
|
|
* @return boolean Returns the enable. |
105
|
|
|
*/ |
106
|
|
|
final public function getEnable() { |
107
|
|
|
return $this->enable; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the icon. |
112
|
|
|
* |
113
|
|
|
* @return string Returns the icon. |
114
|
|
|
*/ |
115
|
|
|
final public function getIcon() { |
116
|
|
|
return $this->icon; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get the route. |
121
|
|
|
* |
122
|
|
|
* @return string Returns the route. |
123
|
|
|
*/ |
124
|
|
|
final public function getRoute() { |
125
|
|
|
return $this->route; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get the target. |
130
|
|
|
* |
131
|
|
|
* @return string Returns the target. |
132
|
|
|
*/ |
133
|
|
|
final public function getTarget() { |
134
|
|
|
return $this->target; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the URL. |
139
|
|
|
* |
140
|
|
|
* @return string Returns the URL. |
141
|
|
|
*/ |
142
|
|
|
final public function getUrl() { |
143
|
|
|
return $this->url; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the visible. |
148
|
|
|
* |
149
|
|
|
* @return boolean Returns the visible. |
150
|
|
|
*/ |
151
|
|
|
final public function getVisible() { |
152
|
|
|
return $this->visible; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Determines if the node is displayable. |
157
|
|
|
* |
158
|
|
|
* @return boolean Returns true in case of success, false otherwise. |
159
|
|
|
*/ |
160
|
|
|
final public function isDisplayable() { |
161
|
|
|
$displayable = $this->enable && $this->visible; |
162
|
|
|
if (false === $displayable) { |
163
|
|
|
foreach ($this->getNodes() as $current) { |
164
|
|
|
if (false === ($current instanceof AbstractNavigationNode)) { |
165
|
|
|
continue; |
166
|
|
|
} |
167
|
|
|
$displayable = $current->isDisplayable(); |
168
|
|
|
if (true === $displayable) { |
169
|
|
|
break; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
return $displayable; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Set the active. |
178
|
|
|
* |
179
|
|
|
* @param boolean $active Active ? |
180
|
|
|
* @return NavigationNode Returns the navigation node. |
181
|
|
|
*/ |
182
|
|
|
final public function setActive($active) { |
183
|
|
|
$this->active = $active; |
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Set the enable. |
189
|
|
|
* |
190
|
|
|
* @param boolean $enable Enable ?. |
191
|
|
|
* @return NavigationNode Returns the navigation node. |
192
|
|
|
*/ |
193
|
|
|
final public function setEnable($enable) { |
194
|
|
|
$this->enable = $enable; |
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Set the icon. |
200
|
|
|
* |
201
|
|
|
* @param string $icon The icon. |
202
|
|
|
* @return NavigationNode Returns the navigation node. |
203
|
|
|
*/ |
204
|
|
|
final public function setIcon($icon) { |
205
|
|
|
$this->icon = $icon; |
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Set the route. |
211
|
|
|
* |
212
|
|
|
* @param string $route The route. |
213
|
|
|
* @return NavigationNode Returns the navigation node. |
214
|
|
|
*/ |
215
|
|
|
final public function setRoute($route) { |
216
|
|
|
$this->route = $route; |
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Set the target. |
222
|
|
|
* |
223
|
|
|
* @param string $target The target. |
224
|
|
|
* @return NavigationNode Returns the navigation node. |
225
|
|
|
*/ |
226
|
|
|
final public function setTarget($target) { |
227
|
|
|
$this->target = $target; |
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Set the URL. |
233
|
|
|
* |
234
|
|
|
* @param string $url The URL. |
235
|
|
|
* @return NavigationNode Returns the navigation node. |
236
|
|
|
*/ |
237
|
|
|
final public function setUrl($url) { |
238
|
|
|
$this->url = $url; |
239
|
|
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Set the visible. |
244
|
|
|
* |
245
|
|
|
* @param boolean $visible Visible ? |
246
|
|
|
* @return NavigationNode Returns the navigation node. |
247
|
|
|
*/ |
248
|
|
|
final protected function setVisible($visible) { |
249
|
|
|
$this->visible = $visible; |
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
} |
254
|
|
|
|