src/Entity/SubCategory.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=SubCategoryRepository::class)
  9.  */
  10. class SubCategory
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $label;
  22.     /**
  23.      * @ORM\Column(type="string", length=10, nullable=true)
  24.      */
  25.     private $code;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="subCategories")
  28.      * @ORM\JoinColumn(nullable=false)
  29.      */
  30.     private $category;
  31.     /**
  32.      * @ORM\Column(type="datetime")
  33.      */
  34.     private $creation_date;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="subCategory")
  37.      */
  38.     private $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 getLabel(): ?string
  48.     {
  49.         return $this->label;
  50.     }
  51.     public function setLabel(string $label): self
  52.     {
  53.         $this->label $label;
  54.         return $this;
  55.     }
  56.     public function getCode(): ?string
  57.     {
  58.         return $this->code;
  59.     }
  60.     public function setCode(?string $code): self
  61.     {
  62.         $this->code $code;
  63.         return $this;
  64.     }
  65.     public function getCategory(): ?Category
  66.     {
  67.         return $this->category;
  68.     }
  69.     public function setCategory(?Category $category): self
  70.     {
  71.         $this->category $category;
  72.         return $this;
  73.     }
  74.     public function getCreationDate(): ?\DateTimeInterface
  75.     {
  76.         return $this->creation_date;
  77.     }
  78.     public function setCreationDate(\DateTimeInterface $creation_date): self
  79.     {
  80.         $this->creation_date $creation_date;
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return Collection<int, Product>
  85.      */
  86.     public function getProducts(): Collection
  87.     {
  88.         return $this->products;
  89.     }
  90.     public function addProduct(Product $product): self
  91.     {
  92.         if (!$this->products->contains($product)) {
  93.             $this->products[] = $product;
  94.             $product->setSubCategory($this);
  95.         }
  96.         return $this;
  97.     }
  98.     public function removeProduct(Product $product): self
  99.     {
  100.         if ($this->products->removeElement($product)) {
  101.             // set the owning side to null (unless already changed)
  102.             if ($product->getSubCategory() === $this) {
  103.                 $product->setSubCategory(null);
  104.             }
  105.         }
  106.         return $this;
  107.     }
  108. }