<?php
namespace App\Entity;
use App\Repository\UserRepository;
use DateTimeInterface;
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;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity("username")
* @UniqueEntity("email", ignoreNull=true)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private ?string $username = null;
/**
* @ORM\Column(type="json")
* @Assert\NotNull()
*/
private array $roles = [];
/**
* @var string|null The hashed password
* @ORM\Column(type="string")
*/
private ?string $password;
/**
* @Assert\NotNull(groups={"create"})
* @Assert\Length(min=8, max=4096)
*/
private ?string $rawPassword = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur", "drci", "girci", "other"})
* @Assert\Blank(groups={"expert"})
*/
private ?string $email;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private ?string $title;
/**
* @ORM\Column(type="string", length=10, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $civility;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $firstname;
/**
* @ORM\Column(type="string", length=25, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $phone;
/**
* @ORM\ManyToOne(targetEntity=Drci::class)
* @Assert\NotNull(groups={"porteur", "drci"})
*/
private ?Drci $drci;
/**
* @ORM\ManyToOne(targetEntity=Girci::class)
* @Assert\NotNull(groups={"girci"})
*/
private ?Girci $girci;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $service;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $street;
/**
* @ORM\Column(type="string", length=10, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $postalCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotNull(groups={"porteur"})
*/
private ?string $city;
/**
* @ORM\OneToMany(targetEntity=Project::class, mappedBy="author")
*/
private $projects;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLoginDate;
/**
* @ORM\Column(type="datetime")
*/
private $creationDate;
/**
* @ORM\OneToMany(targetEntity=UserProject::class, mappedBy="user")
*/
private $userProjects;
/**
* @ORM\Column(type="boolean")
*/
private $enabled;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
public function __construct()
{
$this->projects = new ArrayCollection();
$this->userProjects = new ArrayCollection();
$this->enabled = false;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return $this->username;
}
/**
* @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($role): self
{
$role = strtoupper($role);
if ($role === 'ROLE_USER') {
return $this;
}
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function removeRole($role): self
{
if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
public function hasRole(string $role)
{
if (in_array($role, $this->roles, true)) {
return true;
}
return false;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getRawPassword(): ?string
{
return $this->rawPassword;
}
public function setRawPassword(string $rawPassword): self
{
$this->rawPassword = $rawPassword;
$this->password = null;
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->rawPassword = null;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getDrci(): ?Drci
{
return $this->drci;
}
public function setDrci(?Drci $drci): self
{
$this->drci = $drci;
return $this;
}
public function getGirci(): ?Girci
{
return $this->girci;
}
public function setGirci(?Girci $girci): self
{
$this->girci = $girci;
return $this;
}
public function getService(): ?string
{
return $this->service;
}
public function setService(?string $service): self
{
$this->service = $service;
return $this;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(?string $street): self
{
$this->street = $street;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
/**
* @return Collection|Project[]
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function addProject(Project $project): self
{
if (!$this->projects->contains($project)) {
$this->projects[] = $project;
$project->setAuthor($this);
}
return $this;
}
public function removeProject(Project $project): self
{
if ($this->projects->removeElement($project)) {
// set the owning side to null (unless already changed)
if ($project->getAuthor() === $this) {
$project->setAuthor(null);
}
}
return $this;
}
public function getLastLoginDate(): ?DateTimeInterface
{
return $this->lastLoginDate;
}
public function setLastLoginDate(?DateTimeInterface $lastLoginDate): self
{
$this->lastLoginDate = $lastLoginDate;
return $this;
}
public function getCreationDate(): ?DateTimeInterface
{
return $this->creationDate;
}
public function setCreationDate(DateTimeInterface $creationDate): self
{
$this->creationDate = $creationDate;
return $this;
}
/**
* @return Collection|UserProject[]
*/
public function getUserProjects(): Collection
{
return $this->userProjects;
}
public function addUserProject(UserProject $userProject) {
if (!$this->userProjects->contains($userProject)) {
$this->userProjects[] = $userProject;
$userProject->setUser($this);
}
return $this;
}
public function removeUserProject(UserProject $userproject): self
{
if ($this->userProjects->removeElement($userproject)) {
// set the owning side to null (unless already changed)
if ($userproject->getUser() === $this) {
$userproject->setUser(null);
}
}
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
}