|
24 | 24 | use Doctrine\Common\Collections\Collection; |
25 | 25 | use Doctrine\ORM\Mapping as ORM; |
26 | 26 | use Symfony\Component\Serializer\Annotation\Groups; |
| 27 | +use Symfony\Component\Serializer\Attribute\SerializedName; |
27 | 28 | use Symfony\Component\Validator\Constraints as Assert; |
28 | 29 |
|
29 | 30 | /** |
@@ -71,14 +72,6 @@ class MaterialItem extends BaseEntity implements BelongsToCampInterface, CopyFro |
71 | 72 | #[ORM\JoinColumn(nullable: false, onDelete: 'cascade')] |
72 | 73 | public ?Camp $camp = null; |
73 | 74 |
|
74 | | - /** |
75 | | - * The list to which this item belongs. Lists are used to keep track of who is |
76 | | - * responsible to prepare and bring the item to the camp. |
77 | | - */ |
78 | | - #[Assert\NotNull] |
79 | | - #[AssertBelongsToSameCamp] |
80 | | - #[ApiProperty(example: '/material_lists/1a2b3c4d')] |
81 | | - #[Groups(['read', 'write'])] |
82 | 75 | #[ORM\ManyToOne(targetEntity: MaterialList::class, inversedBy: 'materialItems')] |
83 | 76 | #[ORM\JoinColumn(nullable: true, onDelete: 'cascade')] |
84 | 77 | public ?MaterialList $materialList = null; |
@@ -149,6 +142,36 @@ public function __construct() { |
149 | 142 | $this->periodMaterialItems = new ArrayCollection(); |
150 | 143 | } |
151 | 144 |
|
| 145 | + /** |
| 146 | + * The list to which this item belongs. Lists are used to keep track of who is |
| 147 | + * responsible to prepare and bring the item to the camp. |
| 148 | + */ |
| 149 | + #[Assert\NotNull] |
| 150 | + #[AssertBelongsToSameCamp] |
| 151 | + #[ApiProperty(example: '/material_lists/1a2b3c4d', security: 'is_granted("CAMP_COLLABORATOR", object)')] |
| 152 | + #[Groups(['read', 'write'])] |
| 153 | + public function getMaterialList(): ?MaterialList { |
| 154 | + return $this->materialList; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * The list to which this item belongs. Lists are used to keep track of who is |
| 159 | + * responsible to prepare and bring the item to the camp. |
| 160 | + */ |
| 161 | + #[Assert\NotNull] |
| 162 | + #[AssertBelongsToSameCamp] |
| 163 | + #[ApiProperty(example: '/material_lists/1a2b3c4d', security: '!is_granted("CAMP_COLLABORATOR", object)')] |
| 164 | + #[Groups(['read', 'write'])] |
| 165 | + #[SerializedName('materialList')] |
| 166 | + public function getPublicMaterialList(): ?MaterialList { |
| 167 | + // When accessing a shared or prototype camp, hide personal material lists |
| 168 | + if (null !== $this->materialList->campCollaboration) { |
| 169 | + return null; |
| 170 | + } |
| 171 | + |
| 172 | + return $this->materialList; |
| 173 | + } |
| 174 | + |
152 | 175 | public function getCamp(): ?Camp { |
153 | 176 | return $this->camp ?? $this->period->camp ?? $this->materialNode?->getCamp(); |
154 | 177 | } |
|
0 commit comments