<?php
namespace App\Entity\PointsCatalog;
use App\Annotation\SiteAware;
use App\Entity\AbstractBase;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\MiniAbstractBase;
use App\Entity\Traits\NameTrait;
use App\Entity\Traits\PublishedTrait;
use App\Entity\Traits\SiteTrait;
use App\Repository\PointsCatalog\CatalogSizeGroupRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="vulco_points_catalog_size_group", indexes={@ORM\Index(name="catalog_size_group_site_idx", columns={"site"})})
* @ORM\Entity(repositoryClass=CatalogSizeGroupRepository::class)
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
* @SiteAware(siteFieldName="site")
*/
class CatalogSizeGroup extends AbstractBase implements SiteInterface
{
use NameTrait;
use PublishedTrait;
use SiteTrait;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PointsCatalog\CatalogSize", mappedBy="group", cascade={"persist"}, orphanRemoval=true)
* @Assert\Valid()
*/
private ?Collection $sizes;
public function __construct()
{
$this->sizes = new ArrayCollection();
}
public function getSizes(): ?Collection
{
return $this->sizes;
}
public function setSizes(?Collection $sizes): self
{
$this->sizes = $sizes;
return $this;
}
public function addSize(CatalogSize $size): self
{
if (!$this->sizes->contains($size)) {
$size->setGroup($this);
$this->sizes->add($size);
}
return $this;
}
public function removeSize(CatalogSize $size): self
{
$this->sizes->removeElement($size);
return $this;
}
public function __toString(): string
{
return $this->name ? $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}