<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Controller\ResetRandomPasswordController;
use App\Controller\ResetPasswordController;
use App\Controller\ResetPasswordRequestController;
use App\Controller\UpdateUserCvController;
use App\Controller\UpdateUserPhotoController;
use Symfony\Component\Validator\Constraints as Assert;
use App\Billing\Model\BillablePartyInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[Vich\Uploadable]
class User implements UserInterface, PasswordAuthenticatedUserInterface, BillablePartyInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read:collection:user', 'read:item:user'])]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
#[Assert\NotBlank(message: "Le champ ne peut pas être vide.")]
#[Groups(['write:collection:resetpassword', 'read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $username = null;
#[ORM\Column]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $resetPasswordToken = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $civilite = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $cin = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: "Le champ ne peut pas être vide.")]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $nom = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: "Le champ ne peut pas être vide.")]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $prenom = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?\DateTimeInterface $dateNaissance = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $adresse = null;
#[ORM\Column(nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?int $codePostal = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $ville = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $tel = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $fax = null;
#[ORM\Column(nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?int $etatActivation = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $niveau = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $specialite = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $experience = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $type = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $diplome = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $institution = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $poste = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:collection:user', 'write:collection:user', 'read:item:user', 'put:item:user'])]
private ?string $nationnalite = null;
#[ORM\OneToMany(mappedBy: 'formateur', targetEntity: Engagement::class)]
private Collection $engagements;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Organization $organization = null;
#[ORM\OneToMany(mappedBy: 'candidat', targetEntity: Inscription::class)]
private Collection $inscriptions;
#[ORM\Column(length: 255, nullable: true)]
private ?string $cv = null;
#[Vich\UploadableField(mapping: 'usercv', fileNameProperty: 'cv')]
public $cvFile;
#[ORM\Column(length: 255, nullable: true)]
private ?string $photoDeProfil = null;
#[Vich\UploadableField(mapping: 'userphoto', fileNameProperty: 'photoDeProfil')]
public ?File $photoDeProfilFile = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $updatedAt = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Certificat::class)]
private Collection $certificats;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ServiceUsage::class)]
private Collection $serviceUsages;
public function __construct()
{
$this->engagements = new ArrayCollection();
$this->inscriptions = new ArrayCollection();
$this->certificats = new ArrayCollection();
$this->serviceUsages = new ArrayCollection();
}
public function __toString()
{
return $this->email;
}
public function getId(): ?int
{
return $this->id;
}
public function setCvFile(File $cvFile = null)
{
$this->cvFile = $cvFile;
if (null !== $cvFile) {
$this->updatedAt = new \Datetime();
}
}
public function getCvFile()
{
return $this->cvFile;
}
public function setPhotoDeProfilFile(File $photoDeProfilFile = null)
{
$this->photoDeProfilFile = $photoDeProfilFile;
if (null !== $photoDeProfilFile) {
$this->updatedAt = new \Datetime();
}
}
public function getPhotoDeProfilFile()
{
return $this->photoDeProfilFile;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
public function setUsername(string $username): self
{
$this->email = $username;
$this->username = $username;
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;
// 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;
}
/**
* Get the value of plainPassword
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* Set the value of plainPassword
*
* @return self
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
return $this;
}
public function getResetPasswordToken(): ?string
{
return $this->resetPasswordToken;
}
public function setResetPasswordToken(?string $resetPasswordToken): self
{
$this->resetPasswordToken = $resetPasswordToken;
return $this;
}
public function getCivilite(): ?string
{
return $this->civilite;
}
public function setCivilite(?string $civilite): self
{
$this->civilite = $civilite;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(?string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(?string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getDateNaissance(): ?\DateTimeInterface
{
return $this->dateNaissance;
}
public function setDateNaissance(?\DateTimeInterface $dateNaissance): self
{
$this->dateNaissance = $dateNaissance;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getCodePostal(): ?int
{
return $this->codePostal;
}
public function setCodePostal(?int $codePostal): self
{
$this->codePostal = $codePostal;
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(?string $ville): self
{
$this->ville = $ville;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(?string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getEtatActivation(): ?int
{
return $this->etatActivation;
}
public function setEtatActivation(?int $etatActivation): self
{
$this->etatActivation = $etatActivation;
return $this;
}
public function getNiveau(): ?string
{
return $this->niveau;
}
public function setNiveau(?string $niveau): self
{
$this->niveau = $niveau;
return $this;
}
public function getSpecialite(): ?string
{
return $this->specialite;
}
public function setSpecialite(?string $specialite): self
{
$this->specialite = $specialite;
return $this;
}
public function getExperience(): ?string
{
return $this->experience;
}
public function setExperience(?string $experience): self
{
$this->experience = $experience;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getDiplome(): ?string
{
return $this->diplome;
}
public function setDiplome(?string $diplome): self
{
$this->diplome = $diplome;
return $this;
}
public function getInstitution(): ?string
{
return $this->institution;
}
public function setInstitution(?string $institution): self
{
$this->institution = $institution;
return $this;
}
public function getPoste(): ?string
{
return $this->poste;
}
public function setPoste(?string $poste): self
{
$this->poste = $poste;
return $this;
}
public function getNationnalite(): ?string
{
return $this->nationnalite;
}
public function setNationnalite(?string $nationnalite): self
{
$this->nationnalite = $nationnalite;
return $this;
}
/**
* @return Collection<int, Engagement>
*/
public function getEngagements(): Collection
{
return $this->engagements;
}
public function addEngagement(Engagement $engagement): self
{
if (!$this->engagements->contains($engagement)) {
$this->engagements->add($engagement);
$engagement->setFormateur($this);
}
return $this;
}
public function removeEngagement(Engagement $engagement): self
{
if ($this->engagements->removeElement($engagement)) {
// set the owning side to null (unless already changed)
if ($engagement->getFormateur() === $this) {
$engagement->setFormateur(null);
}
}
return $this;
}
/**
* @return Collection<int, Inscription>
*/
public function getInscriptions(): Collection
{
return $this->inscriptions;
}
public function addInscription(Inscription $inscription): self
{
if (!$this->inscriptions->contains($inscription)) {
$this->inscriptions->add($inscription);
$inscription->setCandidat($this);
}
return $this;
}
public function removeInscription(Inscription $inscription): self
{
if ($this->inscriptions->removeElement($inscription)) {
// set the owning side to null (unless already changed)
if ($inscription->getCandidat() === $this) {
$inscription->setCandidat(null);
}
}
return $this;
}
public function getCv(): ?string
{
return $this->cv;
}
public function setCv(?string $cv): self
{
$this->cv = $cv;
return $this;
}
public function getPhotoDeProfil(): ?string
{
return $this->photoDeProfil;
}
public function setPhotoDeProfil(?string $photoDeProfil): self
{
$this->photoDeProfil = $photoDeProfil;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Certificat>
*/
public function getCertificats(): Collection
{
return $this->certificats;
}
public function addCertificat(Certificat $certificat): self
{
if (!$this->certificats->contains($certificat)) {
$this->certificats->add($certificat);
$certificat->setUser($this);
}
return $this;
}
public function removeCertificat(Certificat $certificat): self
{
if ($this->certificats->removeElement($certificat)) {
// set the owning side to null (unless already changed)
if ($certificat->getUser() === $this) {
$certificat->setUser(null);
}
}
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
$this->username = $email;
return $this;
}
public function getCin(): ?string
{
return $this->cin;
}
public function setCin(?string $cin): static
{
$this->cin = $cin;
return $this;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): static
{
$this->organization = $organization;
return $this;
}
// BillablePartyInterface implementation
public function getBillingName(): string
{
return $this->prenom . ' ' . $this->nom;
}
public function getBillingAddress(): ?string
{
$address = $this->adresse;
if ($this->ville) {
$address .= ', ' . $this->ville;
}
if ($this->codePostal) {
$address .= ' ' . $this->codePostal;
}
return $address;
}
public function getTaxId(): ?string
{
// For individual users, this might be null unless they are independent contractors
// We could use CIN or matriculeFiscaleOrganisation if relevant, but let's keep it simple for now
return null;
}
public function getBillingEmail(): ?string
{
return $this->email;
}
}