<?php
declare(strict_types=1);
namespace Croisiland\CommonBundle\Entity\Offer;
use Crea\MediaBundle\Entity\MediaTagOwnerInterface;
use Crea\ToolsBundle\Entity\CreaIconIdentifiedInterface;
use Crea\ToolsBundle\Entity\CreaIconTrait;
use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
use Croisiland\CommonBundle\Annotation\Offer\OfferCategoryFormValidator;
use Croisiland\CommonBundle\Entity\Traits\ColorTrait;
use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
use Croisiland\CommonBundle\Repository\Offer\OfferCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=OfferCategoryRepository::class)
*
* @OfferCategoryFormValidator(groups={"offer_category_form_validator"})
*/
class OfferCategory implements CreaIconIdentifiedInterface, MediaTagOwnerInterface
{
use CreaIconTrait;
use ColorTrait;
use ListOrderTrait;
use IsActiveTrait;
use LifecycleUserIdentifierTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id;
/**
* @ORM\Column(type="string", length=255)
*/
private ?string $name = null;
/**
* @ORM\Column(type="string", length=100, unique=true)
*
* @Gedmo\Slug(fields={"name"}, updatable=false, unique=true)
*/
private ?string $slug = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* @var Collection<int, Offer>
*
* @ORM\OneToMany(targetEntity=Offer::class, mappedBy="offerCategory")
*/
private Collection $offers;
public function __construct()
{
$this->offers = 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 getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Offer>
*/
public function getOffers(): Collection
{
return $this->offers;
}
public function addOffer(Offer $offer): self
{
if (!$this->offers->contains($offer)) {
$this->offers[] = $offer;
$offer->setOfferCategory($this);
}
return $this;
}
public function removeOffer(Offer $offer): self
{
if ($this->offers->removeElement($offer)) {
// set the owning side to null (unless already changed)
if ($offer->getOfferCategory() === $this) {
$offer->setOfferCategory(null);
}
}
return $this;
}
public function getIconLabel(): ?string
{
return $this->getName();
}
/**
* Method liée au Média Bundle
*/
public function getMediaTagOwnerLabel(): ?string
{
return $this->getName();
}
/**
* Method liée au Média Bundle
* @return class-string
*/
public function getFqcn(): string
{
return ClassUtils::getClass($this);
}
}