RoomControl.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #[ORM\Table(name: 'Control')]
  19. class RoomControl extends AbstractControl
  20. {
  21. #[ORM\ManyToOne(inversedBy: 'controls')]
  22. private ?Room $room = null;
  23. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'controls', cascade: ['persist'], orphanRemoval: false)]
  24. #[ORM\JoinTable(name: 'tag_control')]
  25. #[ORM\JoinColumn(name: 'control_id')]
  26. #[ORM\InverseJoinColumn(name: 'tag_id')]
  27. protected Collection $tags;
  28. public function getRoom(): ?Room
  29. {
  30. return $this->room;
  31. }
  32. public function setRoom(?Room $room): self
  33. {
  34. $this->room = $room;
  35. return $this;
  36. }
  37. public function getTags(): Collection
  38. {
  39. return $this->tags;
  40. }
  41. public function addTag(Tagg $tag): self
  42. {
  43. if (!$this->tags->contains($tag)) {
  44. $this->tags[] = $tag;
  45. $tag->addControl($this);
  46. }
  47. return $this;
  48. }
  49. public function removeTag(Tagg $tag): self
  50. {
  51. if ($this->tags->removeElement($tag)) {
  52. $tag->removeControl($this);
  53. }
  54. return $this;
  55. }
  56. }