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