<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;;
use Doctrine\DBAL\Types\Types;
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)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private ?string $phone = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255)]
private ?string $firstname = null;
#[ORM\Column(length: 255)]
private ?string $lastname = null;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?Card $card = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: CouponUser::class)]
private Collection $coupon;
#[ORM\Column(length: 255)]
private ?string $slug = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: TicketGratter::class)]
private Collection $ticketGratters;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $birthdate = null;
public function __construct()
{
$this->coupon = new ArrayCollection();
$this->ticketGratters = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): void
{
$this->phone = $phone;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstname(): ?string
{
return ucwords($this->firstname);
}
public function setFirstname(string $firstname): static
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return ucwords($this->lastname);
}
public function getFullName(): ?string
{
return $this->getFirstname() . ' ' . $this->getLastname();
}
public function setLastname(string $lastname): static
{
$this->lastname = $lastname;
return $this;
}
public function getCard(): ?Card
{
return $this->card;
}
public function setCard(Card $card): static
{
// set the owning side of the relation if necessary
if ($card->getUser() !== $this) {
$card->setUser($this);
}
$this->card = $card;
return $this;
}
/**
* @return Collection<int, CouponUser>
*/
public function getCoupon(): Collection
{
return $this->coupon;
}
public function addCoupon(CouponUser $coupon): static
{
if (!$this->coupon->contains($coupon)) {
$this->coupon->add($coupon);
$coupon->setUser($this);
}
return $this;
}
public function removeCoupon(CouponUser $coupon): static
{
if ($this->coupon->removeElement($coupon)) {
// set the owning side to null (unless already changed)
if ($coupon->getUser() === $this) {
$coupon->setUser(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, TicketGratter>
*/
public function getTicketGratters(): Collection
{
return $this->ticketGratters;
}
public function addTicketGratter(TicketGratter $ticketGratter): static
{
if (!$this->ticketGratters->contains($ticketGratter)) {
$this->ticketGratters->add($ticketGratter);
$ticketGratter->setUser($this);
}
return $this;
}
public function removeTicketGratter(TicketGratter $ticketGratter): static
{
if ($this->ticketGratters->removeElement($ticketGratter)) {
// set the owning side to null (unless already changed)
if ($ticketGratter->getUser() === $this) {
$ticketGratter->setUser(null);
}
}
return $this;
}
public function getBirthdate(): ?\DateTimeInterface
{
return $this->birthdate;
}
public function setBirthdate(?\DateTimeInterface $birthdate): self
{
$this->birthdate = $birthdate;
return $this;
}
}