Completed
Pull Request — master (#2377)
by Sander
13:22
created

MenuItem::isHiddenFromNav()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    public function __construct(MenuBuilder $menu)
91
    {
92
        $this->menu = $menu;
93
    }
94
95
    /**
96
     * Get menu builder
97
     *
98
     * @return MenuBuilder
99
     */
100
    public function getMenu()
101
    {
102
        return $this->menu;
103
    }
104
105
    /**
106
     * Get unique Id
107
     *
108
     * @return string
109
     */
110
    public function getUniqueId()
111
    {
112
        return $this->uniqueId;
113
    }
114
115
    /**
116
     * Set unique id
117
     *
118
     * @param string $uniqueId
119
     *
120
     * @return MenuItem
121
     */
122
    public function setUniqueId($uniqueId)
123
    {
124
        $this->uniqueId = $uniqueId;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getLabel()
133
    {
134
        return $this->label;
135
    }
136
137
    /**
138
     * @param string $label
139
     *
140
     * @return MenuItem
141
     */
142
    public function setLabel($label)
143
    {
144
        $this->label = $label;
145
146
        return $this;
147
    }
148
149
    /**
150
     * Get role
151
     *
152
     * @return string
153
     */
154
    public function getRole()
155
    {
156
        return $this->role;
157
    }
158
159
    /**
160
     * Set role
161
     *
162
     * @param string $role
163
     *
164
     * @return MenuItem
165
     */
166
    public function setRole($role)
167
    {
168
        $this->role = $role;
169
170
        return $this;
171
    }
172
173
    /**
174
     * Get parent menu item
175
     *
176
     * @return MenuItem|null
177
     */
178
    public function getParent()
179
    {
180
        return $this->parent;
181
    }
182
183
    /**
184
     * Set parent menu item
185
     *
186
     * @param MenuItem|null $parent
187
     *
188
     * @return MenuItem
189
     */
190
    public function setParent(MenuItem $parent = null)
191
    {
192
        $this->parent = $parent;
193
194
        return $this;
195
    }
196
197
    /**
198
     * Get route for menu item
199
     *
200
     * @return string
201
     */
202
    public function getRoute()
203
    {
204
        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
    public function setRoute($route, array $params = array())
216
    {
217
        $this->route = $route;
218
        $this->routeParams = $params;
219
220
        return $this;
221
    }
222
223
    /**
224
     * Get route parameters for menu item
225
     *
226
     * @return array
227
     */
228
    public function getRouteParams()
229
    {
230
        return $this->routeParams;
231
    }
232
233
    /**
234
     * Set route parameters
235
     *
236
     * @param array $routeParams
237
     *
238
     * @return MenuItem
239
     */
240
    public function setRouteParams(array $routeParams = array())
241
    {
242
        $this->routeParams = $routeParams;
243
244
        return $this;
245
    }
246
247
    /**
248
     * Get children of current menu item
249
     *
250
     * @return MenuItem[]
251
     */
252
    public function getChildren()
253
    {
254
        if (is_null($this->children)) {
255
            $this->children = $this->menu->getChildren($this);
256
        }
257
258
        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
    public function setChildren(array $children = array())
269
    {
270
        $this->children = $children;
271
272
        return $this;
273
    }
274
275
    /**
276
     * Get children of current menu item that have the appearInNavigation flag set
277
     *
278
     * @return MenuItem[]
279
     */
280
    public function getNavigationChildren()
281
    {
282
        $result = array();
283
        $children = $this->getChildren();
284
        foreach ($children as $child) {
285
            if ($child->getAppearInNavigation()) {
286
                $result[] = $child;
287
            }
288
        }
289
290
        return $result;
291
    }
292
293
    /**
294
     * Return top children of current menu item
295
     *
296
     * @return TopMenuItem[]
297
     */
298
    public function getTopChildren()
299
    {
300
        $result = array();
301
        $children = $this->getChildren();
302
        foreach ($children as $child) {
303
            if ($child instanceof TopMenuItem) {
304
                $result[] = $child;
305
            }
306
        }
307
308
        return $result;
309
    }
310
311
    /**
312
     * Add attributes
313
     *
314
     * @param array $attributes
315
     *
316
     * @return MenuItem
317
     */
318
    public function addAttributes($attributes)
319
    {
320
        $this->attributes = array_merge($this->attributes, $attributes);
321
322
        return $this;
323
    }
324
325
    /**
326
     * Get attributes
327
     *
328
     * @return array
329
     */
330
    public function getAttributes()
331
    {
332
        return $this->attributes;
333
    }
334
335
    /**
336
     * Get menu item active state
337
     *
338
     * @return bool
339
     */
340
    public function getActive()
341
    {
342
        return $this->active;
343
    }
344
345
    /**
346
     * Set menu item active state
347
     *
348
     * @param bool $active
349
     *
350
     * @return MenuItem
351
     */
352
    public function setActive($active)
353
    {
354
        $this->active = $active;
355
356
        return $this;
357
    }
358
359
    /**
360
     * Get menu item offline state
361
     *
362
     * @return bool
363
     */
364
    public function getOffline()
365
    {
366
        return $this->offline;
367
    }
368
369
    /**
370
     * Set menu item offline state
371
     *
372
     * @param bool $offline
373
     *
374
     * @return MenuItem
375
     */
376
    public function setOffline($offline)
377
    {
378
        $this->offline = $offline;
379
380
        return $this;
381
    }
382
383
    /**
384
     * @return bool
385
     */
386
    public function isHiddenFromNav()
387
    {
388
        return $this->hiddenFromNav;
389
    }
390
391
    /**
392
     * @return $this
393
     */
394
    public function setHiddenFromNav($hiddenFromNav)
395
    {
396
        $this->hiddenFromNav = $hiddenFromNav;
397
398
        return $this;
399
    }
400
401
    /**
402
     * Get menu item folder state
403
     *
404
     * @return bool
405
     */
406
    public function getFolder()
407
    {
408
        return $this->folder;
409
    }
410
411
    /**
412
     * Set menu item folder state
413
     *
414
     * @param bool $folder
415
     *
416
     * @return MenuItem
417
     */
418
    public function setFolder($folder)
419
    {
420
        $this->folder = $folder;
421
422
        return $this;
423
    }
424
425
    /**
426
     * Get appearInNavigation flag
427
     *
428
     * @return bool
429
     */
430
    public function getAppearInNavigation()
431
    {
432
        return $this->appearInNavigation;
433
    }
434
435
    /**
436
     * Set appearInNavigation flag
437
     *
438
     * @param bool $appearInNavigation
439
     *
440
     * @return MenuItem
441
     */
442
    public function setAppearInNavigation($appearInNavigation)
443
    {
444
        $this->appearInNavigation = $appearInNavigation;
445
446
        return $this;
447
    }
448
449
    /**
450
     * Get weight
451
     *
452
     * @return int
453
     */
454
    public function getWeight()
455
    {
456
        return $this->weight;
457
    }
458
459
    /**
460
     * Set weight
461
     *
462
     * @param int $weight
463
     *
464
     * @return MenuItem
465
     */
466
    public function setWeight($weight)
467
    {
468
        $this->weight = $weight;
469
470
        return $this;
471
    }
472
}
473