RoomControl.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Place;
  4. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use App\Entity\Core\AbstractControl;
  7. use App\Entity\Core\Tagg;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11. * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table RoomControl, et supprimer l'attribut discr.
  12. *
  13. * Classe ... qui ...
  14. */
  15. // #[Auditable]
  16. #[ApiResource(operations: [])]
  17. #[ORM\Entity]
  18. class RoomControl extends AbstractControl
  19. {
  20. #[ORM\ManyToOne(inversedBy: 'controls')]
  21. private ?Room $room = null;
  22. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'controls', cascade: ['persist'], orphanRemoval: false)]
  23. #[ORM\JoinTable(name: 'tag_control')]
  24. #[ORM\JoinColumn(name: 'control_id')]
  25. #[ORM\InverseJoinColumn(name: 'tag_id')]
  26. protected Collection $tags;
  27. public function getRoom(): ?Room
  28. {
  29. return $this->room;
  30. }
  31. public function setRoom(?Room $room): self
  32. {
  33. $this->room = $room;
  34. return $this;
  35. }
  36. public function getTags(): Collection
  37. {
  38. return $this->tags;
  39. }
  40. public function addTag(Tagg $tag): self
  41. {
  42. if (!$this->tags->contains($tag)) {
  43. $this->tags[] = $tag;
  44. $tag->addControl($this);
  45. }
  46. return $this;
  47. }
  48. public function removeTag(Tagg $tag): self
  49. {
  50. if ($this->tags->removeElement($tag)) {
  51. $tag->removeControl($this);
  52. }
  53. return $this;
  54. }
  55. }