<?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 libphonenumber\PhoneNumber;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Uid\Uuid;
/**
* Table pour la gestion des utilisateurs
*
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"},message="Un compte exist déjà avec ce mail")
* @UniqueEntity(fields={"cardNumber"},message="Un compte exist déjà pour ce numéro de pièce d'identité")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
*/
private $id;
/**
* @ORM\Column(name="email", type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="phone_number", length=255, nullable=true)
*/
private $number;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $location;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $position;
/**
* @ORM\OneToMany(targetEntity=Requests::class, mappedBy="userRequest", cascade={"persist", "remove"})
*/
private $requests;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $profile;
/**
* @ORM\Column(type="boolean", length=255, nullable=true)
*/
private $locked = true;
/**
* @ORM\OneToMany(targetEntity=History::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $histories;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $picture;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $idCard;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cardNumber;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $certificate = [];
/**
* @ORM\Column(type="boolean")
*/
private $verified = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $verifiedToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $verifiedExpiration;
/**
* @ORM\Column(type="boolean",)
*/
private $updatedPassword = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $civility;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $residence;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $companyName;
public function __construct()
{
$this->requests = new ArrayCollection();
$this->histories = new ArrayCollection();
}
public function getId(): ?Uuid
{
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 = $this->roles;
// guarantee every user at least has ROLE_USER
if(!in_array('ROLE_ADMIN', $roles, true) && !in_array('ROLE_MANAGER', $roles, true)){
$roles[] = 'ROLE_USER';
}
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles ?? ['ROLE_USER'];
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 getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getNumber(): ?PhoneNumber
{
return $this->number;
}
public function setNumber(?PhoneNumber $number): self
{
$this->number = $number;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection<int, Requests>
*/
public function getRequests(): Collection
{
return $this->requests;
}
public function addRequest(Requests $request): self
{
if (!$this->requests->contains($request)) {
$this->requests[] = $request;
$request->setUserRequest($this);
}
return $this;
}
public function removeRequest(Requests $request): self
{
if ($this->requests->removeElement($request)) {
// set the owning side to null (unless already changed)
if ($request->getUserRequest() === $this) {
$request->setUserRequest(null);
}
}
return $this;
}
public function getProfile(): ?string
{
return $this->profile;
}
public function setProfile(?string $profile): self
{
$this->profile = $profile;
return $this;
}
public function isLocked(): ?bool
{
return $this->locked;
}
public function setLocked(?bool $locked): self
{
$this->locked = $locked;
return $this;
}
/**
* @return Collection<int, History>
*/
public function getHistories(): Collection
{
return $this->histories;
}
public function addHistory(History $history): self
{
if (!$this->histories->contains($history)) {
$this->histories[] = $history;
$history->setUser($this);
}
return $this;
}
public function removeHistory(History $history): self
{
if ($this->histories->removeElement($history)) {
// set the owning side to null (unless already changed)
if ($history->getUser() === $this) {
$history->setUser(null);
}
}
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getIdCard(): ?string
{
return $this->idCard;
}
public function setIdCard(?string $idCard): self
{
$this->idCard = $idCard;
return $this;
}
public function getCardNumber(): ?string
{
return $this->cardNumber;
}
public function setCardNumber(?string $cardNumber): self
{
$this->cardNumber = $cardNumber;
return $this;
}
public function getCertificate(): ?array
{
return array_unique($this->certificate);
}
public function setCertificate(?array $certificate): self
{
$this->certificate = $certificate;
return $this;
}
public function isVerified(): ?bool
{
return $this->verified;
}
public function setVerified(bool $verified): self
{
$this->verified = $verified;
return $this;
}
public function getVerifiedToken(): ?string
{
return $this->verifiedToken;
}
public function setVerifiedToken(?string $verifiedToken): self
{
$this->verifiedToken = $verifiedToken;
return $this;
}
public function getVerifiedExpiration(): ?\DateTimeInterface
{
return $this->verifiedExpiration;
}
public function setVerifiedExpiration(?\DateTimeInterface $verifiedExpiration): self
{
$this->verifiedExpiration = $verifiedExpiration;
return $this;
}
public function isUpdatedPassword(): ?bool
{
return $this->updatedPassword;
}
public function setUpdatedPassword(bool $updatedPassword): self
{
$this->updatedPassword = $updatedPassword;
return $this;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getResidence(): ?string
{
return $this->residence;
}
public function setResidence(?string $residence): self
{
$this->residence = $residence;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
}