1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\MenuBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Alpixel\Bundle\MenuBundle\Model\ItemInterface; |
6
|
|
|
use Alpixel\Bundle\MenuBundle\Model\MenuInterface; |
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Table(name="alpixel_menu_item") |
13
|
|
|
* @ORM\Entity |
14
|
|
|
*/ |
15
|
|
|
class Item implements ItemInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var int |
19
|
|
|
* |
20
|
|
|
* @ORM\Column(name="item_id", type="integer", nullable=false) |
21
|
|
|
* @ORM\Id |
22
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
23
|
|
|
*/ |
24
|
|
|
protected $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @Gedmo\SortableGroup |
28
|
|
|
* |
29
|
|
|
* @ORM\ManyToOne(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Item", inversedBy="children") |
30
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="item_id", onDelete="SET NULL") |
31
|
|
|
*/ |
32
|
|
|
protected $parent; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @ORM\OneToMany(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Item", mappedBy="parent") |
36
|
|
|
*/ |
37
|
|
|
protected $children; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\ManyToOne(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Menu", inversedBy="items") |
41
|
|
|
* @ORM\JoinColumn(name="menu_id", referencedColumnName="menu_id") |
42
|
|
|
*/ |
43
|
|
|
protected $menu; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
* |
48
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=false) |
49
|
|
|
*/ |
50
|
|
|
protected $name; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
* |
55
|
|
|
* @ORM\Column(name="uri", type="text", nullable=false) |
56
|
|
|
*/ |
57
|
|
|
protected $uri; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Gedmo\SortablePosition |
61
|
|
|
* |
62
|
|
|
* @ORM\Column(name="position", type="integer", nullable=false) |
63
|
|
|
*/ |
64
|
|
|
protected $position; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Gedmo\Slug(fields={"name"}, updatable=true, separator="_") |
68
|
|
|
* @ORM\Column(length=128) |
69
|
|
|
**/ |
70
|
|
|
protected $slug; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function __construct() |
74
|
|
|
{ |
75
|
|
|
$this->children = new ArrayCollection(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get string defined. |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function __toString() |
84
|
|
|
{ |
85
|
|
|
return $this->name; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get Id. |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
|
|
public function getId() |
94
|
|
|
{ |
95
|
|
|
return $this->id; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get menu. |
100
|
|
|
* |
101
|
|
|
* @return Menu |
102
|
|
|
*/ |
103
|
|
|
public function getMenu() |
104
|
|
|
{ |
105
|
|
|
return $this->menu; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Set menu. |
110
|
|
|
* |
111
|
|
|
* @param Menu $menu |
112
|
|
|
* |
113
|
|
|
* @return self |
114
|
|
|
*/ |
115
|
|
|
public function setMenu(MenuInterface $menu) |
116
|
|
|
{ |
117
|
|
|
$this->menu = $menu; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get parent Item. |
124
|
|
|
* |
125
|
|
|
* @return null\Item |
126
|
|
|
*/ |
127
|
|
|
public function getParent() |
128
|
|
|
{ |
129
|
|
|
return $this->parent; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set parent Item. |
134
|
|
|
* |
135
|
|
|
* @param ItemInterface $menu |
|
|
|
|
136
|
|
|
* |
137
|
|
|
* @return self |
138
|
|
|
*/ |
139
|
|
|
public function setParent(ItemInterface $item = null) |
140
|
|
|
{ |
141
|
|
|
$this->parent = $item; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get children of Item. |
148
|
|
|
* |
149
|
|
|
* @return ArrayCollection (Item) |
150
|
|
|
*/ |
151
|
|
|
public function getChildren() |
152
|
|
|
{ |
153
|
|
|
return $this->children; |
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set Item from ArrayCollection. |
158
|
|
|
* |
159
|
|
|
* @param null\ArrayCollection |
160
|
|
|
* |
161
|
|
|
* @return self |
162
|
|
|
*/ |
163
|
|
|
public function addChildren(ArrayCollection $collection) |
164
|
|
|
{ |
165
|
|
|
foreach ($collection as $item) { |
166
|
|
|
$this->setChildren($item); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set children of Item. |
174
|
|
|
* |
175
|
|
|
* @param Item $item |
176
|
|
|
* |
177
|
|
|
* @return self |
178
|
|
|
*/ |
179
|
|
|
public function setChildren(ItemInterface $item) |
180
|
|
|
{ |
181
|
|
|
if ($this->children->contains($item) === false) { |
182
|
|
|
$this->children->add($item); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Remove children. |
190
|
|
|
* |
191
|
|
|
* @param ItemInterface $item |
192
|
|
|
* |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function removeChildren(ItemInterface $item) |
196
|
|
|
{ |
197
|
|
|
if ($this->children->contains($item) === true) { |
198
|
|
|
$this->children->removeElement($item); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get name displayed in Item. |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function getName() |
210
|
|
|
{ |
211
|
|
|
return $this->name; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set name displayed in Item. |
216
|
|
|
* |
217
|
|
|
* @param string |
218
|
|
|
* |
219
|
|
|
* @return self |
220
|
|
|
*/ |
221
|
|
|
public function setName($name) |
222
|
|
|
{ |
223
|
|
|
$this->name = $name; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Get URL. |
230
|
|
|
* |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getUri() |
234
|
|
|
{ |
235
|
|
|
return $this->uri; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Set URL. |
240
|
|
|
* |
241
|
|
|
* @param string $url |
|
|
|
|
242
|
|
|
* |
243
|
|
|
* @return self |
244
|
|
|
*/ |
245
|
|
|
public function setUri($uri) |
246
|
|
|
{ |
247
|
|
|
$this->uri = $uri; |
248
|
|
|
|
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get position of Item. |
254
|
|
|
* |
255
|
|
|
* @return int |
256
|
|
|
*/ |
257
|
|
|
public function getPosition() |
258
|
|
|
{ |
259
|
|
|
return $this->position; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Set position. |
264
|
|
|
* |
265
|
|
|
* @param int $position |
266
|
|
|
* |
267
|
|
|
* @return self |
268
|
|
|
*/ |
269
|
|
|
public function setPosition($position) |
270
|
|
|
{ |
271
|
|
|
$this->position = $position; |
272
|
|
|
|
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Gets the value of slug. |
278
|
|
|
* |
279
|
|
|
* @return mixed |
280
|
|
|
*/ |
281
|
|
|
public function getSlug() |
282
|
|
|
{ |
283
|
|
|
return $this->slug; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Sets the value of slug. |
288
|
|
|
* |
289
|
|
|
* @param mixed $slug the slug |
290
|
|
|
* |
291
|
|
|
* @return self |
292
|
|
|
*/ |
293
|
|
|
public function setSlug($slug) |
294
|
|
|
{ |
295
|
|
|
$this->slug = $slug; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|