<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[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', nullable: true)]
private $password;
#[ORM\Column(type: 'string', length: 255)]
private $nom;
#[ORM\Column(type: 'string', length: 255)]
private $prenom;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $telephone;
#[ORM\Column(type: 'date', nullable: true)]
private $arrivee;
#[ORM\Column(type: 'date', nullable: true)]
private $depart;
#[ORM\Column(type: 'boolean', nullable: true)]
private $enabled=true;
#[ORM\ManyToOne(targetEntity: Ptf::class, inversedBy: 'users')]
private $ptf;
#[ORM\ManyToOne(targetEntity: Poste::class, inversedBy: 'users')]
private $poste;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: 'datetime')]
private $created_at;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: 'datetime')]
private $updated_at;
#[ORM\Column(type: 'integer')]
private $created_by;
#[ORM\Column(type: 'integer')]
private $updated_by;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $file = 'avatars/null.png';
#[ORM\Column]
private ?bool $changepwd = true;
#[ORM\Column]
private ?bool $resetpwd = true;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Commentaire::class)]
private Collection $commentaires;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Groupe::class)]
private Collection $groupes;
public function __construct()
{
$this->commentaires = new ArrayCollection();
$this->groupes = new ArrayCollection();
}
public function __toString()
{
return $this->getPrenom()." ".$this->getNom();
}
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;
}
/**
* @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;
}
public function hasRole($role)
{
return in_array($role, $this->getRoles(), true);
}
public function addRole($role)
{
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function removeRole($role)
{
if (false !== $key = array_search($role, $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
public function removeAllRole(): self
{
foreach ($this->roles as $role) {
$this->removeRole($role);
}
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getArrivee(): ?\DateTimeInterface
{
return $this->arrivee;
}
public function setArrivee(?\DateTimeInterface $arrivee): self
{
$this->arrivee = $arrivee;
return $this;
}
public function getDepart(): ?\DateTimeInterface
{
return $this->depart;
}
public function setDepart(?\DateTimeInterface $depart): self
{
$this->depart = $depart;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getPtf(): ?Ptf
{
return $this->ptf;
}
public function setPtf(?Ptf $ptf): self
{
$this->ptf = $ptf;
return $this;
}
public function getPoste(): ?Poste
{
return $this->poste;
}
public function setPoste(?Poste $poste): self
{
$this->poste = $poste;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getCreatedBy(): ?int
{
return $this->created_by;
}
public function setCreatedBy(int $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getUpdatedBy(): ?int
{
return $this->updated_by;
}
public function setUpdatedBy(int $updated_by): self
{
$this->updated_by = $updated_by;
return $this;
}
public function getFile(): ?string
{
return $this->file;
}
public function setFile(?string $file): self
{
$this->file = $file;
return $this;
}
public function isChangepwd(): ?bool
{
return $this->changepwd;
}
public function setChangepwd(bool $changepwd): self
{
$this->changepwd = $changepwd;
return $this;
}
public function isResetpwd(): ?bool
{
return $this->resetpwd;
}
public function setResetpwd(bool $resetpwd): self
{
$this->resetpwd = $resetpwd;
return $this;
}
/**
* @return Collection<int, Commentaire>
*/
public function getCommentaires(): Collection
{
return $this->commentaires;
}
public function addCommentaire(Commentaire $commentaire): self
{
if (!$this->commentaires->contains($commentaire)) {
$this->commentaires->add($commentaire);
$commentaire->setUser($this);
}
return $this;
}
public function removeCommentaire(Commentaire $commentaire): self
{
if ($this->commentaires->removeElement($commentaire)) {
// set the owning side to null (unless already changed)
if ($commentaire->getUser() === $this) {
$commentaire->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Groupe>
*/
public function getGroupes(): Collection
{
return $this->groupes;
}
public function addGroupe(Groupe $groupe): self
{
if (!$this->groupes->contains($groupe)) {
$this->groupes->add($groupe);
$groupe->setUser($this);
}
return $this;
}
public function removeGroupe(Groupe $groupe): self
{
if ($this->groupes->removeElement($groupe)) {
// set the owning side to null (unless already changed)
if ($groupe->getUser() === $this) {
$groupe->setUser(null);
}
}
return $this;
}
}