src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Serializer\Annotation\Ignore;
  10. /**
  11.  * @ORM\Entity
  12.  *
  13.  * @SuppressWarnings(PHPMD.TooManyFields)
  14.  */
  15. #[UniqueEntity(fields: ['email'], message'Ein Konto mit dieser E-Mail Adresse ist schon vergeben.')]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface {
  17.     /**
  18.      * @ORM\Id
  19.      *
  20.      * @ORM\GeneratedValue
  21.      *
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=180, unique=true, nullable=true)
  27.      */
  28.     private $username;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, nullable=true)
  31.      */
  32.     private $firstname;
  33.     /**
  34.      * @ORM\Column(type="string", length=180, nullable=true)
  35.      */
  36.     private $lastname;
  37.     /**
  38.      * @ORM\Column(type="boolean", nullable=true)
  39.      */
  40.     private $agreeTermsToReceiveTiInfos;
  41.     /**
  42.      * @ORM\Column(type="string", nullable=true)
  43.      */
  44.     private $passwordResetToken;
  45.     /**
  46.      * @ORM\Column(type="datetime", nullable=true)
  47.      */
  48.     private $passwordResetTokenValidity;
  49.     /**
  50.      * @ORM\Column(type="string", nullable=true)
  51.      */
  52.     private $verifyEmailToken;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=true)
  55.      */
  56.     private $verifyEmailTokenValidity;
  57.     /**
  58.      * @ORM\Column(type="string", length=180, nullable=true)
  59.      */
  60.     private $email;
  61.     /**
  62.      * @ORM\Column(type="json")
  63.      */
  64.     private $roles = [];
  65.     /**
  66.      * @var string The hashed password
  67.      *
  68.      * @ORM\Column(type="string")
  69.      */
  70.     private $password;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity=Tenant::class)
  73.      */
  74.     private $tenant;
  75.     /**
  76.      * @ORM\Column(type="boolean")
  77.      */
  78.     private $isVerified false;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user", orphanRemoval=true)
  81.      *
  82.      * @Ignore()
  83.      */
  84.     private $orders;
  85.     /**
  86.      * @ORM\OneToOne(targetEntity=AddressBook::class, mappedBy="user", cascade={"persist", "remove"})
  87.      */
  88.     private $addressBook;
  89.     private $plainTextPassword;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true)
  92.      */
  93.     private $dateCreated;
  94.     public function __construct() {
  95.         $this->orders = new ArrayCollection();
  96.     }
  97.     public function __toString() {
  98.         return "{$this->firstname} {$this->lastname}";
  99.     }
  100.     public function getId(): ?int {
  101.         return $this->id;
  102.     }
  103.     /**
  104.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  105.      */
  106.     public function getUsername(): string {
  107.         return (string) $this->username;
  108.     }
  109.     public function setUsername(string $username): self {
  110.         $this->username $username;
  111.         return $this;
  112.     }
  113.     public function getFirstname(): string {
  114.         return $this->firstname;
  115.     }
  116.     public function setFirstname(string $firstname): self {
  117.         $this->firstname $firstname;
  118.         return $this;
  119.     }
  120.     public function getLastname(): string {
  121.         return $this->lastname;
  122.     }
  123.     public function setLastname(string $lastname): self {
  124.         $this->lastname $lastname;
  125.         return $this;
  126.     }
  127.     public function getAgreeToTiInfos(): ?bool {
  128.         return $this->agreeTermsToReceiveTiInfos;
  129.     }
  130.     public function setAgreeToTiInfos(?bool $agreeTermsToReceiveTiInfos): self {
  131.         $this->agreeTermsToReceiveTiInfos $agreeTermsToReceiveTiInfos;
  132.         return $this;
  133.     }
  134.     public function getEmail(): string {
  135.         return $this->email;
  136.     }
  137.     public function setEmail(string $email): self {
  138.         $this->email $email;
  139.         return $this;
  140.     }
  141.     /**
  142.      * A visual identifier that represents this user.
  143.      *
  144.      * @see UserInterface
  145.      */
  146.     public function getUserIdentifier(): string {
  147.         return (string) $this->email;
  148.     }
  149.     /**
  150.      * @see UserInterface
  151.      */
  152.     public function getRoles(): array {
  153.         $roles $this->roles;
  154.         // guarantee every user at least has ROLE_USER
  155.         $roles[] = 'ROLE_USER';
  156.         return array_unique($roles);
  157.     }
  158.     public function setRoles(array $roles): self {
  159.         $this->roles $roles;
  160.         return $this;
  161.     }
  162.     /**
  163.      * @see PasswordAuthenticatedUserInterface
  164.      */
  165.     public function getPassword(): string {
  166.         return $this->password;
  167.     }
  168.     public function setPassword(string $password): self {
  169.         $this->password $password;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Returning a salt is only needed, if you are not using a modern
  174.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  175.      *
  176.      * @see UserInterface
  177.      */
  178.     public function getSalt(): ?string {
  179.         return null;
  180.     }
  181.     /**
  182.      * @see UserInterface
  183.      */
  184.     public function eraseCredentials() {
  185.         // If you store any temporary, sensitive data on the user, clear it here
  186.         // $this->plainPassword = null;
  187.     }
  188.     public function getTenant(): ?Tenant {
  189.         return $this->tenant;
  190.     }
  191.     public function setTenant(?Tenant $tenant): self {
  192.         $this->tenant $tenant;
  193.         return $this;
  194.     }
  195.     public function getPasswordResetToken(): ?string {
  196.         return $this->passwordResetToken;
  197.     }
  198.     public function setPasswordResetToken(?string $passwordResetToken): self {
  199.         $this->passwordResetToken $passwordResetToken;
  200.         return $this;
  201.     }
  202.     public function getPasswordResetTokenValidity(): ?\DateTimeInterface {
  203.         return $this->passwordResetTokenValidity;
  204.     }
  205.     public function setPasswordResetTokenValidity(?\DateTimeInterface $passwordResetTokenValidity): self {
  206.         $this->passwordResetTokenValidity $passwordResetTokenValidity;
  207.         return $this;
  208.     }
  209.     public function getVerifyEmailToken(): ?string {
  210.         return $this->verifyEmailToken;
  211.     }
  212.     public function setVerifyEmailToken(?string $verifyEmailToken): self {
  213.         $this->verifyEmailToken $verifyEmailToken;
  214.         return $this;
  215.     }
  216.     public function getVerifyEmailTokenValidity(): ?\DateTimeInterface {
  217.         return $this->verifyEmailTokenValidity;
  218.     }
  219.     public function setVerifyEmailTokenValidity(?\DateTimeInterface $verifyEmailTokenValidity): self {
  220.         $this->verifyEmailTokenValidity $verifyEmailTokenValidity;
  221.         return $this;
  222.     }
  223.     public function isVerified(): bool {
  224.         return $this->isVerified;
  225.     }
  226.     public function setIsVerified(bool $isVerified): self {
  227.         $this->isVerified $isVerified;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return Collection<int, Order>
  232.      */
  233.     public function getOrders(): Collection {
  234.         return $this->orders;
  235.     }
  236.     public function addOrder(Order $order): self {
  237.         if (!$this->orders->contains($order)) {
  238.             $this->orders[] = $order;
  239.             $order->setUser($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeOrder(Order $order): self {
  244.         if ($this->orders->removeElement($order)) {
  245.             // set the owning side to null (unless already changed)
  246.             if ($order->getUser() === $this) {
  247.                 $order->setUser(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252.     public function getAddressBook(): ?AddressBook {
  253.         return $this->addressBook;
  254.     }
  255.     public function setAddressBook(AddressBook $addressBook): self {
  256.         // set the owning side of the relation if necessary
  257.         if ($addressBook->getUser() !== $this) {
  258.             $addressBook->setUser($this);
  259.         }
  260.         $this->addressBook $addressBook;
  261.         return $this;
  262.     }
  263.     public function getPlainTextPassword(): ?string {
  264.         return $this->plainTextPassword;
  265.     }
  266.     public function setPlainTextPassword(?string $plainTextPassword): self {
  267.         $this->plainTextPassword $plainTextPassword;
  268.         return $this;
  269.     }
  270.     public function getDateCreated(): ?\DateTimeInterface {
  271.         return $this->dateCreated;
  272.     }
  273.     public function setDateCreated(?\DateTimeInterface $dateCreated): self {
  274.         $this->dateCreated $dateCreated;
  275.         return $this;
  276.     }
  277. }