src/Entity/User.php line 16

Open in your IDE?
  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\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRepository::class)
  11.  * @ORM\Table(name="`user`")
  12.  */
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     const CUSTOMER_ROLE "CUSTOMER_ROLE";
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="text")
  28.      */
  29.     private $roles;
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $firstname;
  39.     /**
  40.      * @ORM\Column(type="string", length=255)
  41.      */
  42.     private $lastname;
  43.     /**
  44.      * @ORM\Column(type="datetime")
  45.      */
  46.     private $date_added;
  47.     /**
  48.      * @ORM\Column(type="boolean")
  49.      */
  50.     private $active;
  51.     /**
  52.      * @ORM\OneToOne(targetEntity=UserAddress::class, mappedBy="user", cascade={"persist", "remove"})
  53.      */
  54.     private $userAddress;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $stripe_customer_id;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=UserPaymentMethod::class, mappedBy="user", orphanRemoval=true)
  61.      */
  62.     private $userPaymentMethods;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=ShortCode::class, mappedBy="user", orphanRemoval=true)
  65.      */
  66.     private $shortCodes;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=PaymentInvoice::class, mappedBy="user", orphanRemoval=true)
  69.      */
  70.     private $paymentInvoices;
  71.     public function __construct()
  72.     {
  73.         $this->userPaymentMethods = new ArrayCollection();
  74.         $this->shortCodes = new ArrayCollection();
  75.         $this->paymentInvoices = new ArrayCollection();
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getEmail(): ?string
  82.     {
  83.         return $this->email;
  84.     }
  85.     public function setEmail(string $email): self
  86.     {
  87.         $this->email $email;
  88.         return $this;
  89.     }
  90.     /**
  91.      * A visual identifier that represents this user.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getUserIdentifier(): string
  96.     {
  97.         return (string) $this->email;
  98.     }
  99.     /**
  100.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  101.      */
  102.     public function getUsername(): string
  103.     {
  104.         return (string) $this->email;
  105.     }
  106.     /**
  107.      * @see UserInterface
  108.      */
  109.     public function getRoles(): array
  110.     {
  111.         $roles json_decode($this->roles);
  112.         return array_unique($roles);
  113.     }
  114.     public function setRoles(array $roles): self
  115.     {
  116.         $this->roles json_encode($roles);
  117.         return $this;
  118.     }
  119.     /**
  120.      * @see PasswordAuthenticatedUserInterface
  121.      */
  122.     public function getPassword(): string
  123.     {
  124.         return $this->password;
  125.     }
  126.     public function setPassword(string $password): self
  127.     {
  128.         $this->password $password;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Returning a salt is only needed, if you are not using a modern
  133.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  134.      *
  135.      * @see UserInterface
  136.      */
  137.     public function getSalt(): ?string
  138.     {
  139.         return null;
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function eraseCredentials()
  145.     {
  146.         // If you store any temporary, sensitive data on the user, clear it here
  147.         // $this->plainPassword = null;
  148.     }
  149.     public function getFirstname(): ?string
  150.     {
  151.         return $this->firstname;
  152.     }
  153.     public function setFirstname(string $firstname): self
  154.     {
  155.         $this->firstname $firstname;
  156.         return $this;
  157.     }
  158.     public function getLastname(): ?string
  159.     {
  160.         return $this->lastname;
  161.     }
  162.     public function setLastname(string $lastname): self
  163.     {
  164.         $this->lastname $lastname;
  165.         return $this;
  166.     }
  167.     public function getDateAdded(): ?\DateTimeInterface
  168.     {
  169.         return $this->date_added;
  170.     }
  171.     public function setDateAdded(\DateTimeInterface $date_added): self
  172.     {
  173.         $this->date_added $date_added;
  174.         return $this;
  175.     }
  176.     public function getActive(): ?bool
  177.     {
  178.         return $this->active;
  179.     }
  180.     public function setActive(bool $active): self
  181.     {
  182.         $this->active $active;
  183.         return $this;
  184.     }
  185.     public function getUserAddress(): ?UserAddress
  186.     {
  187.         return $this->userAddress;
  188.     }
  189.     public function setUserAddress(UserAddress $userAddress): self
  190.     {
  191.         // set the owning side of the relation if necessary
  192.         if ($userAddress->getUser() !== $this) {
  193.             $userAddress->setUser($this);
  194.         }
  195.         $this->userAddress $userAddress;
  196.         return $this;
  197.     }
  198.     public function getStripeCustomerId(): ?string
  199.     {
  200.         return $this->stripe_customer_id;
  201.     }
  202.     public function setStripeCustomerId(?string $stripe_customer_id): self
  203.     {
  204.         $this->stripe_customer_id $stripe_customer_id;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return Collection<int, UserPaymentMethod>
  209.      */
  210.     public function getUserPaymentMethods(): Collection
  211.     {
  212.         return $this->userPaymentMethods;
  213.     }
  214.     public function addUserPaymentMethod(UserPaymentMethod $userPaymentMethod): self
  215.     {
  216.         if (!$this->userPaymentMethods->contains($userPaymentMethod)) {
  217.             $this->userPaymentMethods[] = $userPaymentMethod;
  218.             $userPaymentMethod->setUser($this);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeUserPaymentMethod(UserPaymentMethod $userPaymentMethod): self
  223.     {
  224.         if ($this->userPaymentMethods->removeElement($userPaymentMethod)) {
  225.             // set the owning side to null (unless already changed)
  226.             if ($userPaymentMethod->getUser() === $this) {
  227.                 $userPaymentMethod->setUser(null);
  228.             }
  229.         }
  230.         return $this;
  231.     }
  232.     /**
  233.      * @return Collection<int, ShortCode>
  234.      */
  235.     public function getShortCodes(): Collection
  236.     {
  237.         return $this->shortCodes;
  238.     }
  239.     public function addShortCode(ShortCode $shortCode): self
  240.     {
  241.         if (!$this->shortCodes->contains($shortCode)) {
  242.             $this->shortCodes[] = $shortCode;
  243.             $shortCode->setUser($this);
  244.         }
  245.         return $this;
  246.     }
  247.     public function removeShortCode(ShortCode $shortCode): self
  248.     {
  249.         if ($this->shortCodes->removeElement($shortCode)) {
  250.             // set the owning side to null (unless already changed)
  251.             if ($shortCode->getUser() === $this) {
  252.                 $shortCode->setUser(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return Collection<int, PaymentInvoice>
  259.      */
  260.     public function getPaymentInvoices(): Collection
  261.     {
  262.         return $this->paymentInvoices;
  263.     }
  264.     public function addPaymentInvoice(PaymentInvoice $paymentInvoice): self
  265.     {
  266.         if (!$this->paymentInvoices->contains($paymentInvoice)) {
  267.             $this->paymentInvoices[] = $paymentInvoice;
  268.             $paymentInvoice->setUser($this);
  269.         }
  270.         return $this;
  271.     }
  272.     public function removePaymentInvoice(PaymentInvoice $paymentInvoice): self
  273.     {
  274.         if ($this->paymentInvoices->removeElement($paymentInvoice)) {
  275.             // set the owning side to null (unless already changed)
  276.             if ($paymentInvoice->getUser() === $this) {
  277.                 $paymentInvoice->setUser(null);
  278.             }
  279.         }
  280.         return $this;
  281.     }
  282. }