| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Product;
- use App\Entity\Core\Tagg;
- use App\Entity\Organization\Organization;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * Classe ... qui ...
- */
- #[ORM\MappedSuperclass]
- #[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
- #[ORM\DiscriminatorMap(
- [
- 'equipment' => Equipment::class,
- 'intangible' => Intangible::class,
- ]
- )]
- abstract class AbstractProduct
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- protected ?int $id = null;
- #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'products', cascade: ['persist'], orphanRemoval: false)]
- protected Collection $tags;
- public function __construct()
- {
- $this->tags = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getTags(): Collection
- {
- return $this->tags;
- }
- public function addTag(Tagg $tag): self
- {
- if (!$this->tags->contains($tag)) {
- $this->tags[] = $tag;
- $tag->addProduct($this);
- }
- return $this;
- }
- public function removeTag(Tagg $tag): self
- {
- if ($this->tags->removeElement($tag)) {
- $tag->removeProduct($this);
- }
- return $this;
- }
- }
|