src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Appointment\Appointment;
  4. use App\Entity\Company\Company;
  5. use App\Entity\Customer\Customer;
  6. use App\Entity\Event\EventUser;
  7. use App\Entity\Invoice\Invoice;
  8. use App\Entity\Order\Cart;
  9. use App\Entity\Order\Order;
  10. use App\Entity\UserInformation\UserInformation;
  11. use App\Entity\User\Wish;
  12. use App\Repository\UserRepository;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  18. use Symfony\Component\Security\Core\User\UserInterface;
  19. #[ORM\Entity(repositoryClassUserRepository::class)]
  20. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  21. class User implements UserInterfacePasswordAuthenticatedUserInterface
  22. {
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\Column(length180uniquetrue)]
  28.     private ?string $email null;
  29.     #[ORM\Column]
  30.     private array $roles = [];
  31.     /**
  32.      * @var string The hashed password
  33.      */
  34.     #[ORM\Column]
  35.     private ?string $password null;
  36.     #[ORM\Column(type'boolean')]
  37.     private $isVerified false;
  38.     #[ORM\Column(length255)]
  39.     private ?string $userName null;
  40.     #[ORM\Column(length20nullabletrue)]
  41.     private ?string $telephone null;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityComment::class)]
  43.     private Collection $comments;
  44.     #[ORM\OneToMany(mappedBy'user'targetEntityOrder::class)]
  45.     private Collection $orders;
  46.     #[ORM\OneToMany(mappedBy'user'targetEntityEventUser::class)]
  47.     private Collection $events;
  48.     #[ORM\OneToMany(mappedBy'user'targetEntityAppointment::class)]
  49.     private Collection $appointments;
  50.     #[ORM\OneToMany(mappedBy'user'targetEntityCart::class)]
  51.     private Collection $carts;
  52.     #[ORM\OneToMany(mappedBy'user'targetEntityUserInformation::class)]
  53.     private Collection $userInformation;
  54.     #[ORM\ManyToMany(targetEntityCompany::class, inversedBy'users')]
  55.     #[ORM\JoinTable(name'user_company')]
  56.     private Collection $companies;
  57.     #[ORM\OneToMany(mappedBy'user'targetEntityWish::class)]
  58.     private Collection $wishes;
  59.     #[ORM\OneToOne(inversedBy'user')]
  60.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  61.     private ?Customer $customer null;
  62.     #[ORM\OneToMany(mappedBy'user'targetEntityInvoice::class)]
  63.     private Collection $invoices;
  64.     public function __toString()
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function __construct()
  69.     {
  70.         $this->comments = new ArrayCollection();
  71.         $this->orders = new ArrayCollection();
  72.         $this->events = new ArrayCollection();
  73.         $this->appointments = new ArrayCollection();
  74.         $this->carts = new ArrayCollection();
  75.         $this->userInformation = new ArrayCollection();
  76.         $this->companies = new ArrayCollection();
  77.         $this->wishes = new ArrayCollection();
  78.         $this->invoices = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getEmail(): ?string
  85.     {
  86.         return $this->email;
  87.     }
  88.     public function setEmail(string $email): self
  89.     {
  90.         $this->email $email;
  91.         return $this;
  92.     }
  93.     /**
  94.      * A visual identifier that represents this user.
  95.      *
  96.      * @see UserInterface
  97.      */
  98.     public function getUserIdentifier(): string
  99.     {
  100.         return (string) $this->email;
  101.     }
  102.     /**
  103.      * @see UserInterface
  104.      */
  105.     public function getRoles(): array
  106.     {
  107.         $roles $this->roles;
  108.         // guarantee every user at least has ROLE_USER
  109.         $roles[] = 'ROLE_USER';
  110.         return array_unique($roles);
  111.     }
  112.     public function setRoles(array $roles): self
  113.     {
  114.         $this->roles $roles;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @see PasswordAuthenticatedUserInterface
  119.      */
  120.     public function getPassword(): string
  121.     {
  122.         return $this->password;
  123.     }
  124.     public function setPassword(string $password): self
  125.     {
  126.         $this->password $password;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @see UserInterface
  131.      */
  132.     public function eraseCredentials()
  133.     {
  134.         // If you store any temporary, sensitive data on the user, clear it here
  135.         // $this->plainPassword = null;
  136.     }
  137.     public function isVerified(): bool
  138.     {
  139.         return $this->isVerified;
  140.     }
  141.     public function setIsVerified(bool $isVerified): self
  142.     {
  143.         $this->isVerified $isVerified;
  144.         return $this;
  145.     }
  146.     public function getUserName(): ?string
  147.     {
  148.         return $this->userName;
  149.     }
  150.     public function setUserName(string $userName): self
  151.     {
  152.         $this->userName $userName;
  153.         return $this;
  154.     }
  155.     public function getTelephone(): ?string
  156.     {
  157.         return $this->telephone;
  158.     }
  159.     public function setTelephone(?string $telephone): self
  160.     {
  161.         $this->telephone $telephone;
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, Comment>
  166.      */
  167.     public function getComments(): Collection
  168.     {
  169.         return $this->comments;
  170.     }
  171.     public function addComment(Comment $comment): self
  172.     {
  173.         if (!$this->comments->contains($comment)) {
  174.             $this->comments->add($comment);
  175.             $comment->setUser($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeComment(Comment $comment): self
  180.     {
  181.         if ($this->comments->removeElement($comment)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($comment->getUser() === $this) {
  184.                 $comment->setUser(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return Collection<int, Order>
  191.      */
  192.     public function getOrders(): Collection
  193.     {
  194.         return $this->orders;
  195.     }
  196.     public function addOrder(Order $order): static
  197.     {
  198.         if (!$this->orders->contains($order)) {
  199.             $this->orders->add($order);
  200.             $order->setUser($this);
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeOrder(Order $order): static
  205.     {
  206.         if ($this->orders->removeElement($order)) {
  207.             // set the owning side to null (unless already changed)
  208.             if ($order->getUser() === $this) {
  209.                 $order->setUser(null);
  210.             }
  211.         }
  212.         return $this;
  213.     }
  214.     /**
  215.      * @return Collection<int, EventUser>
  216.      */
  217.     public function getEvents(): Collection
  218.     {
  219.         return $this->events;
  220.     }
  221.     public function addEvent(EventUser $event): static
  222.     {
  223.         if (!$this->events->contains($event)) {
  224.             $this->events->add($event);
  225.             $event->setUser($this);
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeEvent(EventUser $event): static
  230.     {
  231.         if ($this->events->removeElement($event)) {
  232.             // set the owning side to null (unless already changed)
  233.             if ($event->getUser() === $this) {
  234.                 $event->setUser(null);
  235.             }
  236.         }
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection<int, Appointment>
  241.      */
  242.     public function getAppointments(): Collection
  243.     {
  244.         return $this->appointments;
  245.     }
  246.     public function addAppointment(Appointment $appointment): static
  247.     {
  248.         if (!$this->appointments->contains($appointment)) {
  249.             $this->appointments->add($appointment);
  250.             $appointment->setUser($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeAppointment(Appointment $appointment): static
  255.     {
  256.         if ($this->appointments->removeElement($appointment)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($appointment->getUser() === $this) {
  259.                 $appointment->setUser(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, Cart>
  266.      */
  267.     public function getCarts(): Collection
  268.     {
  269.         return $this->carts;
  270.     }
  271.     public function addCart(Cart $cart): static
  272.     {
  273.         if (!$this->carts->contains($cart)) {
  274.             $this->carts->add($cart);
  275.             $cart->setUser($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeCart(Cart $cart): static
  280.     {
  281.         if ($this->carts->removeElement($cart)) {
  282.             // set the owning side to null (unless already changed)
  283.             if ($cart->getUser() === $this) {
  284.                 $cart->setUser(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     /**
  290.      * @return Collection<int, UserInformation>
  291.      */
  292.     public function getUserInformation(): Collection
  293.     {
  294.         return $this->userInformation;
  295.     }
  296.     public function addUserInformation(UserInformation $userInformation): static
  297.     {
  298.         if (!$this->userInformation->contains($userInformation)) {
  299.             $this->userInformation->add($userInformation);
  300.             $userInformation->setUser($this);
  301.         }
  302.         return $this;
  303.     }
  304.     public function removeUserInformation(UserInformation $userInformation): static
  305.     {
  306.         if ($this->userInformation->removeElement($userInformation)) {
  307.             // set the owning side to null (unless already changed)
  308.             if ($userInformation->getUser() === $this) {
  309.                 $userInformation->setUser(null);
  310.             }
  311.         }
  312.         return $this;
  313.     }
  314.     public function getCompanies(): Collection
  315.     {
  316.         return $this->companies;
  317.     }
  318.     public function addCompany(Company $company): self
  319.     {
  320.         if (!$this->companies->contains($company)) {
  321.             $this->companies->add($company);
  322.             $company->addUser($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeCompany(Company $company): self
  327.     {
  328.         if ($this->companies->removeElement($company)) {
  329.             $company->removeUser($this);
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return Collection<int, Wish>
  335.      */
  336.     public function getWishes(): Collection
  337.     {
  338.         return $this->wishes;
  339.     }
  340.     public function addWish(Wish $wish): static
  341.     {
  342.         if (!$this->wishes->contains($wish)) {
  343.             $this->wishes->add($wish);
  344.             $wish->setUser($this);
  345.         }
  346.         return $this;
  347.     }
  348.     public function removeWish(Wish $wish): static
  349.     {
  350.         if ($this->wishes->removeElement($wish)) {
  351.             // set the owning side to null (unless already changed)
  352.             if ($wish->getUser() === $this) {
  353.                 $wish->setUser(null);
  354.             }
  355.         }
  356.         return $this;
  357.     }
  358.     public function getCustomer(): ?Customer
  359.     {
  360.         return $this->customer;
  361.     }
  362.     public function setCustomer(?Customer $customer): static
  363.     {
  364.         $this->customer $customer;
  365.         return $this;
  366.     }
  367.     /**
  368.      * @return Collection<int, Invoice>
  369.      */
  370.     public function getInvoices(): Collection
  371.     {
  372.         return $this->invoices;
  373.     }
  374.     public function addInvoice(Invoice $invoice): static
  375.     {
  376.         if (!$this->invoices->contains($invoice)) {
  377.             $this->invoices->add($invoice);
  378.             $invoice->setUser($this);
  379.         }
  380.         return $this;
  381.     }
  382.     public function removeInvoice(Invoice $invoice): static
  383.     {
  384.         if ($this->invoices->removeElement($invoice)) {
  385.             // set the owning side to null (unless already changed)
  386.             if ($invoice->getUser() === $this) {
  387.                 $invoice->setUser(null);
  388.             }
  389.         }
  390.         return $this;
  391.     }
  392. }