<?php
namespace App\Entity;
use App\Entity\Subcategory;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
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
{
public function __construct()
{
$this->subcategories = new ArrayCollection();
$this->companies = new ArrayCollection();
}
#[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:'App\Entity\Company',mappedBy:'categories', cascade:['persist'])]
protected $companies;
/**
* @return mixed
*/
public function getCompanies()
{
return $this->companies;
}
public function addCompany(Company $company)
{
$this->companies->add($company);
}
public function removeCompany(Company $company)
{
$this->companies->removeElement($company);
}
#[Groups(['category', 'company'])]
#[ORM\ManyToMany(targetEntity:'App\Entity\Subcategory',inversedBy:'categories', cascade:['persist'], fetch: 'EAGER')]
protected $subcategories;
#[ORM\OneToOne(targetEntity:AdapterContent::class,mappedBy:'category', cascade:['persist', 'remove'])]
private $adapterContent;
#[ORM\Column( type:'integer', nullable:true)]
#[Groups(['category', 'company'])]
private $unicity;
/**
* @return mixed
*/
public function getSubcategories()
{
return $this->subcategories;
}
public function addSubcategory(Subcategory $subcategory)
{
$this->subcategories->add($subcategory);
}
public function removeSubcategory(Subcategory $subcategory)
{
$this->subcategories->removeElement($subcategory);
}
/**
* @param ArrayCollection $subcategories
*/
public function setSubcategories($subcategories)
{
$this->subcategories = $subcategories;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return text
*/
public function getDescription()
{
return $this->description;
}
/**
* @param text $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @param string $image
* @return mixed
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
public function getAdapterContent(): ?AdapterContent
{
return $this->adapterContent;
}
public function setAdapterContent(?AdapterContent $adapterContent): self
{
// unset the owning side of the relation if necessary
if ($adapterContent === null && $this->adapterContent !== null) {
$this->adapterContent->setCategory(null);
}
// set the owning side of the relation if necessary
if ($adapterContent !== null && $adapterContent->getCategory() !== $this) {
$adapterContent->setCategory($this);
}
$this->adapterContent = $adapterContent;
return $this;
}
public function getUnicity(): ?int
{
return $this->unicity;
}
public function setUnicity(?int $unicity): self
{
$this->unicity = $unicity;
return $this;
}
}