PlaceControl.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Place;
  4. use App\Entity\Core\AbstractControl;
  5. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  6. use App\Entity\Core\Tagg;
  7. use Doctrine\Common\Collections\ArrayCollection;
  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 PlaceControl, et supprimer l'attribut discr.
  12. * @todo : migration table tag_control
  13. * Classe ... qui ...
  14. */
  15. // #[Auditable]
  16. #[ORM\Entity]
  17. #[ORM\Table(name: 'Control')]
  18. class PlaceControl extends AbstractControl
  19. {
  20. #[ORM\Column(length: 12, nullable: false)]
  21. protected string $discr = 'place';
  22. #[ORM\ManyToOne(inversedBy: 'controls')]
  23. protected AbstractPlace $place;
  24. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'placeControls', cascade: ['persist'])]
  25. #[ORM\JoinTable(name: 'tag_control')]
  26. #[ORM\JoinColumn(name: 'control_id', referencedColumnName: 'id')]
  27. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  28. protected Collection $tags;
  29. public function __construct()
  30. {
  31. $this->tags = new ArrayCollection();
  32. parent::__construct();
  33. }
  34. public function getDiscr(): ?string
  35. {
  36. return $this->discr;
  37. }
  38. public function setDiscr(string $discr): self
  39. {
  40. $this->discr = $discr;
  41. return $this;
  42. }
  43. public function getPlace(): ?AbstractPlace
  44. {
  45. return $this->place;
  46. }
  47. public function setPlace(?AbstractPlace $place): self
  48. {
  49. $this->place = $place;
  50. return $this;
  51. }
  52. /**
  53. * @return Collection<int, Tagg>
  54. */
  55. public function getTags(): Collection
  56. {
  57. return $this->tags;
  58. }
  59. public function addTag(Tagg $tag): self
  60. {
  61. if (!$this->tags->contains($tag)) {
  62. $this->tags[] = $tag;
  63. }
  64. return $this;
  65. }
  66. public function removeTag(Tagg $tag): self
  67. {
  68. $this->tags->removeElement($tag);
  69. return $this;
  70. }
  71. }