1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\CoreBundle\Model; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use Doctrine\Common\Collections\Collection; |
19
|
|
|
use Doctrine\ORM\Proxy\Proxy; |
20
|
|
|
use SWP\Bundle\ContentBundle\Model\RouteInterface; |
21
|
|
|
use SWP\Component\MultiTenancy\Model\TenantAwareInterface; |
22
|
|
|
use SWP\Component\MultiTenancy\Model\TenantAwareTrait; |
23
|
|
|
use SWP\Bundle\ContentBundle\Model\Route as BaseRoute; |
24
|
|
|
use SWP\Component\Storage\Model\PersistableInterface; |
25
|
|
|
|
26
|
|
|
class Route extends BaseRoute implements PersistableInterface, RouteInterface, TenantAwareInterface, ArticlesCountInterface |
27
|
|
|
{ |
28
|
|
|
use TenantAwareTrait, ArticlesCountTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Collection |
37
|
|
|
*/ |
38
|
|
|
protected $articles; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var RouteInterface |
42
|
|
|
*/ |
43
|
|
|
protected $root; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var RouteInterface |
47
|
|
|
*/ |
48
|
|
|
protected $parent; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var Collection|RouteInterface[] |
52
|
|
|
*/ |
53
|
|
|
protected $children; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $lft; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
protected $rgt; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var int |
67
|
|
|
*/ |
68
|
|
|
protected $level; |
69
|
102 |
|
|
70
|
|
|
/** |
71
|
102 |
|
* Route constructor. |
72
|
102 |
|
*/ |
73
|
|
|
public function __construct() |
74
|
102 |
|
{ |
75
|
102 |
|
$this->articles = new ArrayCollection(); |
76
|
|
|
$this->children = new ArrayCollection(); |
77
|
|
|
|
78
|
|
|
parent::__construct(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getArticles() |
85
|
|
|
{ |
86
|
|
|
return $this->articles; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function setArticles($articles) |
93
|
|
|
{ |
94
|
|
|
$this->articles = $articles; |
95
|
|
|
} |
96
|
29 |
|
|
97
|
|
|
/** |
98
|
29 |
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getId() |
101
|
|
|
{ |
102
|
|
|
return parent::getId(); |
103
|
|
|
} |
104
|
6 |
|
|
105
|
|
|
/** |
106
|
6 |
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function getRouteName() |
109
|
|
|
{ |
110
|
|
|
return $this->getName(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function isRoot(): bool |
117
|
|
|
{ |
118
|
|
|
return null === $this->parent; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function getRoot(): RouteInterface |
125
|
|
|
{ |
126
|
|
|
return $this->root; |
127
|
|
|
} |
128
|
29 |
|
|
129
|
|
|
/** |
130
|
29 |
|
* {@inheritdoc} |
131
|
|
|
*/ |
132
|
|
|
public function getParent() |
133
|
|
|
{ |
134
|
|
|
return $this->parent; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
public function setParent(RouteInterface $parent = null) |
141
|
|
|
{ |
142
|
|
|
$this->parent = $parent; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return Collection|RouteInterface[] |
147
|
|
|
*/ |
148
|
|
|
public function getChildren() |
149
|
|
|
{ |
150
|
|
|
return $this->children; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* {@inheritdoc} |
155
|
|
|
*/ |
156
|
|
|
public function hasChild(RouteInterface $route): bool |
157
|
|
|
{ |
158
|
|
|
return $this->children->contains($route); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* {@inheritdoc} |
163
|
|
|
*/ |
164
|
|
|
public function addChild(RouteInterface $route) |
165
|
|
|
{ |
166
|
|
|
if (!$this->hasChild($route)) { |
167
|
|
|
$route->setParent($this); |
168
|
|
|
$this->children->add($route); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* {@inheritdoc} |
174
|
|
|
*/ |
175
|
|
|
public function removeChild(RouteInterface $route) |
176
|
|
|
{ |
177
|
|
|
if ($this->hasChild($route)) { |
178
|
|
|
$route->setParent(null); |
179
|
|
|
$this->children->removeElement($route); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* {@inheritdoc} |
185
|
|
|
*/ |
186
|
|
|
public function getLeft(): int |
187
|
|
|
{ |
188
|
|
|
return $this->lft; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritdoc} |
193
|
|
|
*/ |
194
|
|
|
public function setLeft(int $left) |
195
|
|
|
{ |
196
|
|
|
$this->lft = $left; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritdoc} |
201
|
|
|
*/ |
202
|
|
|
public function getRight(): int |
203
|
|
|
{ |
204
|
|
|
return $this->rgt; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param int $right |
209
|
|
|
*/ |
210
|
|
|
public function setRight(int $right) |
211
|
|
|
{ |
212
|
|
|
$this->rgt = $right; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* {@inheritdoc} |
217
|
|
|
*/ |
218
|
|
|
public function getLevel(): int |
219
|
|
|
{ |
220
|
|
|
return $this->level; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* {@inheritdoc} |
225
|
|
|
*/ |
226
|
|
|
public function setLevel(int $level) |
227
|
|
|
{ |
228
|
|
|
$this->level = $level; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* {@inheritdoc} |
233
|
|
|
*/ |
234
|
|
|
public function serialize() |
235
|
|
|
{ |
236
|
|
|
$parentSerializedData = unserialize(parent::serialize()); |
237
|
|
|
$parentSerializedData['id'] = $this->getId(); |
238
|
|
|
|
239
|
|
|
return serialize($parentSerializedData); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* {@inheritdoc} |
244
|
|
|
*/ |
245
|
|
|
public function unserialize($serialized) |
246
|
|
|
{ |
247
|
|
|
parent::unserialize($serialized); |
248
|
|
|
|
249
|
|
|
$data = unserialize($serialized); |
250
|
|
|
$this->id = $data['id']; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|