<?php
namespace App\Entity;
use App\Entity\Subcategory;
use App\Entity\Company;
use App\Model\TranslationModel;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\OrderBy;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping\UniqueConstraint as UniqueConstraint;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Table(name: "category")]
#[ORM\Entity(repositoryClass: "App\Repository\CategoryRepository")]
class Category extends TranslationModel
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer', unique: true)]
#[Groups(['category', 'company'])]
private $id;
#[ORM\Column(name: 'name', type: 'string', length: 255)]
#[Groups(['category', 'company'])]
protected $name;
#[ORM\Column(name: 'description', type: 'text', nullable: true)]
#[Groups(['category', 'company'])]
protected $description;
#[ORM\Column(name: 'image', type: 'string')]
#[Groups(['category', 'company'])]
protected $image;
#[ORM\Column(name: 'slug', type: 'string', length: 255, nullable: true)]
#[Groups(['category', 'company'])]
protected $slug;
#[ORM\ManyToMany(targetEntity: Company::class, mappedBy: 'categories', cascade: ['persist'])]
protected Collection $companies;
#[Groups(['category', 'company'])]
#[ORM\ManyToMany(targetEntity: Subcategory::class, inversedBy: 'categories', cascade: ['persist'])]
protected Collection $subcategories;
public function __construct()
{
$this->subcategories = new ArrayCollection();
$this->companies = new ArrayCollection();
}
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
}
return $this;
}
public function removeCompany(Company $company): self
{
$this->companies->removeElement($company);
return $this;
}
public function getSubcategories(): Collection
{
return $this->subcategories;
}
public function addSubcategory(Subcategory $subcategory): self
{
if (!$this->subcategories->contains($subcategory)) {
$this->subcategories->add($subcategory);
}
return $this;
}
public function removeSubcategory(Subcategory $subcategory): self
{
$this->subcategories->removeElement($subcategory);
return $this;
}
public function setSubcategories(Collection $subcategories): self
{
$this->subcategories = $subcategories;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
}