AbstractControl.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. function getAccompanist(): Access
  29. {
  30. return $this->accompanist;
  31. }
  32. function setAccompanist(Access $accompanist): self
  33. {
  34. $this->accompanist = $accompanist;
  35. return $this;
  36. }
  37. function getTags(): Collection
  38. {
  39. return $this->tags;
  40. }
  41. 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. function removeTag(Tagg $tag): self
  50. {
  51. if ($this->tags->removeElement($tag)) {
  52. $tag->addControl($this);
  53. }
  54. return $this;
  55. }
  56. }