src/Entity/CRM/ProductCategory.php line 11

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Repository\ProductCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassProductCategoryRepository::class)]
  8. class ProductCategory
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $name null;
  16.     #[ORM\Column(length255nullabletrue)]
  17.     private ?string $description null;
  18.     #[ORM\Column]
  19.     private bool $isActive true;
  20.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'category')]
  21.     private Collection $products;
  22.     public function __construct()
  23.     {
  24.         $this->products = new ArrayCollection();
  25.     }
  26.     public function __toString(): string
  27.     {
  28.         return $this->id.' '.$this->name;
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getDescription(): ?string
  44.     {
  45.         return $this->description;
  46.     }
  47.     public function setDescription(?string $description): self
  48.     {
  49.         $this->description $description;
  50.         return $this;
  51.     }
  52.     public function isIsActive(): ?bool
  53.     {
  54.         return $this->isActive;
  55.     }
  56.     public function setIsActive(bool $isActive): self
  57.     {
  58.         $this->isActive $isActive;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, Product>
  63.      */
  64.     public function getProducts(): Collection
  65.     {
  66.         return $this->products;
  67.     }
  68.     public function addProduct(Product $product): self
  69.     {
  70.         if (!$this->products->contains($product)) {
  71.             $this->products->add($product);
  72.             $product->addCategory($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeProduct(Product $product): self
  77.     {
  78.         if ($this->products->removeElement($product)) {
  79.             $product->removeCategory($this);
  80.         }
  81.         return $this;
  82.     }
  83. }