<?php
namespace App\Entity;
use App\Entity\Traits\EntityTrait;
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
{
use EntityTrait{
EntityTrait::__construct as private __entityConstruct;
}
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname = 'bug';
/**
* @ORM\Column(type="string", length=255)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255)
*/
private $position_in_company;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
private $plain_password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $forgot_token;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $forgot_time;
/**
* @ORM\OneToMany(targetEntity=Customer::class, mappedBy="user")
*/
private $customers;
/**
* @ORM\ManyToMany(targetEntity=Event::class, mappedBy="users")
*/
private $events;
/**
* @ORM\Column(type="string", length=255)
*/
private $agenda_color;
/**
* @ORM\ManyToOne(targetEntity=UserGroup::class, inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $userGroup;
/**
* @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
*/
private $binome;
/**
* @ORM\OneToMany(targetEntity=Chantier::class, mappedBy="user")
*/
private $chantiers;
/**
* @ORM\ManyToMany(targetEntity=Chantier::class, mappedBy="user_worker")
*/
private $worker_chantiers;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user")
*/
private $comments;
public function __construct()
{
$this->__entityConstruct();
$this->customers = new ArrayCollection();
$this->events = new ArrayCollection();
$this->chantiers = new ArrayCollection();
$this->worker_chantiers = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return mixed
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @param mixed $lastname
*/
public function setLastname($lastname): void
{
$this->lastname = $lastname;
}
/**
* @return mixed
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* @param mixed $firstname
*/
public function setFirstname($firstname): void
{
$this->firstname = $firstname;
}
/**
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param mixed $phone
*/
public function setPhone($phone): void
{
$this->phone = $phone;
}
/**
* @return mixed
*/
public function getPositionInCompany()
{
return $this->position_in_company;
}
/**
* @param mixed $position_in_company
*/
public function setPositionInCompany($position_in_company): void
{
$this->position_in_company = $position_in_company;
}
/**
* @return string|null
*/
public function getAvatar(): ?string
{
return $this->avatar;
}
/**
* @param string $avatar
* @return $this
*/
public function setAvatar(string $avatar): self
{
$this->avatar = $avatar;
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';
// Administration ou Secrétariat
if($this->getUserGroup() != null){
switch ($this->getUserGroup()->getId()) {
case 1:
$roles[] = 'ROLE_ADMIN';
$roles[] = 'ROLE_ADMINISTRATION';
break;
case 2 :
$roles[] = 'ROLE_ADMIN';
$roles[] = 'ROLE_SECRETARIAT';
break;
case 5:
$roles[] = 'ROLE_POSEUR';
break;
default:
break;
}
//if (($this->getUserGroup()->getId() == 1 || $this->getUserGroup()->getId() == 2)) {
// $roles[] = 'ROLE_ADMIN';
// if($this->getUserGroup()->getId() == 1){
// $roles[] = 'ROLE_ADMINISTRATION';
// }else if($this->getUserGroup()->getId() == 2){
// $roles[] = 'ROLE_SECRETARIAT';
// }
//}
}
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 __toString(){
return $this->getFirstname().' '.$this->getLastname();
}
public function getFullName()
{
return $this->getFirstname().' '.$this->getLastname();
}
public function getForgotToken(): ?string
{
return $this->forgot_token;
}
public function setForgotToken(?string $forgot_token): self
{
$this->forgot_token = $forgot_token;
return $this;
}
public function getForgotTime(): ?\DateTimeInterface
{
return $this->forgot_time;
}
public function setForgotTime(?\DateTimeInterface $forgot_time): self
{
$this->forgot_time = $forgot_time;
return $this;
}
/**
* @return Collection|Customer[]
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): self
{
if (!$this->customers->contains($customer)) {
$this->customers[] = $customer;
$customer->setUser($this);
}
return $this;
}
public function removeCustomer(Customer $customer): self
{
if ($this->customers->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getUser() === $this) {
$customer->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->addUser($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
$event->removeUser($this);
}
return $this;
}
public function getAgendaColor(): ?string
{
return $this->agenda_color;
}
public function setAgendaColor(string $agenda_color): self
{
$this->agenda_color = $agenda_color;
return $this;
}
public function getUserGroup(): ?UserGroup
{
return $this->userGroup;
}
public function setUserGroup(?UserGroup $userGroup): self
{
$this->userGroup = $userGroup;
return $this;
}
public function getBinome(): ?self
{
return $this->binome;
}
public function setBinome(?self $binome): self
{
$this->binome = $binome;
return $this;
}
/**
* @return Collection|Chantier[]
*/
public function getChantiers(): Collection
{
return $this->chantiers;
}
public function addChantier(Chantier $chantier): self
{
if (!$this->chantiers->contains($chantier)) {
$this->chantiers[] = $chantier;
$chantier->setUser($this);
}
return $this;
}
public function removeChantier(Chantier $chantier): self
{
if ($this->chantiers->removeElement($chantier)) {
// set the owning side to null (unless already changed)
if ($chantier->getUser() === $this) {
$chantier->setUser(null);
}
}
return $this;
}
/**
* Get the value of plain_password
*/
public function getPlainPassword()
{
return $this->plain_password;
}
/**
* Set the value of plain_password
*
* @return self
*/
public function setPlainPassword($plain_password)
{
$this->plain_password = $plain_password;
return $this;
}
/**
* @return Collection|Chantier[]
*/
public function getWorkerChantiers(): Collection
{
return $this->worker_chantiers;
}
public function addWorkerChantier(Chantier $workerChantier): self
{
if (!$this->worker_chantiers->contains($workerChantier)) {
$this->worker_chantiers[] = $workerChantier;
$workerChantier->addUserWorker($this);
}
return $this;
}
public function removeWorkerChantier(Chantier $workerChantier): self
{
if ($this->worker_chantiers->removeElement($workerChantier)) {
$workerChantier->removeUserWorker($this);
}
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setUser($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getUser() === $this) {
$comment->setUser(null);
}
}
return $this;
}
}