AbstractProduct.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Product;
  4. use App\Entity\Core\Tagg;
  5. use App\Entity\Organization\Organization;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * Classe ... qui ...
  11. */
  12. #[ORM\MappedSuperclass]
  13. #[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
  14. #[ORM\DiscriminatorMap(
  15. [
  16. 'equipment' => Equipment::class,
  17. 'intangible' => Intangible::class,
  18. ]
  19. )]
  20. abstract class AbstractProduct
  21. {
  22. #[ORM\Id]
  23. #[ORM\Column]
  24. #[ORM\GeneratedValue]
  25. protected ?int $id = null;
  26. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'products', cascade: ['persist'], orphanRemoval: false)]
  27. protected Collection $tags;
  28. public function __construct()
  29. {
  30. $this->tags = new ArrayCollection();
  31. }
  32. public function getId(): ?int
  33. {
  34. return $this->id;
  35. }
  36. public function getTags(): Collection
  37. {
  38. return $this->tags;
  39. }
  40. public function addTag(Tagg $tag): self
  41. {
  42. if (!$this->tags->contains($tag)) {
  43. $this->tags[] = $tag;
  44. $tag->addProduct($this);
  45. }
  46. return $this;
  47. }
  48. public function removeTag(Tagg $tag): self
  49. {
  50. if ($this->tags->removeElement($tag)) {
  51. $tag->removeProduct($this);
  52. }
  53. return $this;
  54. }
  55. }