src/Entity/User.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Uid\Uuid;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`user`')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\Column(type'uuid'uniquetrue)]
  18.     #[Groups(['BASE'])]
  19.     private ?string $id null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $name null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $email null;
  24.     #[ORM\Column(length255)]
  25.     private ?string $password null;
  26.     #[ORM\OneToMany(mappedBy'creatorUser'targetEntityComponent::class, orphanRemovaltrue)]
  27.     private Collection $components;
  28.     #[ORM\OneToMany(mappedBy'creatorUser'targetEntityProduct::class, orphanRemovaltrue)]
  29.     private Collection $products;
  30.     #[ORM\OneToMany(mappedBy'creatorUser'targetEntityMenu::class, orphanRemovaltrue)]
  31.     private Collection $menus;
  32.     /**
  33.      * @var string[]
  34.      */
  35.     #[ORM\Column(type'json')]
  36.     private $roles = [];
  37.     #[ORM\ManyToOne(inversedBy'users')]
  38.     #[ORM\JoinColumn(nullablefalse)]
  39.     private ?Whitelabel $whitelabel null;
  40.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  41.     private ?\DateTimeInterface $createDate null;
  42.     #[ORM\OneToMany(mappedBy'creatorUser'targetEntityProductCategory::class)]
  43.     private Collection $productCategories;
  44.     #[ORM\OneToMany(mappedBy'creatorUser'targetEntityAllergen::class)]
  45.     private Collection $allergens;
  46.     #[ORM\ManyToMany(targetEntityProperty::class, inversedBy'users')]
  47.     private Collection $properties;
  48.     public function __construct()
  49.     {
  50.         $this->id Uuid::v4();
  51.         $this->components = new ArrayCollection();
  52.         $this->products = new ArrayCollection();
  53.         $this->menus = new ArrayCollection();
  54.         $this->productCategories = new ArrayCollection();
  55.         $this->allergens = new ArrayCollection();
  56.         $this->properties = new ArrayCollection();
  57.     }
  58.     public function __toString()
  59.     {
  60.         return $this->getName();
  61.     }
  62.     public function getId(): ?string
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getName(): ?string
  67.     {
  68.         return $this->name;
  69.     }
  70.     public function setName(?string $name): self
  71.     {
  72.         $this->name $name;
  73.         return $this;
  74.     }
  75.     public function getEmail(): ?string
  76.     {
  77.         return $this->email;
  78.     }
  79.     public function setEmail(string $email): self
  80.     {
  81.         $this->email $email;
  82.         return $this;
  83.     }
  84.     public function getPassword(): ?string
  85.     {
  86.         return $this->password;
  87.     }
  88.     public function setPassword(string $password): self
  89.     {
  90.         $this->password $password;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection<int, Component>
  95.      */
  96.     public function getComponents(): Collection
  97.     {
  98.         return $this->components;
  99.     }
  100.     public function addComponent(Component $component): self
  101.     {
  102.         if (!$this->components->contains($component)) {
  103.             $this->components->add($component);
  104.             $component->setCreatorUser($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeComponent(Component $component): self
  109.     {
  110.         if ($this->components->removeElement($component)) {
  111.             // set the owning side to null (unless already changed)
  112.             if ($component->getCreatorUser() === $this) {
  113.                 $component->setCreatorUser(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, Product>
  120.      */
  121.     public function getProducts(): Collection
  122.     {
  123.         return $this->products;
  124.     }
  125.     public function addProduct(Product $product): self
  126.     {
  127.         if (!$this->products->contains($product)) {
  128.             $this->products->add($product);
  129.             $product->setCreatorUser($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeProduct(Product $product): self
  134.     {
  135.         if ($this->products->removeElement($product)) {
  136.             // set the owning side to null (unless already changed)
  137.             if ($product->getCreatorUser() === $this) {
  138.                 $product->setCreatorUser(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, Menu>
  145.      */
  146.     public function getMenus(): Collection
  147.     {
  148.         return $this->menus;
  149.     }
  150.     public function addMenu(Menu $menu): self
  151.     {
  152.         if (!$this->menus->contains($menu)) {
  153.             $this->menus->add($menu);
  154.             $menu->setCreatorUser($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeMenu(Menu $menu): self
  159.     {
  160.         if ($this->menus->removeElement($menu)) {
  161.             // set the owning side to null (unless already changed)
  162.             if ($menu->getCreatorUser() === $this) {
  163.                 $menu->setCreatorUser(null);
  164.             }
  165.         }
  166.         return $this;
  167.     }
  168.     /**
  169.      * A visual identifier that represents this user.
  170.      *
  171.      * @see UserInterface
  172.      */
  173.     public function getUserIdentifier(): string
  174.     {
  175.         return (string) $this->email;
  176.     }
  177.     /**
  178.      * @see UserInterface
  179.      */
  180.     public function getRoles(): array
  181.     {
  182.         $roles $this->roles;
  183.         // guarantee every user at least has ROLE_USER
  184.         $roles[] = 'ROLE_USER';
  185.         return array_unique($roles);
  186.     }
  187.     public function setRoles(array $roles): self
  188.     {
  189.         $this->roles $roles;
  190.         return $this;
  191.     }
  192.     /**
  193.      * @see UserInterface
  194.      */
  195.     public function eraseCredentials()
  196.     {
  197.         // If you store any temporary, sensitive data on the user, clear it here
  198.         // $this->plainPassword = null;
  199.     }
  200.     /**
  201.      * @see UserInterface
  202.      */
  203.     public function getUsername()
  204.     {
  205.         // If you store any temporary, sensitive data on the user, clear it here
  206.         // $this->plainPassword = null;
  207.         return '';
  208.     }
  209.     public function getWhitelabel(): ?Whitelabel
  210.     {
  211.         return $this->whitelabel;
  212.     }
  213.     public function setWhitelabel(?Whitelabel $whitelabel): self
  214.     {
  215.         $this->whitelabel $whitelabel;
  216.         return $this;
  217.     }
  218.     public function getCreateDate(): ?\DateTimeInterface
  219.     {
  220.         return $this->createDate;
  221.     }
  222.     public function setCreateDate(\DateTimeInterface $createDate): self
  223.     {
  224.         $this->createDate $createDate;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return Collection<int, ProductCategory>
  229.      */
  230.     public function getProductCategories(): Collection
  231.     {
  232.         return $this->productCategories;
  233.     }
  234.     public function addProductCategory(ProductCategory $productCategory): self
  235.     {
  236.         if (!$this->productCategories->contains($productCategory)) {
  237.             $this->productCategories->add($productCategory);
  238.             $productCategory->setCreatorUser($this);
  239.         }
  240.         return $this;
  241.     }
  242.     public function removeProductCategory(ProductCategory $productCategory): self
  243.     {
  244.         if ($this->productCategories->removeElement($productCategory)) {
  245.             // set the owning side to null (unless already changed)
  246.             if ($productCategory->getCreatorUser() === $this) {
  247.                 $productCategory->setCreatorUser(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252.     /**
  253.      * @return Collection<int, Allergen>
  254.      */
  255.     public function getAllergens(): Collection
  256.     {
  257.         return $this->allergens;
  258.     }
  259.     public function addAllergen(Allergen $allergen): self
  260.     {
  261.         if (!$this->allergens->contains($allergen)) {
  262.             $this->allergens->add($allergen);
  263.             $allergen->setCreatorUser($this);
  264.         }
  265.         return $this;
  266.     }
  267.     public function removeAllergen(Allergen $allergen): self
  268.     {
  269.         if ($this->allergens->removeElement($allergen)) {
  270.             // set the owning side to null (unless already changed)
  271.             if ($allergen->getCreatorUser() === $this) {
  272.                 $allergen->setCreatorUser(null);
  273.             }
  274.         }
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return Collection<int, Property>
  279.      */
  280.     public function getProperties(): Collection
  281.     {
  282.         return $this->properties;
  283.     }
  284.     public function addProperty(Property $property): static
  285.     {
  286.         if (!$this->properties->contains($property)) {
  287.             $this->properties->add($property);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeProperty(Property $property): static
  292.     {
  293.         $this->properties->removeElement($property);
  294.         return $this;
  295.     }
  296. }