1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content\Dynamic; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\PageTrait; |
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\Route; |
11
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareInterface; |
12
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareTrait; |
13
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
14
|
|
|
|
15
|
|
|
abstract class AbstractDynamicPage extends AbstractContent implements RouteAwareInterface |
16
|
|
|
{ |
17
|
|
|
use RouteAwareTrait; |
18
|
|
|
use PageTrait { |
19
|
|
|
getParentRoute as getParentParentRoute; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ApiProperty() |
24
|
|
|
* @Groups({"content","route"}) |
25
|
|
|
*/ |
26
|
|
|
public function isDynamic() |
27
|
|
|
{ |
28
|
|
|
return true; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route") |
33
|
|
|
* @ORM\JoinColumn(nullable=true, referencedColumnName="route") |
34
|
|
|
* @var Route|null |
35
|
|
|
*/ |
36
|
|
|
protected $parentRoute; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\Column(type="boolean", options={"default":"0"}) |
40
|
|
|
* @var boolean |
41
|
|
|
*/ |
42
|
|
|
protected $nested = false; |
43
|
|
|
|
44
|
|
|
/** @Groups({"dynamic_content", "route"}) */ |
45
|
|
|
protected $componentLocations; |
46
|
|
|
|
47
|
3 |
|
public function __construct() |
48
|
|
|
{ |
49
|
3 |
|
parent::__construct(); |
50
|
3 |
|
$this->routes = new ArrayCollection; |
51
|
3 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param null|Route $parentRoute |
55
|
|
|
*/ |
56
|
|
|
public function setParentRoute(?Route $parentRoute): void |
57
|
|
|
{ |
58
|
|
|
$this->parentRoute = $parentRoute; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
64
|
2 |
|
public function getParentRoute(): ?Route |
65
|
|
|
{ |
66
|
2 |
|
if ($this->parentRoute) { |
67
|
|
|
return $this->parentRoute; |
68
|
|
|
} |
69
|
2 |
|
if ($this->nested) { |
70
|
|
|
return $this->getParentParentRoute(); |
71
|
|
|
} |
72
|
2 |
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function isNested(): bool |
79
|
|
|
{ |
80
|
|
|
return $this->nested; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param bool $nested |
85
|
|
|
*/ |
86
|
|
|
public function setNested(bool $nested): void |
87
|
|
|
{ |
88
|
|
|
$this->nested = $nested; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|