|
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\Model\Navigation; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
|
15
|
|
|
use WBW\Library\Core\Model\Node\AbstractNode; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Navigation item. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Model\Navigation |
|
22
|
|
|
* @deprecated |
|
23
|
|
|
*/ |
|
24
|
|
|
class NavigationItem extends AbstractNode implements NavigationInterface { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Href. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $href; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Icon. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $icon; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $id The id. |
|
44
|
|
|
* @param string $icon The icon. |
|
45
|
|
|
* @param string $href The href. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct($id, $icon = null, $href = self::NAVIGATION_HREF_DEFAULT) { |
|
48
|
|
|
parent::__construct($id); |
|
49
|
|
|
$this->icon = $icon; |
|
50
|
|
|
$this->href = $href; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the href. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string Returns the href. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getHref() { |
|
59
|
|
|
return $this->href; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the icon. |
|
64
|
|
|
* |
|
65
|
|
|
* @return string Returns the icon. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getIcon() { |
|
68
|
|
|
return $this->icon; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set the href. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $href The href. |
|
75
|
|
|
* @return NavigationItem Returns the navigation item. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setHref($href) { |
|
78
|
|
|
$this->href = $href; |
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Set the icon. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $icon The icon. |
|
86
|
|
|
* @return NavigationItem Returns the navigation item. |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setIcon($icon) { |
|
89
|
|
|
$this->icon = $icon; |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Convert into an array representing this instance. |
|
95
|
|
|
* |
|
96
|
|
|
* @return array Returns an array representing this instance. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function toArray() { |
|
99
|
|
|
|
|
100
|
|
|
// Initialize the output. |
|
101
|
|
|
$output = []; |
|
102
|
|
|
|
|
103
|
|
|
ArrayHelper::set($output, "href", $this->href, [null]); |
|
104
|
|
|
ArrayHelper::set($output, "icon", $this->icon, [null]); |
|
105
|
|
|
ArrayHelper::set($output, "span", $this->getId(), [null]); |
|
106
|
|
|
|
|
107
|
|
|
// Check the nodes. |
|
108
|
|
|
if (0 < $this->size()) { |
|
109
|
|
|
$output["subitems"] = []; |
|
110
|
|
|
foreach ($this->getNodes() as $current) { |
|
111
|
|
|
if (false === ($current instanceof NavigationItem)) { |
|
112
|
|
|
continue; |
|
113
|
|
|
} |
|
114
|
|
|
$output["subitems"][] = $current->toArray(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
// Return the output. |
|
119
|
|
|
return $output; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|