Completed
Push — master ( e1a919...c5c436 )
by Ruud
28:05 queued 15:36
created

MenuItem::setHiddenFromNav()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Helper\Menu;
4
5
/**
6
 * A MenuItem is part of the menu in the admin interface, this will be build by the {@link MenuBuilder}
7
 */
8
class MenuItem
9
{
10
    /**
11
     * @var MenuBuilder
12
     */
13
    private $menu;
14
15
    /**
16
     * @var string
17
     */
18
    private $uniqueId;
19
20
    /**
21
     * @var string
22
     */
23
    private $label;
24
25
    /**
26
     * @var string
27
     */
28
    private $role;
29
30
    /**
31
     * @var MenuItem
32
     */
33
    private $parent;
34
35
    /**
36
     * @var string
37
     */
38
    private $route;
39
40
    /**
41
     * @var array
42
     */
43
    private $routeParams = array();
44
45
    /**
46
     * @var bool
47
     */
48
    private $active = false;
49
50
    /**
51
     * @var bool
52
     */
53
    private $offline = false;
54
55
    /**
56
     * @var bool
57
     */
58
    private $hiddenFromNav = false;
59
60
    /**
61
     * @var bool
62
     */
63
    private $folder = false;
64
65
    /**
66
     * @var MenuItem[]
67
     */
68
    private $children = null;
69
70
    /**
71
     * @var array
72
     */
73
    private $attributes = array();
74
75
    /**
76
     * @var bool
77
     */
78
    private $appearInNavigation = true;
79
80
    /**
81
     * @var int
82
     */
83
    private $weight = -50;
84
85
    /**
86
     * Construct the MenuItem
87
     *
88
     * @param MenuBuilder $menu
89
     */
90 26
    public function __construct(MenuBuilder $menu)
91
    {
92 26
        $this->menu = $menu;
93 26
    }
94
95
    /**
96
     * Get menu builder
97
     *
98
     * @return MenuBuilder
99
     */
100 4
    public function getMenu()
101
    {
102 4
        return $this->menu;
103
    }
104
105
    /**
106
     * Get unique Id
107
     *
108
     * @return string
109
     */
110 1
    public function getUniqueId()
111
    {
112 1
        return $this->uniqueId;
113
    }
114
115
    /**
116
     * Set unique id
117
     *
118
     * @param string $uniqueId
119
     *
120
     * @return MenuItem
121
     */
122 8
    public function setUniqueId($uniqueId)
123
    {
124 8
        $this->uniqueId = $uniqueId;
125
126 8
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132 7
    public function getLabel()
133
    {
134 7
        return $this->label;
135
    }
136
137
    /**
138
     * @param string $label
139
     *
140
     * @return MenuItem
141
     */
142 8
    public function setLabel($label)
143
    {
144 8
        $this->label = $label;
145
146 8
        return $this;
147
    }
148
149
    /**
150
     * Get role
151
     *
152
     * @return string
153
     */
154 1
    public function getRole()
155
    {
156 1
        return $this->role;
157
    }
158
159
    /**
160
     * Set role
161
     *
162
     * @param string $role
163
     *
164
     * @return MenuItem
165
     */
166 2
    public function setRole($role)
167
    {
168 2
        $this->role = $role;
169
170 2
        return $this;
171
    }
172
173
    /**
174
     * Get parent menu item
175
     *
176
     * @return MenuItem|null
177
     */
178 1
    public function getParent()
179
    {
180 1
        return $this->parent;
181
    }
182
183
    /**
184
     * Set parent menu item
185
     *
186
     * @param MenuItem|null $parent
187
     *
188
     * @return MenuItem
189
     */
190 8
    public function setParent(MenuItem $parent = null)
191
    {
192 8
        $this->parent = $parent;
193
194 8
        return $this;
195
    }
196
197
    /**
198
     * Get route for menu item
199
     *
200
     * @return string
201
     */
202 7
    public function getRoute()
203
    {
204 7
        return $this->route;
205
    }
206
207
    /**
208
     * Set route and parameters for menu item
209
     *
210
     * @param string $route  The route
211
     * @param array  $params The route parameters
212
     *
213
     * @return MenuItem
214
     */
215 8
    public function setRoute($route, array $params = array())
216
    {
217 8
        $this->route = $route;
218 8
        $this->routeParams = $params;
219
220 8
        return $this;
221
    }
222
223
    /**
224
     * Get route parameters for menu item
225
     *
226
     * @return array
227
     */
228 2
    public function getRouteParams()
229
    {
230 2
        return $this->routeParams;
231
    }
232
233
    /**
234
     * Set route parameters
235
     *
236
     * @param array $routeParams
237
     *
238
     * @return MenuItem
239
     */
240 1
    public function setRouteParams(array $routeParams = array())
241
    {
242 1
        $this->routeParams = $routeParams;
243
244 1
        return $this;
245
    }
246
247
    /**
248
     * Get children of current menu item
249
     *
250
     * @return MenuItem[]
251
     */
252 4
    public function getChildren()
253
    {
254 4
        if (is_null($this->children)) {
255 3
            $this->children = $this->menu->getChildren($this);
256
        }
257
258 4
        return $this->children;
259
    }
260
261
    /**
262
     * Warning: the adaptChildren method on the menuadaptors will not be called anymore for this menuitem
263
     *
264
     * @param array $children
265
     *
266
     * @return MenuItem
267
     */
268 1
    public function setChildren(array $children = array())
269
    {
270 1
        $this->children = $children;
271
272 1
        return $this;
273
    }
274
275
    /**
276
     * Get children of current menu item that have the appearInNavigation flag set
277
     *
278
     * @return MenuItem[]
279
     */
280 1
    public function getNavigationChildren()
281
    {
282 1
        $result = array();
283 1
        $children = $this->getChildren();
284 1
        foreach ($children as $child) {
285 1
            if ($child->getAppearInNavigation()) {
286 1
                $result[] = $child;
287
            }
288
        }
289
290 1
        return $result;
291
    }
292
293
    /**
294
     * Return top children of current menu item
295
     *
296
     * @return TopMenuItem[]
297
     */
298 1
    public function getTopChildren()
299
    {
300 1
        $result = array();
301 1
        $children = $this->getChildren();
302 1
        foreach ($children as $child) {
303 1
            if ($child instanceof TopMenuItem) {
304 1
                $result[] = $child;
305
            }
306
        }
307
308 1
        return $result;
309
    }
310
311
    /**
312
     * Add attributes
313
     *
314
     * @param array $attributes
315
     *
316
     * @return MenuItem
317
     */
318 1
    public function addAttributes($attributes)
319
    {
320 1
        $this->attributes = array_merge($this->attributes, $attributes);
321
322 1
        return $this;
323
    }
324
325
    /**
326
     * Get attributes
327
     *
328
     * @return array
329
     */
330 1
    public function getAttributes()
331
    {
332 1
        return $this->attributes;
333
    }
334
335
    /**
336
     * Get menu item active state
337
     *
338
     * @return bool
339
     */
340 1
    public function getActive()
341
    {
342 1
        return $this->active;
343
    }
344
345
    /**
346
     * Set menu item active state
347
     *
348
     * @param bool $active
349
     *
350
     * @return MenuItem
351
     */
352 7
    public function setActive($active)
353
    {
354 7
        $this->active = $active;
355
356 7
        return $this;
357
    }
358
359
    /**
360
     * Get menu item offline state
361
     *
362
     * @return bool
363
     */
364 1
    public function getOffline()
365
    {
366 1
        return $this->offline;
367
    }
368
369
    /**
370
     * Set menu item offline state
371
     *
372
     * @param bool $offline
373
     *
374
     * @return MenuItem
375
     */
376 1
    public function setOffline($offline)
377
    {
378 1
        $this->offline = $offline;
379
380 1
        return $this;
381
    }
382
383
    /**
384
     * @return bool
385
     */
386 1
    public function isHiddenFromNav()
387
    {
388 1
        return $this->hiddenFromNav;
389
    }
390
391
    /**
392
     * @return $this
393
     */
394 1
    public function setHiddenFromNav($hiddenFromNav)
395
    {
396 1
        $this->hiddenFromNav = $hiddenFromNav;
397
398 1
        return $this;
399
    }
400
401
    /**
402
     * Get menu item folder state
403
     *
404
     * @return bool
405
     */
406 1
    public function getFolder()
407
    {
408 1
        return $this->folder;
409
    }
410
411
    /**
412
     * Set menu item folder state
413
     *
414
     * @param bool $folder
415
     *
416
     * @return MenuItem
417
     */
418 1
    public function setFolder($folder)
419
    {
420 1
        $this->folder = $folder;
421
422 1
        return $this;
423
    }
424
425
    /**
426
     * Get appearInNavigation flag
427
     *
428
     * @return bool
429
     */
430 2
    public function getAppearInNavigation()
431
    {
432 2
        return $this->appearInNavigation;
433
    }
434
435
    /**
436
     * Set appearInNavigation flag
437
     *
438
     * @param bool $appearInNavigation
439
     *
440
     * @return MenuItem
441
     */
442 3
    public function setAppearInNavigation($appearInNavigation)
443
    {
444 3
        $this->appearInNavigation = $appearInNavigation;
445
446 3
        return $this;
447
    }
448
449
    /**
450
     * Get weight
451
     *
452
     * @return int
453
     */
454 1
    public function getWeight()
455
    {
456 1
        return $this->weight;
457
    }
458
459
    /**
460
     * Set weight
461
     *
462
     * @param int $weight
463
     *
464
     * @return MenuItem
465
     */
466 1
    public function setWeight($weight)
467
    {
468 1
        $this->weight = $weight;
469
470 1
        return $this;
471
    }
472
}
473