src/Entity/ProductCategory.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Uid\Uuid;
  11. #[ORM\Entity(repositoryClassProductCategoryRepository::class)]
  12. // #[UniqueEntity(['whitelabel', 'name'], message: 'Record with this name already exists.')]
  13. class ProductCategory
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\Column(type'uuid'uniquetrue)]
  17.     #[Groups(['BASE'])]
  18.     private ?string $id null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  22.     private ?\DateTimeInterface $createDate null;
  23.     #[ORM\ManyToOne(inversedBy'productCategories')]
  24.     private ?User $creatorUser null;
  25.     #[ORM\OneToMany(mappedBy'category'targetEntityProduct::class)]
  26.     private Collection $products;
  27.     #[ORM\ManyToOne(inversedBy'productCategories')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private ?Whitelabel $whitelabel null;
  30.     #[ORM\Column(options: ['default' => 1])]
  31.     private ?int $position null;
  32.     public function __construct()
  33.     {
  34.         $this->id Uuid::v4();
  35.         $this->products = new ArrayCollection();
  36.     }
  37.     public function __toString()
  38.     {
  39.         return $this->getName();
  40.     }
  41.     public function getId(): ?string
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getName(): ?string
  46.     {
  47.         return $this->name;
  48.     }
  49.     public function setName(string $name): self
  50.     {
  51.         $this->name $name;
  52.         return $this;
  53.     }
  54.     public function getCreateDate(): ?\DateTimeInterface
  55.     {
  56.         return $this->createDate;
  57.     }
  58.     public function setCreateDate(\DateTimeInterface $createDate): self
  59.     {
  60.         $this->createDate $createDate;
  61.         return $this;
  62.     }
  63.     public function getCreatorUser(): ?User
  64.     {
  65.         return $this->creatorUser;
  66.     }
  67.     public function setCreatorUser(?User $creatorUser): self
  68.     {
  69.         $this->creatorUser $creatorUser;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection<int, Product>
  74.      */
  75.     public function getProducts(): Collection
  76.     {
  77.         return $this->products;
  78.     }
  79.     public function addProduct(Product $product): self
  80.     {
  81.         if (!$this->products->contains($product)) {
  82.             $this->products->add($product);
  83.             $product->setCategory($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeProduct(Product $product): self
  88.     {
  89.         if ($this->products->removeElement($product)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($product->getCategory() === $this) {
  92.                 $product->setCategory(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     public function getWhitelabel(): ?Whitelabel
  98.     {
  99.         return $this->whitelabel;
  100.     }
  101.     public function setWhitelabel(?Whitelabel $whitelabel): self
  102.     {
  103.         $this->whitelabel $whitelabel;
  104.         return $this;
  105.     }
  106.     public function getPosition(): ?int
  107.     {
  108.         return $this->position;
  109.     }
  110.     public function setPosition(int $position): self
  111.     {
  112.         $this->position $position;
  113.         return $this;
  114.     }
  115. }