These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\NodeBundle\Entity; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | use Doctrine\ORM\EntityManager; |
||
7 | use Doctrine\ORM\Mapping as ORM; |
||
8 | use Kunstmaan\AdminBundle\Entity\AbstractEntity; |
||
9 | use Kunstmaan\NodeBundle\Form\NodeTranslationAdminType; |
||
10 | use Symfony\Component\Validator\Constraints as Assert; |
||
11 | |||
12 | /** |
||
13 | * NodeTranslation |
||
14 | * |
||
15 | * @ORM\Entity(repositoryClass="Kunstmaan\NodeBundle\Repository\NodeTranslationRepository") |
||
16 | * @ORM\Table( |
||
17 | * name="kuma_node_translations", |
||
18 | * uniqueConstraints={@ORM\UniqueConstraint(name="ix_kuma_node_translations_node_lang", columns={"node_id", "lang"})}, |
||
19 | * indexes={@ORM\Index(name="idx__node_translation_lang_url", columns={"lang", "url"})} |
||
20 | * ) |
||
21 | * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
||
22 | */ |
||
23 | class NodeTranslation extends AbstractEntity |
||
24 | { |
||
25 | /** |
||
26 | * @var Node |
||
27 | * |
||
28 | * @ORM\ManyToOne(targetEntity="Node", inversedBy="nodeTranslations") |
||
29 | * @ORM\JoinColumn(name="node_id", referencedColumnName="id") |
||
30 | */ |
||
31 | protected $node; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | * |
||
36 | * @ORM\Column(type="string") |
||
37 | */ |
||
38 | protected $lang; |
||
39 | |||
40 | /** |
||
41 | * @var bool |
||
42 | * |
||
43 | * @ORM\Column(type="boolean") |
||
44 | */ |
||
45 | protected $online = false; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | * |
||
50 | * @ORM\Column(type="string") |
||
51 | */ |
||
52 | protected $title; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | * |
||
57 | * @ORM\Column(type="string", nullable=true) |
||
58 | * @Assert\Regex("/^[a-zA-Z0-9\-_\/]+$/") |
||
59 | */ |
||
60 | protected $slug; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | * |
||
65 | * @ORM\Column(type="string", nullable=true) |
||
66 | */ |
||
67 | protected $url; |
||
68 | |||
69 | /** |
||
70 | * @var NodeVersion |
||
71 | * |
||
72 | * @ORM\ManyToOne(targetEntity="NodeVersion") |
||
73 | * @ORM\JoinColumn(name="public_node_version_id", referencedColumnName="id") |
||
74 | */ |
||
75 | protected $publicNodeVersion; |
||
76 | |||
77 | /** |
||
78 | * @var ArrayCollection |
||
79 | * @Assert\Valid() |
||
80 | * @ORM\OneToMany(targetEntity="NodeVersion", mappedBy="nodeTranslation") |
||
81 | * @ORM\OrderBy({"created" = "ASC"}) |
||
82 | */ |
||
83 | protected $nodeVersions; |
||
84 | |||
85 | /** |
||
86 | * @var int |
||
87 | * |
||
88 | * @ORM\Column(type="smallint", nullable=true) |
||
89 | */ |
||
90 | protected $weight; |
||
91 | |||
92 | /** |
||
93 | * @var \DateTime |
||
94 | * |
||
95 | * @ORM\Column(type="datetime", nullable=true) |
||
96 | */ |
||
97 | protected $created; |
||
98 | |||
99 | /** |
||
100 | * @var \DateTime |
||
101 | * |
||
102 | * @ORM\Column(type="datetime", nullable=true) |
||
103 | */ |
||
104 | protected $updated; |
||
105 | |||
106 | /** |
||
107 | * contructor |
||
108 | */ |
||
109 | 59 | public function __construct() |
|
110 | { |
||
111 | 59 | $this->nodeVersions = new ArrayCollection(); |
|
112 | 59 | $this->setCreated(new \DateTime()); |
|
113 | 59 | $this->setUpdated(new \DateTime()); |
|
114 | 59 | } |
|
115 | |||
116 | /** |
||
117 | * Set node |
||
118 | * |
||
119 | * @param Node $node |
||
120 | * |
||
121 | * @return NodeTranslation |
||
122 | */ |
||
123 | 30 | public function setNode($node) |
|
124 | { |
||
125 | 30 | $this->node = $node; |
|
126 | |||
127 | 30 | return $this; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Get Node |
||
132 | * |
||
133 | * @return Node |
||
134 | */ |
||
135 | 14 | public function getNode() |
|
136 | { |
||
137 | 14 | return $this->node; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Set lang |
||
142 | * |
||
143 | * @param string $lang |
||
144 | * |
||
145 | * @return NodeTranslation |
||
146 | */ |
||
147 | 17 | public function setLang($lang) |
|
148 | { |
||
149 | 17 | $this->lang = $lang; |
|
150 | |||
151 | 17 | return $this; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * Get lang |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 13 | public function getLang() |
|
160 | { |
||
161 | 13 | return $this->lang; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * Is online |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | 8 | public function isOnline() |
|
170 | { |
||
171 | 8 | return $this->online; |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * Set online |
||
176 | * |
||
177 | * @param bool $online |
||
178 | * |
||
179 | * @return NodeTranslation |
||
180 | */ |
||
181 | 13 | public function setOnline($online) |
|
182 | { |
||
183 | 13 | $this->online = $online; |
|
184 | |||
185 | 13 | return $this; |
|
186 | } |
||
187 | |||
188 | /** |
||
189 | * Set title |
||
190 | * |
||
191 | * @param string $title |
||
192 | * |
||
193 | * @return NodeTranslation |
||
194 | */ |
||
195 | 10 | public function setTitle($title) |
|
196 | { |
||
197 | 10 | $this->title = $title; |
|
198 | |||
199 | 10 | return $this; |
|
200 | } |
||
201 | |||
202 | /** |
||
203 | * Get title |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | 3 | public function getTitle() |
|
208 | { |
||
209 | 3 | return $this->title; |
|
210 | } |
||
211 | |||
212 | /** |
||
213 | * Set slug |
||
214 | * |
||
215 | * @param string $slug |
||
216 | * |
||
217 | * @return NodeTranslation |
||
218 | */ |
||
219 | 3 | public function setSlug($slug) |
|
220 | { |
||
221 | 3 | $this->slug = $slug; |
|
222 | |||
223 | 3 | return $this; |
|
224 | } |
||
225 | |||
226 | /** |
||
227 | * Get slug |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | 2 | public function getFullSlug() |
|
232 | { |
||
233 | 2 | $slug = $this->getSlugPart(); |
|
234 | |||
235 | 2 | if (empty($slug)) { |
|
236 | 1 | return null; |
|
237 | } |
||
238 | |||
239 | 1 | return $slug; |
|
240 | } |
||
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | 2 | public function getSlugPart() |
|
246 | { |
||
247 | 2 | $slug = ''; |
|
248 | 2 | $parentNode = $this->getNode()->getParent(); |
|
249 | 2 | if ($parentNode !== null) { |
|
250 | 1 | $nodeTranslation = $parentNode->getNodeTranslation($this->lang, true); |
|
251 | |||
252 | 1 | if ($nodeTranslation !== null) { |
|
253 | 1 | $parentSlug = $nodeTranslation->getSlugPart(); |
|
254 | 1 | if (!empty($parentSlug)) { |
|
255 | 1 | $slug = rtrim($parentSlug, '/') . '/'; |
|
256 | } |
||
257 | } |
||
258 | } |
||
259 | 2 | $slug .= $this->getSlug(); |
|
260 | |||
261 | 2 | return $slug; |
|
262 | } |
||
263 | |||
264 | /** |
||
265 | * Get slug |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 3 | public function getSlug() |
|
270 | { |
||
271 | 3 | return $this->slug; |
|
272 | } |
||
273 | |||
274 | /** |
||
275 | * @return NodeTranslation |
||
276 | */ |
||
277 | 6 | public function setPublicNodeVersion(NodeVersion $publicNodeVersion) |
|
278 | { |
||
279 | 6 | $this->publicNodeVersion = $publicNodeVersion; |
|
280 | |||
281 | 6 | return $this; |
|
282 | } |
||
283 | |||
284 | /** |
||
285 | * @return NodeVersion |
||
286 | */ |
||
287 | 11 | public function getPublicNodeVersion() |
|
288 | { |
||
289 | 11 | return $this->publicNodeVersion; |
|
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return NodeVersion |
||
0 ignored issues
–
show
|
|||
294 | */ |
||
295 | 1 | public function getDraftNodeVersion() |
|
296 | { |
||
297 | 1 | return $this->getNodeVersion('draft'); |
|
298 | } |
||
299 | |||
300 | /** |
||
301 | * @return ArrayCollection |
||
302 | */ |
||
303 | 4 | public function getNodeVersions() |
|
304 | { |
||
305 | 4 | return $this->nodeVersions; |
|
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return NodeTranslation |
||
310 | */ |
||
311 | 2 | public function setNodeVersions(ArrayCollection $nodeVersions) |
|
312 | { |
||
313 | 2 | $this->nodeVersions = $nodeVersions; |
|
314 | |||
315 | 2 | return $this; |
|
316 | } |
||
317 | |||
318 | /** |
||
319 | * @param string $type |
||
320 | * |
||
321 | * @return NodeVersion|null |
||
322 | */ |
||
323 | 4 | public function getNodeVersion($type) |
|
324 | { |
||
325 | 4 | if ($type == 'public') { |
|
326 | 2 | return $this->publicNodeVersion; |
|
327 | } |
||
328 | |||
329 | 3 | $nodeVersions = $this->getNodeVersions(); |
|
330 | |||
331 | 3 | $max = \count($nodeVersions); |
|
332 | 3 | for ($i = $max - 1; $i >= 0; --$i) { |
|
333 | /* @var NodeVersion $nodeVersion */ |
||
334 | 2 | $nodeVersion = $nodeVersions[$i]; |
|
335 | |||
336 | 2 | if ($type == $nodeVersion->getType()) { |
|
337 | 2 | return $nodeVersion; |
|
338 | } |
||
339 | } |
||
340 | |||
341 | 1 | return null; |
|
342 | } |
||
343 | |||
344 | /** |
||
345 | * Add nodeVersion |
||
346 | * |
||
347 | * @return NodeTranslation |
||
348 | */ |
||
349 | 11 | public function addNodeVersion(NodeVersion $nodeVersion) |
|
350 | { |
||
351 | 11 | $this->nodeVersions[] = $nodeVersion; |
|
352 | 11 | $nodeVersion->setNodeTranslation($this); |
|
353 | |||
354 | 11 | if ($nodeVersion->getType() == 'public') { |
|
355 | 10 | $this->publicNodeVersion = $nodeVersion; |
|
356 | } |
||
357 | |||
358 | 11 | return $this; |
|
359 | } |
||
360 | |||
361 | /** |
||
362 | * @return string |
||
363 | */ |
||
364 | 1 | public function getDefaultAdminType() |
|
365 | { |
||
366 | 1 | return NodeTranslationAdminType::class; |
|
367 | } |
||
368 | |||
369 | /** |
||
370 | * @param EntityManager $em The entity manager |
||
371 | * @param string $type The type |
||
372 | * |
||
373 | * @return object|null |
||
374 | */ |
||
375 | 1 | public function getRef(EntityManager $em, $type = 'public') |
|
376 | { |
||
377 | 1 | $nodeVersion = $this->getNodeVersion($type); |
|
378 | 1 | if ($nodeVersion) { |
|
379 | 1 | return $em->getRepository($nodeVersion->getRefEntityName())->find($nodeVersion->getRefId()); |
|
380 | } |
||
381 | |||
382 | 1 | return null; |
|
383 | } |
||
384 | |||
385 | /** |
||
386 | * @param string $url |
||
387 | * |
||
388 | * @return NodeTranslation |
||
389 | */ |
||
390 | 2 | public function setUrl($url) |
|
391 | { |
||
392 | 2 | $this->url = $url; |
|
393 | |||
394 | 2 | return $this; |
|
395 | } |
||
396 | |||
397 | /** |
||
398 | * @return string |
||
399 | */ |
||
400 | 7 | public function getUrl() |
|
401 | { |
||
402 | 7 | return $this->url; |
|
403 | } |
||
404 | |||
405 | /** |
||
406 | * @param int $weight |
||
407 | * |
||
408 | * @return NodeTranslation |
||
409 | */ |
||
410 | 2 | public function setWeight($weight) |
|
411 | { |
||
412 | 2 | $this->weight = $weight; |
|
413 | |||
414 | 2 | return $this; |
|
415 | } |
||
416 | |||
417 | /** |
||
418 | * @return int |
||
419 | */ |
||
420 | 2 | public function getWeight() |
|
421 | { |
||
422 | 2 | return $this->weight; |
|
423 | } |
||
424 | |||
425 | /** |
||
426 | * @return \DateTime |
||
427 | */ |
||
428 | 1 | public function getCreated() |
|
429 | { |
||
430 | 1 | return $this->created; |
|
431 | } |
||
432 | |||
433 | /** |
||
434 | * @param \DateTime $created |
||
435 | * |
||
436 | * @return NodeTranslation |
||
437 | */ |
||
438 | 59 | public function setCreated($created) |
|
439 | { |
||
440 | 59 | $this->created = $created; |
|
441 | |||
442 | 59 | return $this; |
|
443 | } |
||
444 | |||
445 | /** |
||
446 | * @return \DateTime |
||
447 | */ |
||
448 | 1 | public function getUpdated() |
|
449 | { |
||
450 | 1 | return $this->updated; |
|
451 | } |
||
452 | |||
453 | /** |
||
454 | * @param \DateTime $updated |
||
455 | * |
||
456 | * @return NodeTranslation |
||
457 | */ |
||
458 | 59 | public function setUpdated($updated) |
|
459 | { |
||
460 | 59 | $this->updated = $updated; |
|
461 | |||
462 | 59 | return $this; |
|
463 | } |
||
464 | } |
||
465 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.