<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="category")
*/
private $products;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name_en;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* @ORM\OneToMany(targetEntity=SousCategorie::class, mappedBy="categorie")
*/
private $sousCategories;
/**
* @ORM\ManyToOne(targetEntity=SupCategorie::class, inversedBy="categories")
*/
private $supCategory;
public function __construct()
{
$this->products = new ArrayCollection();
$this->sousCategories = new ArrayCollection();
}
public function __toString(){
return $this->getName();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCategory($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
public function getNameEn(): ?string
{
return $this->name_en;
}
public function setNameEn(?string $name_en): self
{
$this->name_en = $name_en;
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @return Collection<int, SousCategorie>
*/
public function getSousCategories(): Collection
{
return $this->sousCategories;
}
public function addSousCategory(SousCategorie $sousCategory): self
{
if (!$this->sousCategories->contains($sousCategory)) {
$this->sousCategories[] = $sousCategory;
$sousCategory->setCategorie($this);
}
return $this;
}
public function removeSousCategory(SousCategorie $sousCategory): self
{
if ($this->sousCategories->removeElement($sousCategory)) {
// set the owning side to null (unless already changed)
if ($sousCategory->getCategorie() === $this) {
$sousCategory->setCategorie(null);
}
}
return $this;
}
public function getSupCategory(): ?SupCategorie
{
return $this->supCategory;
}
public function setSupCategory(?SupCategorie $supCategory): self
{
$this->supCategory = $supCategory;
return $this;
}
}