1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\ValidComponentInterface; |
10
|
|
|
use Silverback\ApiComponentBundle\Entity\ValidComponentTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class ComponentGroup |
14
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Content\Component |
15
|
|
|
* @author Daniel West <[email protected]> |
16
|
|
|
* @ApiResource() |
17
|
|
|
* @ORM\Entity() |
18
|
|
|
*/ |
19
|
|
|
class ComponentGroup extends AbstractContent implements ValidComponentInterface |
20
|
|
|
{ |
21
|
|
|
use ValidComponentTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent", inversedBy="componentGroups") |
25
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
26
|
|
|
* @var AbstractComponent |
27
|
|
|
*/ |
28
|
|
|
protected $parent; |
29
|
|
|
|
30
|
18 |
|
public function __construct() |
31
|
|
|
{ |
32
|
18 |
|
$this->validComponents = new ArrayCollection; |
33
|
18 |
|
parent::__construct(); |
34
|
18 |
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return AbstractComponent |
39
|
|
|
*/ |
40
|
1 |
|
public function getParent(): AbstractComponent |
41
|
|
|
{ |
42
|
1 |
|
return $this->parent; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param AbstractComponent $parent |
47
|
|
|
* @param bool|null $cascadeValidComponent |
48
|
|
|
*/ |
49
|
13 |
|
public function setParent(AbstractComponent $parent, ?bool $cascadeValidComponent = null): void |
50
|
|
|
{ |
51
|
13 |
|
$this->parent = $parent; |
52
|
13 |
|
if ($cascadeValidComponent !== false) { |
53
|
|
|
// convert to bool again for $force (null becomes false) |
54
|
13 |
|
$this->cascadeValidComponents($parent, (bool) $cascadeValidComponent); |
55
|
|
|
} |
56
|
13 |
|
} |
57
|
|
|
|
58
|
1 |
|
public function hasComponent(AbstractComponent $component) |
59
|
|
|
{ |
60
|
1 |
|
foreach ($this->getComponents() as $componentLocation) { |
61
|
|
|
if ($component === $componentLocation->getComponent()) { |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
} |
65
|
1 |
|
return false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|