<?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: 'Il existe déjà un compte avec cet email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const IS_VERIFIED = 1;
const IS_NOT_VERIFIED = 0;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 255)]
private ?string $phone = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255)]
private ?string $postalCode = null;
#[ORM\Column(length: 255)]
private ?string $city = null;
#[ORM\Column(length: 255)]
private ?string $company = null;
#[ORM\Column]
private ?\DateTimeImmutable $addedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updateAt = null;
#[ORM\Column]
private ?int $isActive = 1;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Project::class, orphanRemoval: true)]
private Collection $projects;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
// User entity
#[ORM\OneToMany(mappedBy: 'user', targetEntity: AccountingDocument::class, orphanRemoval: true)]
private Collection $accounting_document;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Chat::class, orphanRemoval: true)]
private Collection $chat;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Ticket::class, orphanRemoval: true)]
private Collection $ticket;
public function __construct()
{
$this->setAddedAt(new \DateTimeImmutable());
$this->projects = new ArrayCollection();
$this->accounting_document = new ArrayCollection();
$this->chat = new ArrayCollection();
$this->ticket = new ArrayCollection();
}
public function __toString(): string
{
return $this->firstName;
}
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;
}
/**
* @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 getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
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;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(string $company): self
{
$this->company = $company;
return $this;
}
public function getAddedAt(): ?\DateTimeImmutable
{
return $this->addedAt;
}
public function setAddedAt(\DateTimeImmutable $addedAt): self
{
$this->addedAt = $addedAt;
return $this;
}
public function getUpdateAt(): ?\DateTimeImmutable
{
return $this->updateAt;
}
public function setUpdateAt(?\DateTimeImmutable $updateAt): self
{
$this->updateAt = $updateAt;
return $this;
}
public function getIsActive(): ?int
{
return $this->isActive;
}
public function setIsActive(int $isActive): self
{
$this->isActive = $isActive;
return $this;
}
/**
* @return Collection<int, Project>
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function addProject(Project $project): self
{
if (!$this->projects->contains($project)) {
$this->projects->add($project);
$project->setUser($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->getUser() === $this) {
$project->setUser(null);
}
}
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getAccountingDocument(): ?AccountingDocument
{
return $this->accountingDocument;
}
public function setAccountingDocument(?AccountingDocument $accountingDocument): self
{
// unset the owning side of the relation if necessary
if ($accountingDocument === null && $this->accountingDocument !== null) {
$this->accountingDocument->setUser(null);
}
// set the owning side of the relation if necessary
if ($accountingDocument !== null && $accountingDocument->getUser() !== $this) {
$accountingDocument->setUser($this);
}
$this->accountingDocument = $accountingDocument;
return $this;
}
public function addAccountingDocument(AccountingDocument $accountingDocument): self
{
if (!$this->accounting_document->contains($accountingDocument)) {
$this->accounting_document->add($accountingDocument);
$accountingDocument->setUser($this);
}
return $this;
}
public function removeAccountingDocument(AccountingDocument $accountingDocument): self
{
if ($this->accounting_document->removeElement($accountingDocument)) {
// set the owning side to null (unless already changed)
if ($accountingDocument->getUser() === $this) {
$accountingDocument->setUser(null);
}
}
return $this;
}
public function getIdentity(): string
{
return $this->lastName . ' ' . $this->firstName;
}
/**
* @return Collection<int, Chat>
*/
public function getChat(): Collection
{
return $this->chat;
}
public function addChat(Chat $chat): self
{
if (!$this->chat->contains($chat)) {
$this->chat->add($chat);
$chat->setUser($this);
}
return $this;
}
public function removeChat(Chat $chat): self
{
if ($this->chat->removeElement($chat)) {
// set the owning side to null (unless already changed)
if ($chat->getUser() === $this) {
$chat->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Ticket>
*/
public function getTicket(): Collection
{
return $this->ticket;
}
public function addTicket(Ticket $ticket): self
{
if (!$this->ticket->contains($ticket)) {
$this->ticket->add($ticket);
$ticket->setUser($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->ticket->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getUser() === $this) {
$ticket->setUser(null);
}
}
return $this;
}
}