Completed
Push — master ( 926740...1237f3 )
by Daniel
91:04 queued 79:23
created

AbstractContent::getSecurityRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
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\RestrictedResourceInterface;
13
use Silverback\ApiComponentBundle\Entity\RestrictedResourceTrait;
14
use Silverback\ApiComponentBundle\Entity\TimestampedEntityTrait;
15
16
/**
17
 * @ORM\Entity(repositoryClass="Silverback\ApiComponentBundle\Repository\Content\AbstractContentRepository")
18
 * @ORM\Table(name="content")
19
 * @ORM\InheritanceType("SINGLE_TABLE")
20
 * @ORM\DiscriminatorColumn(name="type", type="string")
21
 * @ORM\DiscriminatorMap({
22
 *     "abstract_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\AbstractPage",
23
 *     "static_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\StaticPage",
24
 *     "dynamic_page" = "Silverback\ApiComponentBundle\Entity\Content\Page\DynamicPage",
25
 *     "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup\ComponentGroup"
26
 * })
27
 */
28
abstract class AbstractContent implements ContentInterface, RestrictedResourceInterface
29
{
30
    use TimestampedEntityTrait;
31
    use RestrictedResourceTrait;
32
33
    /**
34
     * @ORM\Id()
35
     * @ORM\Column(type="string", length=36)
36
     * @var string
37
     */
38
    protected $id;
39
40
    /**
41
     * @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Component\ComponentLocation", mappedBy="content", cascade={"persist", "remove"})
42
     * @ORM\OrderBy({"sort"="ASC"})
43
     * @var Collection|ComponentLocation[]
44
     */
45
    protected $componentLocations;
46
47 7
    public function __construct()
48
    {
49 7
        $this->id = Uuid::uuid4()->getHex();
50 7
        $this->componentLocations = new ArrayCollection;
51 7
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getId(): string
57
    {
58
        return $this->id;
59
    }
60
61
    /**
62
     * @return Collection|ComponentLocation[]
63
     */
64
    public function getComponentLocations(): Collection
65
    {
66
        return $this->componentLocations;
67
    }
68
69
    /**
70
     * @param ComponentLocation[]|iterable $componentLocations
71
     * @return AbstractContent
72
     */
73
    public function setComponentLocations(iterable $componentLocations): AbstractContent
74
    {
75
        $this->componentLocations = new ArrayCollection;
76
        /** @var ComponentLocation $componentLocation */
77
        foreach ($componentLocations as $componentLocation) {
78
            $this->addComponentLocation($componentLocation);
79
        }
80
        return $this;
81
    }
82
83
    /**
84
     * @param ComponentLocation $componentLocation
85
     * @return AbstractContent
86
     */
87
    public function addComponentLocation(ComponentLocation $componentLocation): AbstractContent
88
    {
89
        if (!$this->componentLocations->contains($componentLocation)) {
90
            $this->componentLocations->add($componentLocation);
91
            $componentLocation->setContent($this);
92
        }
93
        return $this;
94
    }
95
96
    /**
97
     * @param ComponentLocation $componentLocation
98
     * @return AbstractContent
99
     */
100
    public function removeComponentLocation(ComponentLocation $componentLocation): AbstractContent
101
    {
102
        if ($this->componentLocations->contains($componentLocation)) {
103
            $this->componentLocations->removeElement($componentLocation);
104
            if ($componentLocation->getContent() === $this) {
105
                $componentLocation->setContent(null);
106
            }
107
        }
108
        return $this;
109
    }
110
}
111