src/Entity/Allergen.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AllergenRepository;
  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(repositoryClassAllergenRepository::class)]
  12. #[UniqueEntity(['whitelabel''name'], message'Record with this name already exists.')]
  13. class Allergen
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\Column(type'uuid'uniquetrue)]
  17.     #[Groups(['BASE'])]
  18.     private ?string $id null;
  19.     #[ORM\ManyToOne(inversedBy'allergens')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?Whitelabel $whitelabel null;
  22.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  23.     private ?\DateTimeInterface $createDate null;
  24.     #[ORM\ManyToOne(inversedBy'allergens')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?User $creatorUser null;
  27.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'allergens')]
  28.     private Collection $products;
  29.     #[ORM\Column(length255)]
  30.     private ?string $name null;
  31.     public function __construct()
  32.     {
  33.         $this->id Uuid::v4();
  34.         $this->products = new ArrayCollection();
  35.     }
  36.     public function getId(): ?string
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function __toString()
  41.     {
  42.         return $this->getName();
  43.     }
  44.     public function getWhitelabel(): ?Whitelabel
  45.     {
  46.         return $this->whitelabel;
  47.     }
  48.     public function setWhitelabel(?Whitelabel $whitelabel): self
  49.     {
  50.         $this->whitelabel $whitelabel;
  51.         return $this;
  52.     }
  53.     public function getCreateDate(): ?\DateTimeInterface
  54.     {
  55.         return $this->createDate;
  56.     }
  57.     public function setCreateDate(\DateTimeInterface $createDate): self
  58.     {
  59.         $this->createDate $createDate;
  60.         return $this;
  61.     }
  62.     public function getCreatorUser(): ?User
  63.     {
  64.         return $this->creatorUser;
  65.     }
  66.     public function setCreatorUser(?User $creatorUser): self
  67.     {
  68.         $this->creatorUser $creatorUser;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, Product>
  73.      */
  74.     public function getProducts(): Collection
  75.     {
  76.         return $this->products;
  77.     }
  78.     public function addProduct(Product $product): self
  79.     {
  80.         if (!$this->products->contains($product)) {
  81.             $this->products->add($product);
  82.             $product->addAllergen($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeProduct(Product $product): self
  87.     {
  88.         if ($this->products->removeElement($product)) {
  89.             $product->removeAllergen($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function getName(): ?string
  94.     {
  95.         return $this->name;
  96.     }
  97.     public function setName(string $name): self
  98.     {
  99.         $this->name $name;
  100.         return $this;
  101.     }
  102. }