<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\DateTimeType;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use DateTimeInterface;
use DateTime;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="users")
* @UniqueEntity("email")
* @UniqueEntity("slug")
*
* @ORM\HasLifecycleCallbacks
*/
class User implements UserInterface
{
const USER_ROLES = [
'ROLE_SUPER_ADMIN',
'ROLE_ADMIN',
'ROLE_EDITOR',
'ROLE_USER',
];
const USER_STATUS = [
'active',
'blocked',
'waiting_validation',
'deleted',
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotNull(message="The email field is required.")
* @Assert\Email(message="This is not a valid email.")
*/
private $email;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $slug;
/**
* @var string The hashed password
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $activationKey;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotNull(message="The status field is required.")
* @Assert\Choice(choices=USER::USER_STATUS, message="Choose a valid status.")
*/
private $status;
/**
* @ORM\Column(type="json")
* @Assert\Choice(choices=USER::USER_ROLES, message="Choose a valid role.", multiple=true)
*/
private $roles = [];
/**
* @var string A "Y-m-d H:i:s" formatted value
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @var string A "Y-m-d H:i:s" formatted value
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\OneToOne(targetEntity=Coach::class, mappedBy="utilisateur", cascade={"persist", "remove"})
*/
private $coach;
/**
* @ORM\OneToOne(targetEntity=Subscription::class, mappedBy="utilisateur", cascade={"persist", "remove"})
*/
private $subscription;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeCustomerId;
/**
* @ORM\OneToMany(targetEntity=Reservation::class, mappedBy="utilisateur")
*/
private $reservations;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isAcceptNewsletter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isAcceptPromos;
public function __construct()
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
$this->status = 'active';
$this->reservations = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getFullName(): ?string
{
return $this->firstName . ' ' . $this->lastName;
}
/**
* @return string|null
*/
public function getFirstName(): ?string
{
return $this->firstName;
}
/**
* @param string|null $firstName
* @return self
*/
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string|null
*/
public function getLastName(): ?string
{
return $this->lastName;
}
/**
* @param string|null $lastName
* @return self
*/
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param string $email
* @return self
*/
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @param string $slug
* @return self
*/
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return string|null
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* @param string $password
* @return self
*/
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return string|null
*/
public function getActivationKey(): ?string
{
return $this->activationKey;
}
/**
* @param string|null $activationKey
* @return self
*/
public function setActivationKey(?string $activationKey): self
{
$this->activationKey = $activationKey;
return $this;
}
/**
* @return string|null
*/
public function getStatus(): ?string
{
return $this->status;
}
/**
* @param string $status
* @return self
*/
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getCreatedAt(): ?DateTimeInterface
{
return $this->createdAt;
}
/**
* @param DateTimeInterface $createdAt
* @return self
*/
public function setCreatedAt(DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
/**
* @param DateTimeInterface $updatedAt
* @return self
*/
public function setUpdatedAt(DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): 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): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* set createdAt, updatedAt fields automatically when doctrine persist Brief.
*
* @ORM\PrePersist
*/
public function onPrePersist(): void
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
}
/**
* update updatedAt field automatically when doctrine update brief.
*
* @ORM\PreUpdate
*/
public function onPreUpdate(): void
{
$this->updatedAt = new DateTime();
}
public function getCoach(): ?Coach
{
return $this->coach;
}
public function setCoach(Coach $coach): self
{
$this->coach = $coach;
// set the owning side of the relation if necessary
if ($coach->getUtilisateur() !== $this) {
$coach->setUtilisateur($this);
}
return $this;
}
public function __toString()
{
// TODO: Implement __toString() method.
return $this->firstName.' '.$this->lastName;
}
public function getSubscription(): ?Subscription
{
return $this->subscription;
}
public function setSubscription(Subscription $subscription): self
{
$this->subscription = $subscription;
// set the owning side of the relation if necessary
if ($subscription->getUtilisateur() !== $this) {
$subscription->setUtilisateur($this);
}
return $this;
}
public function getStripeCustomerId(): ?string
{
return $this->stripeCustomerId;
}
public function setStripeCustomerId(?string $stripeCustomerId): self
{
$this->stripeCustomerId = $stripeCustomerId;
return $this;
}
/**
* @return Collection|Reservation[]
*/
public function getReservations(): Collection
{
return $this->reservations;
}
public function addReservation(Reservation $reservation): self
{
if (!$this->reservations->contains($reservation)) {
$this->reservations[] = $reservation;
$reservation->setUtilisateur($this);
}
return $this;
}
public function removeReservation(Reservation $reservation): self
{
if ($this->reservations->contains($reservation)) {
$this->reservations->removeElement($reservation);
// set the owning side to null (unless already changed)
if ($reservation->getUtilisateur() === $this) {
$reservation->setUtilisateur(null);
}
}
return $this;
}
public function getIsAcceptNewsletter(): ?bool
{
return $this->isAcceptNewsletter;
}
public function setIsAcceptNewsletter(?bool $isAcceptNewsletter): self
{
$this->isAcceptNewsletter = $isAcceptNewsletter;
return $this;
}
public function getIsAcceptPromos(): ?bool
{
return $this->isAcceptPromos;
}
public function setIsAcceptPromos(?bool $isAcceptPromos): self
{
$this->isAcceptPromos = $isAcceptPromos;
return $this;
}
}