|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content\Component; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
8
|
|
|
use Ramsey\Uuid\Uuid; |
|
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent; |
|
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\Feature\AbstractFeatureItem; |
|
11
|
|
|
use Silverback\ApiComponentBundle\Entity\SortableInterface; |
|
12
|
|
|
use Silverback\ApiComponentBundle\Entity\SortableTrait; |
|
13
|
|
|
use Silverback\ApiComponentBundle\Validator\Constraints as ACBAssert; |
|
14
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
15
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
16
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class ComponentLocation |
|
20
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Content\Component |
|
21
|
|
|
* @ACBAssert\ComponentLocation() |
|
22
|
|
|
* @ORM\Entity(repositoryClass="Silverback\ApiComponentBundle\Repository\ComponentLocationRepository") |
|
23
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
|
24
|
|
|
*/ |
|
25
|
|
|
class ComponentLocation implements SortableInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use SortableTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @ORM\Id |
|
31
|
|
|
* @ORM\Column(type="string") |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $id; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\AbstractContent", inversedBy="componentLocations") |
|
38
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
|
39
|
|
|
* @Groups({"component"}) |
|
40
|
|
|
* @var AbstractContent |
|
41
|
|
|
*/ |
|
42
|
|
|
private $content; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent", inversedBy="locations") |
|
46
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
|
47
|
|
|
* @Groups({"default"}) |
|
48
|
|
|
* @var AbstractComponent |
|
49
|
|
|
*/ |
|
50
|
|
|
private $component; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @ORM\Column(type="string", nullable=true) |
|
54
|
|
|
* @var null|string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $dynamicPageClass; |
|
57
|
|
|
|
|
58
|
1 |
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$metadata->addPropertyConstraint( |
|
61
|
1 |
|
'content', |
|
62
|
1 |
|
new Assert\NotBlank() |
|
63
|
|
|
); |
|
64
|
1 |
|
$metadata->addPropertyConstraint( |
|
65
|
1 |
|
'component', |
|
66
|
1 |
|
new Assert\NotBlank() |
|
67
|
|
|
); |
|
68
|
1 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* ComponentLocation constructor. |
|
72
|
|
|
* @param null|AbstractContent $newContent |
|
73
|
|
|
* @param null|AbstractComponent $newComponent |
|
74
|
|
|
*/ |
|
75
|
4 |
|
public function __construct( |
|
76
|
|
|
?AbstractContent $newContent = null, |
|
77
|
|
|
?AbstractComponent $newComponent = null |
|
78
|
|
|
) { |
|
79
|
4 |
|
$this->id = Uuid::uuid4()->getHex(); |
|
80
|
4 |
|
if ($newContent) { |
|
81
|
|
|
$this->setContent($newContent); |
|
82
|
|
|
} |
|
83
|
4 |
|
if ($newComponent) { |
|
84
|
|
|
$this->setComponent($newComponent); |
|
85
|
|
|
} |
|
86
|
4 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getId(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->id; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return AbstractContent|null |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getContent(): ?AbstractContent |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->content; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param AbstractContent $content |
|
106
|
|
|
* @param bool|null $sortLast |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setContent(?AbstractContent $content, ?bool $sortLast = true): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->content = $content; |
|
111
|
|
|
if (null === $this->sort || $sortLast !== null) { |
|
112
|
|
|
$this->setSort($this->calculateSort($sortLast)); |
|
113
|
|
|
} |
|
114
|
|
|
if ($this->content) { |
|
115
|
|
|
$this->content->addComponentLocation($this); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return AbstractComponent |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getComponent(): AbstractComponent |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->component; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param AbstractComponent $component |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setComponent(AbstractComponent $component): void |
|
131
|
|
|
{ |
|
132
|
|
|
$this->component = $component; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return Collection|AbstractFeatureItem[] |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getSortCollection(): Collection |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->content ? $this->content->getComponentLocations() : new ArrayCollection; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return null|string |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getDynamicPageClass(): ?string |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->dynamicPageClass; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param null|string $dynamicPageClass |
|
153
|
|
|
*/ |
|
154
|
|
|
public function setDynamicPageClass(?string $dynamicPageClass): void |
|
155
|
|
|
{ |
|
156
|
|
|
$this->dynamicPageClass = $dynamicPageClass; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|