1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content; |
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\Component\ComponentLocation; |
10
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
11
|
|
|
use Symfony\Component\Serializer\Annotation\MaxDepth; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class AbstractContent |
15
|
|
|
* @package Silverback\ApiComponentBundle\Entity |
16
|
|
|
* @author Daniel West <[email protected]> |
17
|
|
|
* @ORM\Entity() |
18
|
|
|
* @ORM\Table(name="route_content") |
19
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
20
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
21
|
|
|
* @ORM\DiscriminatorMap({ |
22
|
|
|
* "page" = "Silverback\ApiComponentBundle\Entity\Content\Page", |
23
|
|
|
* "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup" |
24
|
|
|
* }) |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractContent implements ContentInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @ORM\Id() |
30
|
|
|
* @ORM\Column(type="string") |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation", mappedBy="content", cascade={"persist", "remove"}) |
37
|
|
|
* @Groups({"content", "route"}) |
38
|
|
|
* @MaxDepth(10) |
39
|
|
|
* @var Collection|ComponentLocation[] |
40
|
|
|
*/ |
41
|
|
|
protected $componentLocations; |
42
|
|
|
|
43
|
26 |
|
public function __construct() |
44
|
|
|
{ |
45
|
26 |
|
$this->id = Uuid::uuid4()->getHex(); |
46
|
26 |
|
$this->componentLocations = new ArrayCollection; |
47
|
26 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getId(): string |
53
|
|
|
{ |
54
|
|
|
return $this->id; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Collection|ComponentLocation[] |
59
|
|
|
*/ |
60
|
2 |
|
public function getComponentLocations(): Collection |
61
|
|
|
{ |
62
|
2 |
|
return $this->componentLocations; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param ComponentLocation $componentLocation |
67
|
|
|
* @return AbstractContent |
68
|
|
|
*/ |
69
|
1 |
|
public function addComponentLocation(ComponentLocation $componentLocation): AbstractContent |
70
|
|
|
{ |
71
|
1 |
|
$this->componentLocations->add($componentLocation); |
72
|
1 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ComponentLocation $componentLocation |
77
|
|
|
* @return AbstractContent |
78
|
|
|
*/ |
79
|
|
|
public function removeComponentLocation(ComponentLocation $componentLocation): AbstractContent |
80
|
|
|
{ |
81
|
|
|
$this->componentLocations->removeElement($componentLocation); |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|