src/Entity/Collection.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\MainTranslationTrait;
  4. use App\Entity\Translation\CollectionTranslation;
  5. use App\Entity\Translation\ProductTranslation;
  6. use App\Repository\CollectionRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Translatable\Translatable;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. #[Gedmo\TranslationEntity(class: self::TRANSLATION_ENTITY)]
  12. #[ORM\Entity(repositoryClassCollectionRepository::class)]
  13. class Collection implements Translatable
  14. {
  15.     use MainTranslationTrait;
  16.     const TRANSLATION_ENTITY CollectionTranslation::class;
  17.     public function __toString(): string
  18.     {
  19.         return $this->title ?? '';
  20.     }
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\OneToMany(mappedBy'collection'targetEntityProduct::class)]
  26.     private \Doctrine\Common\Collections\Collection $products;
  27.     #[ORM\Column(type'string',nullabletrue)]
  28.     #[Gedmo\Translatable]
  29.     private ?string $title null;
  30.     #[ORM\Column(type'text',nullabletrue)]
  31.     #[Gedmo\Translatable]
  32.     private mixed $description null;
  33.     public function __construct()
  34.     {
  35.         $this->products = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getTitle(): ?string
  42.     {
  43.         return $this->title;
  44.     }
  45.     public function setTitle(?string $title): self
  46.     {
  47.         $this->title $title;
  48.         return $this;
  49.     }
  50.     public function getProducts(): \Doctrine\Common\Collections\Collection
  51.     {
  52.         return $this->products;
  53.     }
  54.     public function addProduct(Product $product): self
  55.     {
  56.         if (!$this->products->contains($product)) {
  57.             $this->products->add($product);
  58.             $product->setCollection($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeProduct(Product $product): self
  63.     {
  64.         if ($this->products->removeElement($product)) {
  65.             // set the owning side to null (unless already changed)
  66.             if ($product->getCollection() === $this) {
  67.                 $product->setCollection(null);
  68.             }
  69.         }
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return mixed|null
  74.      */
  75.     public function getDescription(): mixed
  76.     {
  77.         return $this->description;
  78.     }
  79.     /**
  80.      * @param mixed|null $description
  81.      */
  82.     public function setDescription(mixed $description): void
  83.     {
  84.         $this->description $description;
  85.     }
  86. }