AbstractRepair.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\MappedSuperclass]
  8. abstract class AbstractRepair
  9. {
  10. #[ORM\Id]
  11. #[ORM\Column]
  12. #[ORM\GeneratedValue]
  13. protected ?int $id = null;
  14. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'repairs', cascade: ['persist'], orphanRemoval: false)]
  15. protected Collection $tags;
  16. public function __construct()
  17. {
  18. $this->tags = new ArrayCollection();
  19. }
  20. public function getId(): ?int
  21. {
  22. return $this->id;
  23. }
  24. function getTags(): Collection
  25. {
  26. return $this->tags;
  27. }
  28. function addTag(Tagg $tag): self
  29. {
  30. if (!$this->tags->contains($tag)) {
  31. $this->tags[] = $tag;
  32. $tag->addRepair($this);
  33. }
  34. return $this;
  35. }
  36. function removeTag(Tagg $tag): self
  37. {
  38. if ($this->tags->removeElement($tag)) {
  39. $tag->removeRepair($this);
  40. }
  41. return $this;
  42. }
  43. }