<?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\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @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="string", length=255)
*/
private $roles;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $username;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $resetToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $resetTokenExpiresAt;
/**
* @ORM\ManyToMany(targetEntity=Entreprise::class, inversedBy="users")
* @ORM\JoinTable(name="user_entreprise")
*/
private $entreprises;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $isProAccessRequested = false;
public function __construct()
{
$this->entreprises = new ArrayCollection();
}
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 == "" ? 'ROLE_USER' : $this->roles;
return array_unique(explode(',', $roles));
}
public function setRoles(array $roles): self
{
$this->roles = implode(',', $roles);
return $this;
}
public function addRole(string $role): self
{
$this->roles = $this->roles . ',' . $role;
return $this;
}
public function removeRole(string $role): self
{
$this->roles = str_replace($role, '', $this->roles);
$this->roles = str_replace(',,', ',', $this->roles);
return $this;
}
public function hasRole(string $role): bool
{
return strpos($this->roles, $role) !== false;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @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 getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getResetToken(): ?string
{
return $this->resetToken;
}
public function setResetToken(?string $resetToken): self
{
$this->resetToken = $resetToken;
return $this;
}
public function getResetTokenExpiresAt(): ?\DateTimeInterface
{
return $this->resetTokenExpiresAt;
}
public function setResetTokenExpiresAt(?\DateTimeInterface $resetTokenExpiresAt): self
{
$this->resetTokenExpiresAt = $resetTokenExpiresAt;
return $this;
}
/**
* @return Collection|Entreprise[]
*/
public function getEntreprises(): Collection
{
return $this->entreprises;
}
public function addEntreprise(Entreprise $entreprise): self
{
if (!$this->entreprises->contains($entreprise)) {
$this->entreprises[] = $entreprise;
}
return $this;
}
public function removeEntreprise(Entreprise $entreprise): self
{
$this->entreprises->removeElement($entreprise);
return $this;
}
public function isProAccessRequested(): bool
{
return $this->isProAccessRequested;
}
public function setProAccessRequested(bool $isProAccessRequested): self
{
$this->isProAccessRequested = $isProAccessRequested;
return $this;
}
}