src/Entity/SubCategories.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubCategoriesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassSubCategoriesRepository::class)]
  8. class SubCategories
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\ManyToOne(targetEntityCategories::class, inversedBy'subCategories')]
  15.     private $category;
  16.     #[ORM\Column(type'string'length255)]
  17.     private $subCategory;
  18.     #[ORM\Column(type'datetime')]
  19.     private $modified;
  20.     #[ORM\Column(type'datetime')]
  21.     private $created;
  22.     #[ORM\OneToMany(targetEntityProducts::class, mappedBy'subCategory')]
  23.     private $products;
  24.     public function __construct()
  25.     {
  26.         $this->setCreated(new \DateTime());
  27.         if ($this->getModified() == null) {
  28.             $this->setModified(new \DateTime());
  29.         }
  30.         $this->products = new ArrayCollection();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getCategory(): ?Categories
  37.     {
  38.         return $this->category;
  39.     }
  40.     public function setCategory(?Categories $category): self
  41.     {
  42.         $this->category $category;
  43.         return $this;
  44.     }
  45.     public function getSubCategory(): ?string
  46.     {
  47.         return $this->subCategory;
  48.     }
  49.     public function setSubCategory(string $subCategory): self
  50.     {
  51.         $this->subCategory $subCategory;
  52.         return $this;
  53.     }
  54.     public function getModified(): ?\DateTimeInterface
  55.     {
  56.         return $this->modified;
  57.     }
  58.     public function setModified(\DateTimeInterface $modified): self
  59.     {
  60.         $this->modified $modified;
  61.         return $this;
  62.     }
  63.     public function getCreated(): ?\DateTimeInterface
  64.     {
  65.         return $this->created;
  66.     }
  67.     public function setCreated(\DateTimeInterface $created): self
  68.     {
  69.         $this->created $created;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection|Products[]
  74.      */
  75.     public function getProducts(): Collection
  76.     {
  77.         return $this->products;
  78.     }
  79.     public function addProduct(Products $product): self
  80.     {
  81.         if (!$this->products->contains($product)) {
  82.             $this->products[] = $product;
  83.             $product->setSubCategory($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeProduct(Products $product): self
  88.     {
  89.         if ($this->products->removeElement($product)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($product->getSubCategory() === $this) {
  92.                 $product->setSubCategory(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return string
  99.      */
  100.     public function __toString(){
  101.         return $this->getSubCategory();
  102.     }
  103. }