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'string'length65nullabletrue)]
  31.     #[Gedmo\Translatable]
  32.     private ?string $metaTitle null;
  33.     #[ORM\Column(type'string',length165,nullabletrue)]
  34.     #[Gedmo\Translatable]
  35.     private ?string $metaDescription null;
  36.     #[ORM\Column(type'string',nullabletrue)]
  37.     private ?string $metaImage null;
  38.     #[ORM\Column(type'text',nullabletrue)]
  39.     #[Gedmo\Translatable]
  40.     private mixed $description null;
  41.     public function __construct()
  42.     {
  43.         $this->products = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getTitle(): ?string
  50.     {
  51.         return $this->title;
  52.     }
  53.     public function setTitle(?string $title): self
  54.     {
  55.         $this->title $title;
  56.         return $this;
  57.     }
  58.     public function getProducts(): \Doctrine\Common\Collections\Collection
  59.     {
  60.         return $this->products;
  61.     }
  62.     public function addProduct(Product $product): self
  63.     {
  64.         if (!$this->products->contains($product)) {
  65.             $this->products->add($product);
  66.             $product->setCollection($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeProduct(Product $product): self
  71.     {
  72.         if ($this->products->removeElement($product)) {
  73.             // set the owning side to null (unless already changed)
  74.             if ($product->getCollection() === $this) {
  75.                 $product->setCollection(null);
  76.             }
  77.         }
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return mixed|null
  82.      */
  83.     public function getDescription(): mixed
  84.     {
  85.         return $this->description;
  86.     }
  87.     /**
  88.      * @param mixed|null $description
  89.      */
  90.     public function setDescription(mixed $description): void
  91.     {
  92.         $this->description $description;
  93.     }
  94.     /**
  95.      * @return string|null
  96.      */
  97.     public function getMetaTitle(): ?string
  98.     {
  99.         return $this->metaTitle;
  100.     }
  101.     /**
  102.      * @param string|null $metaTitle
  103.      */
  104.     public function setMetaTitle(?string $metaTitle): void
  105.     {
  106.         $this->metaTitle $metaTitle;
  107.     }
  108.     /**
  109.      * @return string|null
  110.      */
  111.     public function getMetaDescription(): ?string
  112.     {
  113.         return $this->metaDescription;
  114.     }
  115.     /**
  116.      * @param string|null $metaDescription
  117.      */
  118.     public function setMetaDescription(?string $metaDescription): void
  119.     {
  120.         $this->metaDescription $metaDescription;
  121.     }
  122.     /**
  123.      * @return string|null
  124.      */
  125.     public function getMetaImage(): ?string
  126.     {
  127.         return $this->metaImage;
  128.     }
  129.     /**
  130.      * @param string|null $metaImage
  131.      */
  132.     public function setMetaImage(?string $metaImage): void
  133.     {
  134.         $this->metaImage $metaImage;
  135.     }
  136. }