<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const CUSTOMER_ROLE = "CUSTOMER_ROLE";
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="text")
*/
private $roles;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="datetime")
*/
private $date_added;
/**
* @ORM\Column(type="boolean")
*/
private $active;
/**
* @ORM\OneToOne(targetEntity=UserAddress::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $userAddress;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripe_customer_id;
/**
* @ORM\OneToMany(targetEntity=UserPaymentMethod::class, mappedBy="user", orphanRemoval=true)
*/
private $userPaymentMethods;
/**
* @ORM\OneToMany(targetEntity=ShortCode::class, mappedBy="user", orphanRemoval=true)
*/
private $shortCodes;
/**
* @ORM\OneToMany(targetEntity=PaymentInvoice::class, mappedBy="user", orphanRemoval=true)
*/
private $paymentInvoices;
public function __construct()
{
$this->userPaymentMethods = new ArrayCollection();
$this->shortCodes = new ArrayCollection();
$this->paymentInvoices = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = json_decode($this->roles);
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = json_encode($roles);
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getDateAdded(): ?\DateTimeInterface
{
return $this->date_added;
}
public function setDateAdded(\DateTimeInterface $date_added): self
{
$this->date_added = $date_added;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getUserAddress(): ?UserAddress
{
return $this->userAddress;
}
public function setUserAddress(UserAddress $userAddress): self
{
// set the owning side of the relation if necessary
if ($userAddress->getUser() !== $this) {
$userAddress->setUser($this);
}
$this->userAddress = $userAddress;
return $this;
}
public function getStripeCustomerId(): ?string
{
return $this->stripe_customer_id;
}
public function setStripeCustomerId(?string $stripe_customer_id): self
{
$this->stripe_customer_id = $stripe_customer_id;
return $this;
}
/**
* @return Collection<int, UserPaymentMethod>
*/
public function getUserPaymentMethods(): Collection
{
return $this->userPaymentMethods;
}
public function addUserPaymentMethod(UserPaymentMethod $userPaymentMethod): self
{
if (!$this->userPaymentMethods->contains($userPaymentMethod)) {
$this->userPaymentMethods[] = $userPaymentMethod;
$userPaymentMethod->setUser($this);
}
return $this;
}
public function removeUserPaymentMethod(UserPaymentMethod $userPaymentMethod): self
{
if ($this->userPaymentMethods->removeElement($userPaymentMethod)) {
// set the owning side to null (unless already changed)
if ($userPaymentMethod->getUser() === $this) {
$userPaymentMethod->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ShortCode>
*/
public function getShortCodes(): Collection
{
return $this->shortCodes;
}
public function addShortCode(ShortCode $shortCode): self
{
if (!$this->shortCodes->contains($shortCode)) {
$this->shortCodes[] = $shortCode;
$shortCode->setUser($this);
}
return $this;
}
public function removeShortCode(ShortCode $shortCode): self
{
if ($this->shortCodes->removeElement($shortCode)) {
// set the owning side to null (unless already changed)
if ($shortCode->getUser() === $this) {
$shortCode->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, PaymentInvoice>
*/
public function getPaymentInvoices(): Collection
{
return $this->paymentInvoices;
}
public function addPaymentInvoice(PaymentInvoice $paymentInvoice): self
{
if (!$this->paymentInvoices->contains($paymentInvoice)) {
$this->paymentInvoices[] = $paymentInvoice;
$paymentInvoice->setUser($this);
}
return $this;
}
public function removePaymentInvoice(PaymentInvoice $paymentInvoice): self
{
if ($this->paymentInvoices->removeElement($paymentInvoice)) {
// set the owning side to null (unless already changed)
if ($paymentInvoice->getUser() === $this) {
$paymentInvoice->setUser(null);
}
}
return $this;
}
}