1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Entity\Core; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
17
|
|
|
use Doctrine\Common\Collections\Collection; |
18
|
|
|
use Silverback\ApiComponentsBundle\Annotation as Silverback; |
19
|
|
|
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait; |
20
|
|
|
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait; |
21
|
|
|
use Silverback\ApiComponentsBundle\Validator\Constraints as AcbAssert; |
22
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
23
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Daniel West <[email protected]> |
27
|
|
|
* |
28
|
|
|
* @Silverback\Timestamped |
29
|
|
|
* @ApiResource(mercure=true, attributes={"order"={"sortValue"="ASC"}}, normalizationContext={"groups"={"ComponentPosition:read"}}, denormalizationContext={"groups"={"ComponentPosition:write"}}) |
30
|
|
|
* @AcbAssert\ComponentPosition |
31
|
|
|
* @Assert\Expression( |
32
|
|
|
* "!(this.component == null & this.pageDataProperty == null)", |
33
|
|
|
* message="Please specify either a component or pageDataProperty.", |
34
|
|
|
* ) |
35
|
|
|
*/ |
36
|
|
|
class ComponentPosition |
37
|
|
|
{ |
38
|
|
|
use IdTrait; |
39
|
|
|
use TimestampedTrait; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Assert\NotNull() |
43
|
|
|
* @Groups({"ComponentPosition:read", "ComponentPosition:write", "AbstractComponent:component:write"}) |
44
|
|
|
*/ |
45
|
|
|
public ?ComponentCollection $componentCollection = null; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @Groups({"ComponentPosition:read", "ComponentPosition:write"}) |
49
|
|
|
*/ |
50
|
|
|
public ?AbstractComponent $component = null; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Groups({"ComponentPosition:read:role_admin", "ComponentPosition:write"}) |
54
|
|
|
*/ |
55
|
|
|
public ?string $pageDataProperty = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Assert\NotNull() |
59
|
|
|
* @Groups({"ComponentPosition:read", "ComponentPosition:write"}) |
60
|
|
|
*/ |
61
|
|
|
public ?int $sortValue = null; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ComponentPosition[]|Collection|null |
65
|
|
|
*/ |
66
|
|
|
public function getSortCollection(): ?Collection |
67
|
|
|
{ |
68
|
|
|
return $this->componentCollection ? $this->componentCollection->componentPositions : null; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setComponentCollection(ComponentCollection $componentCollection): self |
72
|
|
|
{ |
73
|
|
|
$this->componentCollection = $componentCollection; |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setComponent(AbstractComponent $component): self |
79
|
|
|
{ |
80
|
|
|
$this->component = $component; |
81
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setSortValue(int $sortValue): self |
86
|
|
|
{ |
87
|
|
|
$this->sortValue = $sortValue; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getPageDataProperty(): ?string |
93
|
|
|
{ |
94
|
|
|
return $this->pageDataProperty; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setPageDataProperty(?string $pageDataProperty): self |
98
|
|
|
{ |
99
|
|
|
$this->pageDataProperty = $pageDataProperty; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|