src/Entity/Component.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ComponentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Uid\Uuid;
  11. #[ORM\Entity(repositoryClassComponentRepository::class)]
  12. // #[UniqueEntity(['whitelabel', 'name'], message: 'Record with this name already exists.')]
  13. class Component
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\Column(type'uuid'uniquetrue)]
  17.     #[Groups(['BASE'])]
  18.     private ?string $id null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $nameEn null;
  23.     #[ORM\ManyToOne(inversedBy'components')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?Whitelabel $whitelabel null;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  27.     private ?\DateTimeInterface $createDate null;
  28.     #[ORM\ManyToOne(inversedBy'components')]
  29.     #[ORM\JoinColumn(nullablefalse)]
  30.     private ?User $creatorUser null;
  31.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'components')]
  32.     private Collection $products;
  33.     public function __construct()
  34.     {
  35.         $this->id Uuid::v4();
  36.         $this->products = new ArrayCollection();
  37.     }
  38.     public function __toString()
  39.     {
  40.         return $this->getName();
  41.     }
  42.     public function getId(): ?string
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): ?string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function getNameEn(): ?string
  56.     {
  57.         return $this->nameEn;
  58.     }
  59.     public function setNameEn(?string $nameEn): self
  60.     {
  61.         $this->nameEn $nameEn;
  62.         return $this;
  63.     }
  64.     public function getWhitelabel(): ?Whitelabel
  65.     {
  66.         return $this->whitelabel;
  67.     }
  68.     public function setWhitelabel(?Whitelabel $whitelabel): self
  69.     {
  70.         $this->whitelabel $whitelabel;
  71.         return $this;
  72.     }
  73.     public function getCreateDate(): ?\DateTimeInterface
  74.     {
  75.         return $this->createDate;
  76.     }
  77.     public function setCreateDate(\DateTimeInterface $createDate): self
  78.     {
  79.         $this->createDate $createDate;
  80.         return $this;
  81.     }
  82.     public function getCreatorUser(): ?User
  83.     {
  84.         return $this->creatorUser;
  85.     }
  86.     public function setCreatorUser(?User $creatorUser): self
  87.     {
  88.         $this->creatorUser $creatorUser;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return Collection<int, Product>
  93.      */
  94.     public function getProducts(): Collection
  95.     {
  96.         return $this->products;
  97.     }
  98.     public function addProduct(Product $product): self
  99.     {
  100.         if (!$this->products->contains($product)) {
  101.             $this->products->add($product);
  102.             $product->addComponent($this);
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeProduct(Product $product): self
  107.     {
  108.         if ($this->products->removeElement($product)) {
  109.             $product->removeComponent($this);
  110.         }
  111.         return $this;
  112.     }
  113. }