<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="Il existe déjà un utilisateur avec cet email")
*
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const ROLE_ADMIN = "ROLE_ADMIN";
const ROLE_DIRECTEUR = "ROLE_DIRECTEUR";
const ROLE_DIRECTEUR_ADMIN = "ROLE_DIRECTEUR_ADMIN";
const ROLE_PARENT = "ROLE_PARENT";
const ROLE_CANDIDAT = "ROLE_CANDIDAT";
const ROLE_COMPTA = "ROLE_COMPTA";
const ROLE_HR = "ROLE_HR";
const ROLE_CE = "ROLE_CE";
const ROLE_SEO = "ROLE_SEO";
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Email
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\OneToOne(targetEntity=Contact::class, inversedBy="user", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
* @Ignore()
*/
private $contact;
/**
* @ORM\OneToMany(targetEntity=ConnexionLog::class, mappedBy="user")
*/
private $connexionLogs;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActive;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $hasOptin;
/**
* @ORM\Column(type="integer")
*/
private $count;
public function __construct()
{
$this->connexionLogs = new ArrayCollection();
$this->count = 0;
}
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;
}
public function addRole(string $role):self
{
$this->roles[] = $role;
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 isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getContact(): ?Contact
{
return $this->contact;
}
public function setContact(Contact $contact): self
{
$this->contact = $contact;
return $this;
}
/**
* @return Collection|ConnexionLog[]
*/
public function getConnexionLogs(): Collection
{
return $this->connexionLogs;
}
public function addConnexionLog(ConnexionLog $connexionLog): self
{
if (!$this->connexionLogs->contains($connexionLog)) {
$this->connexionLogs[] = $connexionLog;
$connexionLog->setUser($this);
}
return $this;
}
public function removeConnexionLog(ConnexionLog $connexionLog): self
{
if ($this->connexionLogs->removeElement($connexionLog)) {
// set the owning side to null (unless already changed)
if ($connexionLog->getUser() === $this) {
$connexionLog->setUser(null);
}
}
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getHasOptin(): ?bool
{
return $this->hasOptin;
}
public function setHasOptin(?bool $isActive): self
{
$this->hasOptin = $isActive;
return $this;
}
/**
* Return only the security relevant data
*
* @return array
*/
public function __serialize(): array
{
return [
'id' => $this->id,
'email' => $this->email,
'password' => $this->password,
];
}
/**
* Restore security relevant data
*
* @param array $data
*/
public function __unserialize(array $data): void
{
$this->id = $data['id'];
$this->email = $data['email'];
$this->password = $data['password'];
}
public function getCount(): ?int
{
return $this->count;
}
public function setCount(int $count): self
{
$this->count = $count;
return $this;
}
}