<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
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)
*
* @Assert\NotBlank(message="Veuillez donner un nom à la catégorie")
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $image;
/**
* @ORM\Column(type="string", length=255)
* @Groups("publication:read","post:read")
*/
private $slug;
/**
* @ORM\ManyToMany(targetEntity=SubCategory::class, mappedBy="categories")
*/
private $subCategories;
/**
* @ORM\ManyToMany(targetEntity=Company::class, mappedBy="category")
*/
private $companies;
/**
* @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="categorys")
*/
private $annonces;
public function __construct()
{
$this->articles = new ArrayCollection();
$this->subCategories = new ArrayCollection();
$this->companies = new ArrayCollection();
$this->annonces = new ArrayCollection();
}
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;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection|SubCategory[]
*/
public function getSubCategories(): Collection
{
return $this->subCategories;
}
public function addSubCategory(SubCategory $subCategory): self
{
if (!$this->subCategories->contains($subCategory)) {
$this->subCategories[] = $subCategory;
$subCategory->setCategory($this);
}
return $this;
}
public function removeSubCategory(SubCategory $subCategory): self
{
if ($this->subCategories->contains($subCategory)) {
$this->subCategories->removeElement($subCategory);
// set the owning side to null (unless already changed)
if ($subCategory->getCategory() === $this) {
$subCategory->setCategory(null);
}
}
return $this;
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
$company->addCategory($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->contains($company)) {
$this->companies->removeElement($company);
$company->removeCategory($this);
}
return $this;
}
/**
* @return Collection|Annonce[]
*/
public function getAnnonces(): Collection
{
return $this->annonces;
}
public function addAnnonce(Annonce $annonce): self
{
if (!$this->annonces->contains($annonce)) {
$this->annonces[] = $annonce;
$annonce->setCategorys($this);
}
return $this;
}
public function removeAnnonce(Annonce $annonce): self
{
if ($this->annonces->removeElement($annonce)) {
// set the owning side to null (unless already changed)
if ($annonce->getCategorys() === $this) {
$annonce->setCategorys(null);
}
}
return $this;
}
}