src/Entity/Category.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\MainTranslationTrait;
  4. use App\Entity\Translation\CategoryTranslation;
  5. use App\Entity\Translation\ProductTranslation;
  6. use App\Repository\CategoryRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Translatable\Translatable;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[Gedmo\TranslationEntity(class: self::TRANSLATION_ENTITY)]
  13. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  14. class Category implements Translatable
  15. {
  16.     use MainTranslationTrait;
  17.     const TRANSLATION_ENTITY CategoryTranslation::class;
  18.     #[ORM\Column(type'string'length65nullabletrue)]
  19.     #[Gedmo\Translatable]
  20.     private ?string $metaTitle null;
  21.     #[ORM\Column(type'string',length165,nullabletrue)]
  22.     #[Gedmo\Translatable]
  23.     private ?string $metaDescription null;
  24.     #[ORM\Column(type'string',nullabletrue)]
  25.     private ?string $metaImage null;
  26.     public function __toString(): string
  27.     {
  28.         return $this->title ?? '';
  29.     }
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue]
  32.     #[ORM\Column]
  33.     private ?int $id null;
  34.     #[ORM\Column(type'string',nullabletrue)]
  35.     #[Gedmo\Translatable]
  36.     private ?string $title null;
  37.     #[ORM\OneToMany(mappedBy'category'targetEntityProduct::class)]
  38.     private Collection $products;
  39.     public function __construct()
  40.     {
  41.         $this->products = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getProducts(): Collection
  48.     {
  49.         return $this->products;
  50.     }
  51.     public function addProduct(Product $product): self
  52.     {
  53.         if (!$this->products->contains($product)) {
  54.             $this->products->add($product);
  55.             $product->setCategory($this);
  56.         }
  57.         return $this;
  58.     }
  59.     public function removeProduct(Product $product): self
  60.     {
  61.         if ($this->products->removeElement($product)) {
  62.             if ($product->getCategory() === $this) {
  63.                 $product->setCategory(null);
  64.             }
  65.         }
  66.         return $this;
  67.     }
  68.     public function getTitle(): ?string
  69.     {
  70.         return $this->title;
  71.     }
  72.     public function setTitle(?string $title): self
  73.     {
  74.         $this->title $title;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return string|null
  79.      */
  80.     public function getMetaTitle(): ?string
  81.     {
  82.         return $this->metaTitle;
  83.     }
  84.     /**
  85.      * @param string|null $metaTitle
  86.      */
  87.     public function setMetaTitle(?string $metaTitle): void
  88.     {
  89.         $this->metaTitle $metaTitle;
  90.     }
  91.     /**
  92.      * @return string|null
  93.      */
  94.     public function getMetaDescription(): ?string
  95.     {
  96.         return $this->metaDescription;
  97.     }
  98.     /**
  99.      * @param string|null $metaDescription
  100.      */
  101.     public function setMetaDescription(?string $metaDescription): void
  102.     {
  103.         $this->metaDescription $metaDescription;
  104.     }
  105.     /**
  106.      * @return string|null
  107.      */
  108.     public function getMetaImage(): ?string
  109.     {
  110.         return $this->metaImage;
  111.     }
  112.     /**
  113.      * @param string|null $metaImage
  114.      */
  115.     public function setMetaImage(?string $metaImage): void
  116.     {
  117.         $this->metaImage $metaImage;
  118.     }
  119. }