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