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 | public function __construct() |
||
110 | { |
||
111 | $this->nodeVersions = new ArrayCollection(); |
||
112 | $this->setCreated(new \DateTime()); |
||
113 | $this->setUpdated(new \DateTime()); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Set node |
||
118 | * |
||
119 | * @param Node $node |
||
120 | * |
||
121 | * @return NodeTranslation |
||
122 | */ |
||
123 | public function setNode($node) |
||
124 | { |
||
125 | $this->node = $node; |
||
126 | |||
127 | return $this; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Get Node |
||
132 | * |
||
133 | * @return Node |
||
134 | */ |
||
135 | public function getNode() |
||
136 | { |
||
137 | return $this->node; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Set lang |
||
142 | * |
||
143 | * @param string $lang |
||
144 | * |
||
145 | * @return NodeTranslation |
||
146 | */ |
||
147 | public function setLang($lang) |
||
148 | { |
||
149 | $this->lang = $lang; |
||
150 | |||
151 | return $this; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Get lang |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function getLang() |
||
160 | { |
||
161 | return $this->lang; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Is online |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function isOnline() |
||
170 | { |
||
171 | return $this->online; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Set online |
||
176 | * |
||
177 | * @param bool $online |
||
178 | * |
||
179 | * @return NodeTranslation |
||
180 | */ |
||
181 | public function setOnline($online) |
||
182 | { |
||
183 | $this->online = $online; |
||
184 | |||
185 | return $this; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Set title |
||
190 | * |
||
191 | * @param string $title |
||
192 | * |
||
193 | * @return NodeTranslation |
||
194 | */ |
||
195 | public function setTitle($title) |
||
196 | { |
||
197 | $this->title = $title; |
||
198 | |||
199 | return $this; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Get title |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getTitle() |
||
208 | { |
||
209 | return $this->title; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Set slug |
||
214 | * |
||
215 | * @param string $slug |
||
216 | * |
||
217 | * @return NodeTranslation |
||
218 | */ |
||
219 | public function setSlug($slug) |
||
220 | { |
||
221 | $this->slug = $slug; |
||
222 | |||
223 | return $this; |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Get slug |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | public function getFullSlug() |
||
232 | { |
||
233 | $slug = $this->getSlugPart(); |
||
234 | |||
235 | if (empty($slug)) { |
||
236 | return null; |
||
237 | } |
||
238 | |||
239 | return $slug; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | public function getSlugPart() |
||
246 | { |
||
247 | $slug = ''; |
||
248 | $parentNode = $this->getNode()->getParent(); |
||
249 | if ($parentNode !== null) { |
||
250 | $nodeTranslation = $parentNode->getNodeTranslation($this->lang, true); |
||
251 | |||
252 | if ($nodeTranslation !== null) { |
||
253 | $parentSlug = $nodeTranslation->getSlugPart(); |
||
254 | if (!empty($parentSlug)) { |
||
255 | $slug = rtrim($parentSlug, '/') . '/'; |
||
256 | } |
||
257 | } |
||
258 | } |
||
259 | $slug = $slug . $this->getSlug(); |
||
260 | |||
261 | return $slug; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * Get slug |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getSlug() |
||
270 | { |
||
271 | return $this->slug; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @param NodeVersion $publicNodeVersion |
||
276 | * |
||
277 | * @return NodeTranslation |
||
278 | */ |
||
279 | public function setPublicNodeVersion(NodeVersion $publicNodeVersion) |
||
280 | { |
||
281 | $this->publicNodeVersion = $publicNodeVersion; |
||
282 | |||
283 | return $this; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @return NodeVersion |
||
288 | */ |
||
289 | public function getPublicNodeVersion() |
||
290 | { |
||
291 | return $this->publicNodeVersion; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * @return NodeVersion |
||
0 ignored issues
–
show
|
|||
296 | */ |
||
297 | public function getDraftNodeVersion() |
||
298 | { |
||
299 | return $this->getNodeVersion('draft'); |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * @return ArrayCollection |
||
304 | */ |
||
305 | public function getNodeVersions() |
||
306 | { |
||
307 | return $this->nodeVersions; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @param ArrayCollection $nodeVersions |
||
312 | * |
||
313 | * @return NodeTranslation |
||
314 | */ |
||
315 | public function setNodeVersions(ArrayCollection $nodeVersions) |
||
316 | { |
||
317 | $this->nodeVersions = $nodeVersions; |
||
318 | |||
319 | return $this; |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * @param string $type |
||
324 | * |
||
325 | * @return NodeVersion|null |
||
326 | */ |
||
327 | public function getNodeVersion($type) |
||
328 | { |
||
329 | if ($type == 'public') { |
||
330 | return $this->publicNodeVersion; |
||
331 | } |
||
332 | |||
333 | $nodeVersions = $this->getNodeVersions(); |
||
334 | |||
335 | $max = count($nodeVersions); |
||
336 | for ($i = $max - 1; $i >= 0; --$i) { |
||
337 | /* @var NodeVersion $nodeVersion */ |
||
338 | $nodeVersion = $nodeVersions[$i]; |
||
339 | |||
340 | if ($type == $nodeVersion->getType()) { |
||
341 | return $nodeVersion; |
||
342 | } |
||
343 | } |
||
344 | |||
345 | return null; |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Add nodeVersion |
||
350 | * |
||
351 | * @param NodeVersion $nodeVersion |
||
352 | * |
||
353 | * @return NodeTranslation |
||
354 | */ |
||
355 | public function addNodeVersion(NodeVersion $nodeVersion) |
||
356 | { |
||
357 | $this->nodeVersions[] = $nodeVersion; |
||
358 | $nodeVersion->setNodeTranslation($this); |
||
359 | |||
360 | if ($nodeVersion->getType() == 'public') { |
||
361 | $this->publicNodeVersion = $nodeVersion; |
||
362 | } |
||
363 | |||
364 | return $this; |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @return string |
||
369 | */ |
||
370 | public function getDefaultAdminType() |
||
371 | { |
||
372 | return NodeTranslationAdminType::class; |
||
373 | } |
||
374 | |||
375 | /** |
||
376 | * @param EntityManager $em The entity manager |
||
377 | * @param string $type The type |
||
378 | * |
||
379 | * @return object|null |
||
380 | */ |
||
381 | public function getRef(EntityManager $em, $type = 'public') |
||
382 | { |
||
383 | $nodeVersion = $this->getNodeVersion($type); |
||
384 | if ($nodeVersion) { |
||
385 | return $em->getRepository($nodeVersion->getRefEntityName())->find($nodeVersion->getRefId()); |
||
386 | } |
||
387 | |||
388 | return null; |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * @param string $url |
||
393 | * |
||
394 | * @return NodeTranslation |
||
395 | */ |
||
396 | public function setUrl($url) |
||
397 | { |
||
398 | $this->url = $url; |
||
399 | |||
400 | return $this; |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * @return string |
||
405 | */ |
||
406 | public function getUrl() |
||
407 | { |
||
408 | return $this->url; |
||
409 | } |
||
410 | |||
411 | /** |
||
412 | * @param int $weight |
||
413 | * |
||
414 | * @return NodeTranslation |
||
415 | */ |
||
416 | public function setWeight($weight) |
||
417 | { |
||
418 | $this->weight = $weight; |
||
419 | |||
420 | return $this; |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * @return int |
||
425 | */ |
||
426 | public function getWeight() |
||
427 | { |
||
428 | return $this->weight; |
||
429 | } |
||
430 | |||
431 | /** |
||
432 | * @return \DateTime |
||
433 | */ |
||
434 | public function getCreated() |
||
435 | { |
||
436 | return $this->created; |
||
437 | } |
||
438 | |||
439 | /** |
||
440 | * @param \DateTime $created |
||
441 | * |
||
442 | * @return NodeTranslation |
||
443 | */ |
||
444 | public function setCreated($created) |
||
445 | { |
||
446 | $this->created = $created; |
||
447 | |||
448 | return $this; |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * @return \DateTime |
||
453 | */ |
||
454 | public function getUpdated() |
||
455 | { |
||
456 | return $this->updated; |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @param \DateTime $updated |
||
461 | * |
||
462 | * @return NodeTranslation |
||
463 | */ |
||
464 | public function setUpdated($updated) |
||
465 | { |
||
466 | $this->updated = $updated; |
||
467 | |||
468 | return $this; |
||
469 | } |
||
470 | } |
||
471 |
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.