src/Entity/Website/Product/ProductCategory.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Website\Product;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\SeoFieldsTrait;
  5. use App\Entity\Website\Website\Website;
  6. use App\Repository\Website\Product\ProductCategoryRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  12. #[ORM\Entity(repositoryClassProductCategoryRepository::class)]
  13. class ProductCategory extends BaseEntity
  14. {
  15.     use SeoFieldsTrait;
  16.     #[ORM\Id]
  17.     #[ORM\Column(type'guid'uniquetrue)]
  18.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  19.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  20.     private ?string $id;
  21.     #[ORM\Column(length255)]
  22.     private ?string $name null;
  23.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  24.     private ?string $description null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $imageUrl null;
  27.     #[ORM\ManyToOne(inversedBy'productCategories')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private ?Website $website null;
  30.     #[ORM\ManyToMany(targetEntityProduct::class, inversedBy'productCategories')]
  31.     private Collection $products;
  32.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'productCategories')]
  33.     private ?self $parent null;
  34.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  35.     private Collection $productCategories;
  36.     public function __construct()
  37.     {
  38.         parent::__construct();
  39.         $this->products = new ArrayCollection();
  40.         $this->productCategories = new ArrayCollection();
  41.     }
  42.     public function __toString()
  43.     {
  44.         return (string) $this->getName();
  45.     }
  46.     public function getId(): ?string
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getName(): ?string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function setName(string $name): static
  55.     {
  56.         $this->name $name;
  57.         return $this;
  58.     }
  59.     public function getDescription(): ?string
  60.     {
  61.         return $this->description;
  62.     }
  63.     public function setDescription(?string $description): static
  64.     {
  65.         $this->description $description;
  66.         return $this;
  67.     }
  68.     public function getImageUrl(): ?string
  69.     {
  70.         return $this->imageUrl;
  71.     }
  72.     public function setImageUrl(?string $imageUrl): static
  73.     {
  74.         $this->imageUrl $imageUrl;
  75.         return $this;
  76.     }
  77.     public function getWebsite(): ?Website
  78.     {
  79.         return $this->website;
  80.     }
  81.     public function setWebsite(?Website $shop): static
  82.     {
  83.         $this->website $shop;
  84.         return $this;
  85.     }
  86.     public function getParent(): ?self
  87.     {
  88.         return $this->parent;
  89.     }
  90.     public function setParent(?self $parent): static
  91.     {
  92.         $this->parent $parent;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, self>
  97.      */
  98.     public function getProductCategories(): Collection
  99.     {
  100.         return $this->productCategories;
  101.     }
  102.     public function addProductCategory(self $productCategory): static
  103.     {
  104.         if (!$this->productCategories->contains($productCategory)) {
  105.             $this->productCategories->add($productCategory);
  106.             $productCategory->setParent($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeProductCategory(self $productCategory): static
  111.     {
  112.         if ($this->productCategories->removeElement($productCategory)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($productCategory->getParent() === $this) {
  115.                 $productCategory->setParent(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, Product>
  122.      */
  123.     public function getProducts(): Collection
  124.     {
  125.         return $this->products;
  126.     }
  127.     public function addProduct(Product $product): static
  128.     {
  129.         if (!$this->products->contains($product)) {
  130.             $this->products->add($product);
  131.         }
  132.         return $this;
  133.     }
  134.     public function removeProduct(Product $product): static
  135.     {
  136.         $this->products->removeElement($product);
  137.         return $this;
  138.     }
  139. }