<?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;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(
* fields={"email"},
* message="Ce mail est déjà utilisé."
* )
* @UniqueEntity(fields={"telephone"},message="Ce téléphone est déjà utilisé." )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Email(message = "L'email '{{ value }}' n'est pas valide.")
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\ManyToOne(targetEntity=Role::class, inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $role;
/**
* @ORM\ManyToOne(targetEntity=Site::class, inversedBy="users")
* @ORM\JoinColumn(nullable=true)
*/
private $site;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=15, nullable=true)
* @Assert\Length(min=8,minMessage = "La taille minimum doit être de {{ limit }} caractères")
*/
private $telephone;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="executant")
*/
private $tasks;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="createdby")
*/
private $tasksemit;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $firstconnexion;
/**
* @ORM\OneToMany(targetEntity=DemandeByCanal::class, mappedBy="executant")
*/
private $demandeByCanals;
/**
* @ORM\OneToMany(targetEntity=DemandePro::class, mappedBy="executant")
*/
private $demandePros;
public function __construct()
{
$this->tasks = new ArrayCollection();
$this->tasksemit = new ArrayCollection();
// $this->demandeByCanals = new ArrayCollection();
$this->demandePros = 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 = $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 getRole(): ?Role
{
return $this->role;
}
public function setRole(?Role $role): self
{
$this->role = $role;
return $this;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): self
{
$this->site = $site;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->setExecutant($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getExecutant() === $this) {
$task->setExecutant(null);
}
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasksemit(): Collection
{
return $this->tasksemit;
}
public function addTasksemit(Task $tasksemit): self
{
if (!$this->tasksemit->contains($tasksemit)) {
$this->tasksemit[] = $tasksemit;
$tasksemit->setCreatedby($this);
}
return $this;
}
public function removeTasksemit(Task $tasksemit): self
{
if ($this->tasksemit->removeElement($tasksemit)) {
// set the owning side to null (unless already changed)
if ($tasksemit->getCreatedby() === $this) {
$tasksemit->setCreatedby(null);
}
}
return $this;
}
public function getFirstconnexion(): ?bool
{
return $this->firstconnexion;
}
public function setFirstconnexion(bool $firstconnexion): self
{
$this->firstconnexion = $firstconnexion;
return $this;
}
/**
* @return Collection<int, DemandeByCanal>
*/
public function getDemandeByCanals(): Collection
{
return $this->demandeByCanals;
}
public function addDemandeByCanal(DemandeByCanal $demandeByCanal): self
{
if (!$this->demandeByCanals->contains($demandeByCanal)) {
$this->demandeByCanals[] = $demandeByCanal;
$demandeByCanal->setExecutant($this);
}
return $this;
}
public function removeDemandeByCanal(DemandeByCanal $demandeByCanal): self
{
if ($this->demandeByCanals->removeElement($demandeByCanal)) {
// set the owning side to null (unless already changed)
if ($demandeByCanal->getExecutant() === $this) {
$demandeByCanal->setExecutant(null);
}
}
return $this;
}
/**
* @return Collection<int, DemandePro>
*/
public function getDemandePros(): Collection
{
return $this->demandePros;
}
public function addDemandePro(DemandePro $demandePro): self
{
if (!$this->demandePros->contains($demandePro)) {
$this->demandePros[] = $demandePro;
$demandePro->setExecutant($this);
}
return $this;
}
public function removeDemandePro(DemandePro $demandePro): self
{
if ($this->demandePros->removeElement($demandePro)) {
// set the owning side to null (unless already changed)
if ($demandePro->getExecutant() === $this) {
$demandePro->setExecutant(null);
}
}
return $this;
}
}