<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User
*
* @ORM\Table(name="`user`")
* @ORM\Entity
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface
{
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_BO = 'ROLE_BO';
const ROLE_ADMINISTRATIVE = 'ROLE_ADMINISTRATIVE';
const ROLE_COIFFEUR = 'ROLE_COIFFEUR';
const ROLE_TELECONSEILER = 'ROLE_TELECONSEILER';
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=180, nullable=false)
*/
private $email;
/**
* @var json
*
* @ORM\Column(name="roles", type="json", nullable=false)
*/
private $roles;
/**
* @Assert\Length(max=4096)
*/
private $plainPassword;
/**
* @ORM\OneToOne(targetEntity=Intervenant::class, inversedBy="user")
* @ORM\JoinColumn(name="intervenant_id", referencedColumnName="id", nullable=true)
*/
protected $intervenant;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
public function __toString()
{
return (string)$this->getUsername();
}
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;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return mixed
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param mixed $plainPassword
*/
public function setPlainPassword($plainPassword): void
{
$this->plainPassword = $plainPassword;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string)$this->email;
}
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
$this->plainPassword = null;
}
public function hasRole(string $role): bool
{
return in_array($role, $this->getRoles());
}
/**
* @return mixed
*/
public function getIntervenant()
{
return $this->intervenant;
}
/**
* @param mixed $intervenant
*/
public function setIntervenant($intervenant): void
{
$this->intervenant = $intervenant;
}
}