<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'Adresse email invalide')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string', nullable: false)]
private $password;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(type: 'string', length: 180, nullable: true)]
private $firstName;
#[ORM\Column(type: 'string', length: 180, nullable: true)]
private $lastName;
#[ORM\Column(type: 'string', length: 180, nullable: true)]
private $phoneNumber;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Commande::class, orphanRemoval: true)]
private $commandes;
#[ORM\ManyToMany(targetEntity: Foodtruck::class, mappedBy: 'users')]
private $foodtrucks;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: AccesEmplacement::class, orphanRemoval: true)]
private Collection $accesEmplacements;
#[ORM\OneToMany(mappedBy: 'createur', targetEntity: Emplacement::class)]
private Collection $emplacements;
public function __construct()
{
$this->commandes = new ArrayCollection();
$this->foodtrucks = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris'));
$this->accesEmplacements = new ArrayCollection();
$this->emplacements = 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;
}
/**
* The public representation of the user (e.g. a username, an email address, etc.)
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3
*/
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 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 isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
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 getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return Collection|Commande[]
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commande $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes[] = $commande;
$commande->setUser($this);
}
return $this;
}
public function removeCommande(Commande $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getUser() === $this) {
$commande->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Foodtruck>
*/
public function getFoodtrucks(): Collection
{
return $this->foodtrucks;
}
public function addFoodtruck(Foodtruck $foodtruck): self
{
if (!$this->foodtrucks->contains($foodtruck)) {
$this->foodtrucks->add($foodtruck);
$foodtruck->addUser($this);
}
return $this;
}
public function removeFoodtruck(Foodtruck $foodtruck): self
{
if ($this->foodtrucks->removeElement($foodtruck)) {
$foodtruck->removeUser($this);
}
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, AccesEmplacement>
*/
public function getAccesEmplacements(): Collection
{
return $this->accesEmplacements;
}
public function addAccesEmplacement(AccesEmplacement $accesEmplacement): self
{
if (!$this->accesEmplacements->contains($accesEmplacement)) {
$this->accesEmplacements->add($accesEmplacement);
$accesEmplacement->setUser($this);
}
return $this;
}
public function removeAccesEmplacement(AccesEmplacement $accesEmplacement): self
{
if ($this->accesEmplacements->removeElement($accesEmplacement)) {
// set the owning side to null (unless already changed)
if ($accesEmplacement->getUser() === $this) {
$accesEmplacement->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Emplacement>
*/
public function getEmplacements(): Collection
{
return $this->emplacements;
}
public function addEmplacement(Emplacement $emplacement): static
{
if (!$this->emplacements->contains($emplacement)) {
$this->emplacements->add($emplacement);
$emplacement->setCreateur($this);
}
return $this;
}
public function removeEmplacement(Emplacement $emplacement): static
{
if ($this->emplacements->removeElement($emplacement)) {
// set the owning side to null (unless already changed)
if ($emplacement->getCreateur() === $this) {
$emplacement->setCreateur(null);
}
}
return $this;
}
}