1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Navigation; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Collection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Ramsey\Uuid\Uuid; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Navigation\Route\Route; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\SortableTrait; |
10
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class AbstractNavigationItem |
14
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Navigation |
15
|
|
|
* @author Daniel West <[email protected]> |
16
|
|
|
* @ORM\Entity() |
17
|
|
|
* @ORM\Table(name="navigation_item") |
18
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
19
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
20
|
|
|
* @ORM\DiscriminatorMap({ |
21
|
|
|
* "nav_bar" = "Silverback\ApiComponentBundle\Entity\Layout\NavBar\NavBarItem", |
22
|
|
|
* "tabs" = "Silverback\ApiComponentBundle\Entity\Component\Navigation\Tabs\TabsItem", |
23
|
|
|
* "menu" = "Silverback\ApiComponentBundle\Entity\Component\Navigation\Menu\MenuItem" |
24
|
|
|
* }) |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractNavigationItem implements NavigationItemInterface |
27
|
|
|
{ |
28
|
|
|
use SortableTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\Id() |
32
|
|
|
* @ORM\Column(type="string") |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $id; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Navigation\AbstractNavigation", inversedBy="items", cascade={"remove"}) |
39
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
40
|
|
|
* @var AbstractNavigation |
41
|
|
|
* @Groups({"component_item_write"}) |
42
|
|
|
*/ |
43
|
|
|
protected $navigation; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @ORM\Column() |
47
|
|
|
* @Groups({"layout", "component", "component_item"}) |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $label; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Navigation\Route\Route") |
54
|
|
|
* @ORM\JoinColumn(referencedColumnName="route") |
55
|
|
|
* @Groups({"layout", "component", "component_item"}) |
56
|
|
|
* @var null|Route |
57
|
|
|
*/ |
58
|
|
|
protected $route; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\Column(nullable=true) |
62
|
|
|
* @Groups({"layout", "component", "component_item"}) |
63
|
|
|
* @var null|string |
64
|
|
|
*/ |
65
|
|
|
protected $fragment; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Navigation\AbstractNavigation") |
69
|
|
|
* @Groups({"layout", "component", "component_item"}) |
70
|
|
|
* @var null|AbstractNavigation |
71
|
|
|
*/ |
72
|
|
|
protected $child; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* AbstractNavigationItem constructor. |
76
|
|
|
*/ |
77
|
|
|
public function __construct() |
78
|
|
|
{ |
79
|
|
|
$this->id = Uuid::uuid4()->getHex(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getId(): string |
86
|
|
|
{ |
87
|
|
|
return $this->id; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return AbstractNavigation |
92
|
|
|
*/ |
93
|
|
|
public function getNavigation(): AbstractNavigation |
94
|
|
|
{ |
95
|
|
|
return $this->navigation; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param AbstractNavigation $navigation |
100
|
|
|
* @param bool|null $sortLast |
101
|
|
|
*/ |
102
|
|
|
public function setNavigation(AbstractNavigation $navigation, ?bool $sortLast = true): void |
103
|
|
|
{ |
104
|
|
|
$this->navigation = $navigation; |
105
|
|
|
if (null === $this->sort || $sortLast !== null) { |
106
|
|
|
$this->setSort($this->calculateSort($sortLast)); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getLabel(): string |
115
|
|
|
{ |
116
|
|
|
return $this->label; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param string $label |
121
|
|
|
* @return AbstractNavigationItem |
122
|
|
|
*/ |
123
|
|
|
public function setLabel(string $label): AbstractNavigationItem |
124
|
|
|
{ |
125
|
|
|
$this->label = $label; |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return null|Route |
131
|
|
|
*/ |
132
|
|
|
public function getRoute(): ?Route |
133
|
|
|
{ |
134
|
|
|
return $this->route; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param null|Route $route |
139
|
|
|
* @return AbstractNavigationItem |
140
|
|
|
*/ |
141
|
|
|
public function setRoute(?Route $route): AbstractNavigationItem |
142
|
|
|
{ |
143
|
|
|
$this->route = $route; |
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return null|string |
149
|
|
|
*/ |
150
|
|
|
public function getFragment(): ?string |
151
|
|
|
{ |
152
|
|
|
return $this->fragment; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param null|string $fragment |
157
|
|
|
* @return AbstractNavigationItem |
158
|
|
|
*/ |
159
|
|
|
public function setFragment(?string $fragment): AbstractNavigationItem |
160
|
|
|
{ |
161
|
|
|
$this->fragment = $fragment; |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return null|AbstractNavigation |
167
|
|
|
*/ |
168
|
|
|
public function getChild(): ?AbstractNavigation |
169
|
|
|
{ |
170
|
|
|
return $this->child; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param null|AbstractNavigation $child |
175
|
|
|
* @return AbstractNavigationItem |
176
|
|
|
*/ |
177
|
|
|
public function setChild(?AbstractNavigation $child): AbstractNavigationItem |
178
|
|
|
{ |
179
|
|
|
$this->child = $child; |
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection|Collection|\Silverback\ApiComponentBundle\Entity\SortableInterface[]|AbstractNavigationItem[] |
185
|
|
|
*/ |
186
|
|
|
public function getSortCollection(): Collection |
187
|
|
|
{ |
188
|
|
|
return $this->navigation->getItems(); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|