<?php
/*
* Ce fichier est la propriété de l'association (c) Projets Métiers
*
* (c) crée par Jean-Marc CATALA <jeanmmarccatala@gmail.com>
*
*/
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\Boolean;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use function in_array;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="Il y a déjà un compte avec cette adresse mail.")
* @method string getUserIdentifier()
*/
class User implements UserInterface
{
const ROLE_COLLEGE = "ROLE_COLLEGE";
const ROLE_LYCEE = "ROLE_LYCEE";
const ROLE_ADULTE = "ROLE_ADULTE";
const ROLE_PARENT = "ROLE_PARENT";
const ROLE_PROF = "ROLE_PROF";
const ROLE_CONSEILLER = "ROLE_CONSEILLER";
const ROLE_MENTOR = "ROLE_MENTOR";
const ROLE_EXPERT = "ROLE_EXPERT";
const ROLE_ADMIN = "ROLE_ADMIN";
const STATUS_ACTIF = 1;
const STATUS_UNVERIFIED = 2;
CONST STATUS_DELETED = 3;
/**
* @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", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups("main")
*/
private $twitterUsername;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\ManyToOne(targetEntity=Step::class, inversedBy="users")
*/
private $step;
/**
* @ORM\ManyToOne(targetEntity=Question::class, inversedBy="users")
*/
private $question;
/**
* @ORM\OneToMany(targetEntity=UserAnswer::class, mappedBy="user")
*/
private $answers;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=UserAnswerAdd::class, mappedBy="user")
*/
private $userAnswerAdds;
/**
* @ORM\Column(type="smallint")
*/
private $status = self::STATUS_UNVERIFIED;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $emailParent1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $emailParent2;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="parents")
*/
private $enfants;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="enfants")
*/
private $parents;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="eleves")
*/
private $profPrincipal;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="profPrincipal")
*/
private $eleves;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="mentored")
*/
private $mentor;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="mentor")
*/
private $mentored;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="adultes")
*/
private $conseille;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="conseille")
*/
private $adultes;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $classe;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
/**
* @ORM\ManyToMany(targetEntity=Institution::class, inversedBy="listUsers")
*/
private $listInstitutions;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $bilanStepProf;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $role;
/**
* @ORM\OneToOne(targetEntity=Survey::class, inversedBy="user", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $survey;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metier;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $mustBeMentored;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $hasMentor;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reset_token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $codePostal;
/**
* @ORM\ManyToOne(targetEntity=Institution::class, inversedBy="users")
*/
private $institution;
/**
* @ORM\OneToMany(targetEntity=Institution::class, mappedBy="exp")
*/
private $exp;
public function __construct()
{
$this->answers = new ArrayCollection();
$this->userAnswerAdds = new ArrayCollection();
$this->enfants = new ArrayCollection();
$this->parents = new ArrayCollection();
$this->eleves = new ArrayCollection();
$this->adultes = new ArrayCollection();
$this->listInstitutions = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->setHasMentor(0);
$this->expert = new ArrayCollection();
$this->expertMetier = new ArrayCollection();
$this->exp = new ArrayCollection();
}
public static function getRolefromString(string $string): string{
switch ($string){
case "college" : return self::ROLE_COLLEGE;
case "lycee" : return self::ROLE_LYCEE;
case "adulte" : return self::ROLE_ADULTE;
case "professeur" : return self::ROLE_PROF;
case "parent" : return self::ROLE_PARENT;
case "conseiller" : return self::ROLE_CONSEILLER;
case "mentor" : return self::ROLE_MENTOR;
case "expert" : return self::ROLE_EXPERT;
default: return "";
}
}
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 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 hasRole(string $roles):bool {
return in_array($roles, $this->getRoles());
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword()
{
return $this->password;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed for apps that do not check user passwords
}
/**
* @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 getTwitterUsername(): ?string
{
return $this->twitterUsername;
}
public function setTwitterUsername(?string $twitterUsername): self
{
$this->twitterUsername = $twitterUsername;
return $this;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getStep(): ?Step
{
return $this->step;
}
public function setStep(?Step $step): self
{
$this->step = $step;
return $this;
}
public function getQuestion(): ?Question
{
return $this->question;
}
public function setQuestion(?Question $question): self
{
$this->question = $question;
return $this;
}
/**
* @return Collection|UserAnswer[]
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(UserAnswer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
$answer->setUser($this);
}
return $this;
}
public function removeAnswer(UserAnswer $answer): self
{
if ($this->answers->contains($answer)) {
$this->answers->removeElement($answer);
// set the owning side to null (unless already changed)
if ($answer->getUser() === $this) {
$answer->setUser(null);
}
}
return $this;
}
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|UserAnswerAdd[]
*/
public function getUserAnswerAdds(): Collection
{
return $this->userAnswerAdds;
}
public function addUserAnswerAdd(UserAnswerAdd $userAnswerAdd): self
{
if (!$this->userAnswerAdds->contains($userAnswerAdd)) {
$this->userAnswerAdds[] = $userAnswerAdd;
$userAnswerAdd->setUser($this);
}
return $this;
}
public function removeUserAnswerAdd(UserAnswerAdd $userAnswerAdd): self
{
if ($this->userAnswerAdds->contains($userAnswerAdd)) {
$this->userAnswerAdds->removeElement($userAnswerAdd);
// set the owning side to null (unless already changed)
if ($userAnswerAdd->getUser() === $this) {
$userAnswerAdd->setUser(null);
}
}
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function getEmailParent1(): ?string
{
return $this->emailParent1;
}
public function setEmailParent1(?string $emailParent1): self
{
$this->emailParent1 = $emailParent1;
return $this;
}
public function getEmailParent2(): ?string
{
return $this->emailParent2;
}
public function setEmailParent2(?string $emailParent2): self
{
$this->emailParent2 = $emailParent2;
return $this;
}
/**
* @return Collection|self[]
*/
public function getEnfants(): Collection
{
return $this->enfants;
}
public function addEnfant(self $enfant): self
{
if (!$this->enfants->contains($enfant)) {
$this->enfants[] = $enfant;
}
return $this;
}
public function removeEnfant(self $enfant): self
{
if ($this->enfants->contains($enfant)) {
$this->enfants->removeElement($enfant);
}
return $this;
}
/**
* @return Collection|self[]
*/
public function getParents(): Collection
{
return $this->parents;
}
public function addParent(self $parent): self
{
if (!$this->parents->contains($parent)) {
$this->parents[] = $parent;
$parent->addEnfant($this);
}
return $this;
}
public function removeParent(self $parent): self
{
if ($this->parents->contains($parent)) {
$this->parents->removeElement($parent);
$parent->removeEnfant($this);
}
return $this;
}
public function getProfPrincipal(): ?self
{
return $this->profPrincipal;
}
public function setProfPrincipal(?self $profPrincipal): self
{
$this->profPrincipal = $profPrincipal;
return $this;
}
/**
* @return Collection|self[]
*/
public function getEleves(): Collection
{
return $this->eleves;
}
public function addEleve(self $eleve): self
{
if (!$this->eleves->contains($eleve)) {
$this->eleves[] = $eleve;
$eleve->setProfPrincipal($this);
}
return $this;
}
public function removeEleve(self $eleve): self
{
if ($this->eleves->contains($eleve)) {
$this->eleves->removeElement($eleve);
// set the owning side to null (unless already changed)
if ($eleve->getProfPrincipal() === $this) {
$eleve->setProfPrincipal(null);
}
}
return $this;
}
/************************/
public function getMentor(): ?self
{
return $this->mentor;
}
public function setMentor(?self $mentor): self
{
$this->mentor = $mentor;
return $this;
}
/**
* @return Collection|self[]
*/
public function getMentored(): Collection
{
return $this->mentored;
}
public function addMentored(self $mentored): self
{
if (!$this->mentored->contains($mentored)) {
$this->mentored[] = $mentored;
$mentored->setProfPrincipal($this);
}
return $this;
}
public function removeMentored(self $mentored): self
{
if ($this->mentored->contains($mentored)) {
$this->mentored->removeElement($mentored);
// set the owning side to null (unless already changed)
if ($mentored->getMentor() === $this) {
$mentored->setMentor(null);
}
}
return $this;
}
/************************/
public function getConseille(): ?self
{
return $this->conseille;
}
public function setConseille(?self $conseille): self
{
$this->conseille = $conseille;
return $this;
}
/**
* @return Collection|self[]
*/
public function getAdultes(): Collection
{
return $this->adultes;
}
public function addAdultes(self $adulte): self
{
if (!$this->adultes->contains($adulte)) {
$this->adultes[] = $adulte;
$adulte->setConseille($this);
}
return $this;
}
public function removeAdulte(self $adulte): self
{
if ($this->adultes->contains($adulte)) {
$this->adultes->removeElement($adulte);
// set the owning side to null (unless already changed)
if ($adulte->getConseille() === $this) {
$adulte->setConseille(null);
}
}
return $this;
}
/************************/
public function getFullName(){
return $this->firstName .' '.$this->name;
}
public function getClasse(): ?string
{
return $this->classe;
}
public function setClasse(?string $classe): self
{
$this->classe = $classe;
return $this;
}
public function getResetToken(): ?string
{
return $this->reset_token;
}
public function setResetToken(?string $reset_token): self
{
$this->reset_token = $reset_token;
return $this;
}
public function getInstitution(): ?Institution
{
return $this->institution;
}
public function setInstitution(?Institution $institution): self
{
$this->institution = $institution;
return $this;
}
/**
* @return Collection|Institution[]
*/
public function getListInstitutions(): Collection
{
return $this->listInstitutions;
}
public function addListInstitution(Institution $listInstitution): self
{
if (!$this->listInstitutions->contains($listInstitution)) {
$this->listInstitutions[] = $listInstitution;
}
return $this;
}
public function removeListInstitution(Institution $listInstitution): self
{
if ($this->listInstitutions->contains($listInstitution)) {
$this->listInstitutions->removeElement($listInstitution);
}
return $this;
}
public function getBilanStepProf(): ?int
{
return $this->bilanStepProf;
}
public function setBilanStepProf(?int $bilanStepProf): self
{
$this->bilanStepProf = $bilanStepProf;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): self
{
$this->role = $role;
return $this;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
public function getMetier(): ?string
{
return $this->metier;
}
public function setMetier(?string $metier): self
{
$this->metier = $metier;
return $this;
}
public function getMustBeMentored(): ?bool
{
return $this->mustBeMentored;
}
public function setMustBeMentored(?bool $mustBeMentored): self
{
$this->mustBeMentored = $mustBeMentored;
return $this;
}
public function getHasMentor(): ?bool
{
return $this->hasMentor;
}
public function setHasMentor(?bool $hasMentor): self
{
$this->hasMentor = $hasMentor;
return $this;
}
public function getCodePostal(): ?int
{
return $this->codePostal;
}
public function setCodePostal(?int $codePostal): self
{
$this->codePostal = $codePostal;
return $this;
}
/**
* @return Collection|Institution[]
*/
public function getExp(): Collection
{
return $this->exp;
}
public function addExp(Institution $exp): self
{
if (!$this->exp->contains($exp)) {
$this->exp[] = $exp;
$exp->setExp($this);
}
return $this;
}
public function removeExp(Institution $exp): self
{
if ($this->exp->contains($exp)) {
$this->exp->removeElement($exp);
// set the owning side to null (unless already changed)
if ($exp->getExp() === $this) {
$exp->setExp(null);
}
}
return $this;
}
public function __call($name, $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
}