<?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;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const AGE_25 = '< 25';
const AGE_25_35 = '25-35';
const AGE_35_45 = '35-45';
const AGE_45_55 = '45-55';
const AGE_55 = '> 55';
const LEVEL_BAC = 'BAC';
const LEVEL_BAC2 = 'BAC+2';
const LEVEL_BAC3 = 'BAC+3';
const LEVEL_BAC4 = 'BAC+4';
const LEVEL_BAC5 = 'BAC+5';
const NB_MANAGED_10 = '< 10';
const NB_MANAGED_10_20 = '10-20';
const NB_MANAGED_20_30 = '20-30';
const NB_MANAGED_30 = '> 30';
/**
* @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 = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255)
*/
private $poste;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $age;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $level;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $diplome;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $initialTrained;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $alreadyTrained;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $experience;
/**
* @ORM\OneToMany(targetEntity=Respondent::class, mappedBy="user")
*/
private $respondents;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nbManaged;
public function __construct()
{
$this->respondents = 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 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 getPoste(): ?string
{
return $this->poste;
}
public function setPoste(string $poste): self
{
$this->poste = $poste;
return $this;
}
public function getAge(): ?string
{
return $this->age;
}
public function getAgeAsString()
{
$age ='';
switch ($this->age) {
case User::AGE_25:
$age = 'Moins de 25 ans';
break;
case User::AGE_25_35:
$age = 'Entre 25 et 35 ans';
break;
case User::AGE_35_45:
$age = 'Entre 35 et 45 ans';
break;
case User::AGE_45_55:
$age = 'Entre 45 et 55 ans';
break;
case User::AGE_55:
$age = 'Plus de 55 ans';
break;
default:
break;
}
return $age;
}
public function setAge(?string $age): self
{
$this->age = $age;
return $this;
}
public function getLevel(): ?string
{
return $this->level;
}
public function getLevelAsString()
{
$level ='';
switch ($this->level) {
case User::LEVEL_BAC:
$level = 'BAC (ou inférieur)';
break;
case User::LEVEL_BAC2:
$level = 'BAC+2';
break;
case User::LEVEL_BAC3:
$level = 'BAC+3';
break;
case User::LEVEL_BAC4:
$level = 'BAC+4';
break;
case User::LEVEL_BAC5:
$level = 'BAC+5 (ou supérieur)';
break;
default:
break;
}
return $level;
}
public function setLevel(?string $level): self
{
$this->level = $level;
return $this;
}
public function getDiplome(): ?string
{
return $this->diplome;
}
public function setDiplome(?string $diplome): self
{
$this->diplome = $diplome;
return $this;
}
public function isInitialTrained(): ?bool
{
return $this->initialTrained;
}
public function setInitialTrained(?bool $initialTrained): self
{
$this->initialTrained = $initialTrained;
return $this;
}
public function isAlreadyTrained(): ?bool
{
return $this->alreadyTrained;
}
public function setAlreadyTrained(?bool $alreadyTrained): self
{
$this->alreadyTrained = $alreadyTrained;
return $this;
}
public function getExperience(): ?int
{
return $this->experience;
}
public function setExperience(?int $experience): self
{
$this->experience = $experience;
return $this;
}
/**
* @return Collection<int, Respondent>
*/
public function getRespondents(): Collection
{
return $this->respondents;
}
public function addRespondent(Respondent $respondent): self
{
if (!$this->respondents->contains($respondent)) {
$this->respondents[] = $respondent;
$respondent->setUser($this);
}
return $this;
}
public function removeRespondent(Respondent $respondent): self
{
if ($this->respondents->removeElement($respondent)) {
// set the owning side to null (unless already changed)
if ($respondent->getUser() === $this) {
$respondent->setUser(null);
}
}
return $this;
}
public function getNbManaged(): ?string
{
return $this->nbManaged;
}
public function getNbManagedAsString()
{
$nbManaged ='';
switch ($this->nbManaged) {
case User::NB_MANAGED_10:
$nbManaged = 'Moins de 10 personnes';
break;
case User::NB_MANAGED_10_20:
$nbManaged = 'Entre 10 et 20 personnes';
break;
case User::NB_MANAGED_20_30:
$nbManaged = 'Entre 20 et 30 personnes';
break;
case User::NB_MANAGED_30:
$nbManaged = 'Plus de 30 personnes';
break;
}
return $nbManaged;
}
public function setNbManaged(?string $nbManaged): self
{
$this->nbManaged = $nbManaged;
return $this;
}
}