AbstractControl.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use App\Entity\Access\Access;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\MappedSuperclass]
  9. abstract class AbstractControl
  10. {
  11. #[ORM\Id]
  12. #[ORM\Column]
  13. #[ORM\GeneratedValue]
  14. protected ?int $id = null;
  15. #[ORM\ManyToOne(inversedBy: 'accompanistControl')]
  16. #[ORM\JoinColumn(nullable: true)]
  17. protected Access $accompanist;
  18. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'controls', cascade: ['persist'], orphanRemoval: false)]
  19. protected Collection $tags;
  20. public function __construct()
  21. {
  22. $this->tags = new ArrayCollection();
  23. }
  24. public function getId(): ?int
  25. {
  26. return $this->id;
  27. }
  28. public function getAccompanist(): Access
  29. {
  30. return $this->accompanist;
  31. }
  32. public function setAccompanist(Access $accompanist): self
  33. {
  34. $this->accompanist = $accompanist;
  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->addControl($this);
  53. }
  54. return $this;
  55. }
  56. }