src/Infrastructure/Doctrine/Entity/DoctrineIzOrderColor.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Doctrine\Entity;
  4. use App\Domain\Common\Entity\ColorFamily;
  5. use App\Domain\Common\Entity\IzOrderColor;
  6. use App\Domain\Common\Entity\IzOrderProduct;
  7. use App\Infrastructure\Doctrine\Entity\Traits\IdableTrait;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use function Symfony\Component\String\u;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Infrastructure\Doctrine\Repository\DoctrineIzOrderColorRepository")
  14.  */
  15. class DoctrineIzOrderColor implements IzOrderColor
  16. {
  17.     use IdableTrait;
  18.     /**
  19.      * @ORM\Column(type="string", length=191)
  20.      */
  21.     private string $importCode '';
  22.     /**
  23.      * @ORM\Column(type="string", length=191)
  24.      */
  25.     private string $importLabel '';
  26.     /**
  27.      * @ORM\Column(type="json", nullable=true)
  28.      */
  29.     private array $hexadecimalCodes = [];
  30.     /**
  31.      * @ORM\Column(type="string", length=191, nullable=true)
  32.      */
  33.     private ?string $label null;
  34.     /**
  35.      * @var Collection<int, ColorFamily>
  36.      *
  37.      * @ORM\ManyToMany(targetEntity="App\Infrastructure\Doctrine\Entity\DoctrineColorFamily", mappedBy="colors")
  38.      */
  39.     private iterable $families;
  40.     /**
  41.      * @var Collection<int, IzOrderProduct>
  42.      *
  43.      * @ORM\OneToMany(targetEntity="App\Infrastructure\Doctrine\Entity\DoctrineIzOrderProduct", mappedBy="codeCouleur")
  44.      */
  45.     private iterable $products;
  46.     public function __construct()
  47.     {
  48.         $this->families = new ArrayCollection();
  49.         $this->products = new ArrayCollection();
  50.     }
  51.     public function __toString(): string
  52.     {
  53.         return $this->getLabel();
  54.     }
  55.     public function getImportCode(): string
  56.     {
  57.         return $this->importCode;
  58.     }
  59.     public function setImportCode(string $importCode): void
  60.     {
  61.         $this->importCode $importCode;
  62.         $this->setImportLabel((string) u($importCode)->lower()->title());
  63.     }
  64.     public function getImportLabel(): string
  65.     {
  66.         return $this->importLabel;
  67.     }
  68.     public function setImportLabel(string $importLabel): void
  69.     {
  70.         $this->importLabel $importLabel;
  71.     }
  72.     public function getHexadecimalCodes(): array
  73.     {
  74.         return $this->hexadecimalCodes ?: [];
  75.     }
  76.     public function setHexadecimalCodes(array $hexadecimalCodes): void
  77.     {
  78.         $this->hexadecimalCodes $hexadecimalCodes;
  79.     }
  80.     public function getLabel(): string
  81.     {
  82.         return $this->label ?: $this->getImportLabel();
  83.     }
  84.     public function setLabel(?string $label): void
  85.     {
  86.         $this->label $label;
  87.     }
  88.     /**
  89.      * {@inheritDoc}
  90.      */
  91.     public function getFamilies(): iterable
  92.     {
  93.         return $this->families;
  94.     }
  95.     public function addFamily(ColorFamily $family): self
  96.     {
  97.         if (!$this->families->contains($family)) {
  98.             $this->families[] = $family;
  99.             $family->addColor($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeFamily(ColorFamily $family): self
  104.     {
  105.         if ($this->families->removeElement($family)) {
  106.             $family->removeColor($this);
  107.         }
  108.         return $this;
  109.     }
  110.     /**
  111.      * {@inheritDoc}
  112.      */
  113.     public function getProducts(): iterable
  114.     {
  115.         return $this->products;
  116.     }
  117.     public function addProduct(IzOrderProduct $product): void
  118.     {
  119.         if (!$this->products->contains($product)) {
  120.             $this->products[] = $product;
  121.             $product->setCodeCouleur($this);
  122.         }
  123.     }
  124.     public function removeProduct(IzOrderProduct $product): void
  125.     {
  126.         if ($this->products->removeElement($product) && $product->getCodeCouleur() === $this) {
  127.             $product->setCodeCouleur(null);
  128.         }
  129.     }
  130. }