<?php
namespace App\Entity;
use App\Repository\SubCategoriesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SubCategoriesRepository::class)]
class SubCategories
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToOne(targetEntity: Categories::class, inversedBy: 'subCategories')]
private $category;
#[ORM\Column(type: 'string', length: 255)]
private $subCategory;
#[ORM\Column(type: 'datetime')]
private $modified;
#[ORM\Column(type: 'datetime')]
private $created;
#[ORM\OneToMany(targetEntity: Products::class, mappedBy: 'subCategory')]
private $products;
public function __construct()
{
$this->setCreated(new \DateTime());
if ($this->getModified() == null) {
$this->setModified(new \DateTime());
}
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCategory(): ?Categories
{
return $this->category;
}
public function setCategory(?Categories $category): self
{
$this->category = $category;
return $this;
}
public function getSubCategory(): ?string
{
return $this->subCategory;
}
public function setSubCategory(string $subCategory): self
{
$this->subCategory = $subCategory;
return $this;
}
public function getModified(): ?\DateTimeInterface
{
return $this->modified;
}
public function setModified(\DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
/**
* @return Collection|Products[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Products $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setSubCategory($this);
}
return $this;
}
public function removeProduct(Products $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getSubCategory() === $this) {
$product->setSubCategory(null);
}
}
return $this;
}
/**
* @return string
*/
public function __toString(){
return $this->getSubCategory();
}
}