1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
10
|
|
|
use Ramsey\Uuid\Uuid; |
11
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\ComponentLocation; |
12
|
|
|
use Silverback\ApiComponentBundle\Entity\TimestampedEntityTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AbstractContent |
16
|
|
|
* @package Silverback\ApiComponentBundle\Entity |
17
|
|
|
* @author Daniel West <[email protected]> |
18
|
|
|
* @ORM\Entity() |
19
|
|
|
* @ORM\Table(name="content") |
20
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
21
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
22
|
|
|
* @ORM\DiscriminatorMap({ |
23
|
|
|
* "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup\ComponentGroup", |
24
|
|
|
* "abstract_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\AbstractPage", |
25
|
|
|
* "page" = "Silverback\ApiComponentBundle\Entity\Content\Page\Page", |
26
|
|
|
* "dynamic_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\AbstractDynamicPage", |
27
|
|
|
* "article_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\ArticlePage" |
28
|
|
|
* }) |
29
|
|
|
*/ |
30
|
|
|
abstract class AbstractContent implements ContentInterface |
31
|
|
|
{ |
32
|
|
|
use TimestampedEntityTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @ORM\Id() |
36
|
|
|
* @ORM\Column(type="string") |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $id; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Component\ComponentLocation", mappedBy="content", cascade={"persist", "remove"}) |
43
|
|
|
* @ORM\OrderBy({"sort"="ASC"}) |
44
|
|
|
* @var Collection|ComponentLocation[] |
45
|
|
|
*/ |
46
|
|
|
protected $componentLocations; |
47
|
7 |
|
|
48
|
|
|
public function __construct() |
49
|
7 |
|
{ |
50
|
7 |
|
$this->id = Uuid::uuid4()->getHex(); |
51
|
7 |
|
$this->componentLocations = new ArrayCollection; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getId(): string |
58
|
|
|
{ |
59
|
|
|
return $this->id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return Collection|ComponentLocation[] |
64
|
|
|
*/ |
65
|
|
|
public function getComponentLocations(): Collection |
66
|
|
|
{ |
67
|
|
|
return $this->componentLocations; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param \Silverback\ApiComponentBundle\Entity\Component\ComponentLocation[]|iterable $componentLocations |
72
|
|
|
* @return AbstractContent |
73
|
|
|
*/ |
74
|
|
|
public function setComponentLocations(iterable $componentLocations): AbstractContent |
75
|
|
|
{ |
76
|
|
|
$this->componentLocations = new ArrayCollection; |
77
|
|
|
/** @var ComponentLocation $componentLocation */ |
78
|
|
|
foreach ($componentLocations as $componentLocation) { |
79
|
|
|
$this->addComponentLocation($componentLocation); |
80
|
|
|
} |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param ComponentLocation $componentLocation |
86
|
|
|
* @return AbstractContent |
87
|
|
|
*/ |
88
|
|
|
public function addComponentLocation(ComponentLocation $componentLocation): AbstractContent |
89
|
|
|
{ |
90
|
|
|
if (!$this->componentLocations->contains($componentLocation)) { |
91
|
|
|
$this->componentLocations->add($componentLocation); |
92
|
|
|
$componentLocation->setContent($this); |
93
|
|
|
} |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param ComponentLocation $componentLocation |
99
|
|
|
* @return AbstractContent |
100
|
|
|
*/ |
101
|
|
|
public function removeComponentLocation(ComponentLocation $componentLocation): AbstractContent |
102
|
|
|
{ |
103
|
|
|
if ($this->componentLocations->contains($componentLocation)) { |
104
|
|
|
$this->componentLocations->removeElement($componentLocation); |
105
|
|
|
if ($componentLocation->getContent() === $this) { |
106
|
|
|
$componentLocation->setContent(null); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|