<?php
namespace App\Entity;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\UserRepository;
use App\Validator\Constraints\CustomUniqueUser;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use SLLH\IsoCodesValidator\Constraints as IsoCodesAssert;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[CustomUniqueUser(
fields: ['email', 'codeAurige'],
message: 'Vous êtes déjà inscrits',
groups: ['start_registration'],
errorPath: 'email',
ignoreIfEmpty: 'password'
)]
#[Vich\Uploadable]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[Serializer\ExclusionPolicy('ALL')]
#[ORM\Table(name: 'user')]
#[ORM\Index(columns: ['compte_id'], name: 'compte_id')]
class User implements UserInterface, \Serializable
{
use TimestampableTrait;
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;
#[ORM\Column(name: 'civility', type: 'string', length: 10, nullable: true)]
#[Serializer\SerializedName('civility')]
#[Serializer\Expose]
private ?string $civility = null;
#[ORM\Column(name: 'lastname', type: 'string', length: 80, nullable: true)]
#[Assert\NotBlank(message: 'Le nom est obligatoire.', groups: ['registration'])]
#[Assert\Length(max: 80, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
#[Assert\Regex(pattern: '/^[a-zùûüÿàâæçéèêëïîôœ \-]+$/i', message: 'Le nom est incorrect.', groups: ['registration'])]
#[Serializer\SerializedName('lastname')]
#[Serializer\Expose]
private ?string $lastname = null;
#[ORM\Column(name: 'firstname', type: 'string', length: 80, nullable: true)]
#[Assert\NotBlank(message: 'Le Prénom est obligatoire.', groups: ['registration'])]
#[Assert\Regex(pattern: '/^[a-zùûüÿàâæçéèêëïîôœ \-]+$/i', message: 'Le prénom est incorrect.', groups: ['registration'])]
#[Serializer\SerializedName('firstname')]
#[Serializer\Expose]
private ?string $firstname = null;
#[ORM\Column(name: 'company_name', type: 'string', length: 255, nullable: true)]
#[Serializer\SerializedName('corporate_name')]
#[Serializer\Expose]
protected ?string $companyName = null;
#[Assert\NotBlank(message: 'Le Code Aurige est obligatoire.', groups: ['start_registration', 'login'])]
#[ORM\Column(name: 'code_aurige', type: 'string', length: 11, unique: false, nullable: false)]
protected ?string $codeAurige = null;
#[ORM\Column(name: 'phone', type: 'string', length: 255, nullable: true)]
#[Serializer\SerializedName('phone')]
#[Serializer\Expose]
protected ?string $phone = null;
#[ORM\Column(name: 'email', type: 'string', length: 50, unique: true, nullable: false)]
#[Assert\NotBlank(message: "L'adresse email est obligatoire.", groups: ['start_registration', 'login'])]
#[Assert\Email(message: "L'email est incorrect.", mode: 'strict', groups: ['start_registration', 'login'])]
#[Assert\Length(max: 50, exactMessage: 'Le nombre de caractères est trop important.', groups: ['start_registration', 'login'])]
#[Serializer\SerializedName('email')]
#[Serializer\Expose]
private ?string $email = null;
#[ORM\Column(name: 'address', type: 'string', length: 38, nullable: true)]
#[Serializer\SerializedName('address_1')]
#[Serializer\Expose]
private ?string $address = null;
#[ORM\Column(name: 'address2', type: 'string', length: 38, nullable: true)]
#[Serializer\SerializedName('address_2')]
#[Serializer\Expose]
private ?string $address2 = null;
#[ORM\Column(name: 'address3', type: 'string', length: 38, nullable: true)]
#[Serializer\SerializedName('address_3')]
#[Serializer\Expose]
private ?string $address3 = null;
#[ORM\Column(name: 'address4', type: 'string', length: 38, nullable: true)]
#[Serializer\SerializedName('address_4')]
#[Serializer\Expose]
private ?string $address4 = null;
#[ORM\Column(name: 'postal_code', type: 'string', length: 5)]
#[Serializer\SerializedName('postal_code')]
#[Serializer\Expose]
private ?string $postalCode = null;
#[ORM\Column(name: 'city', type: 'string', length: 38)]
#[Serializer\SerializedName('city')]
#[Serializer\Expose]
private ?string $city = null;
#[ORM\Column(name: 'password', type: 'string', nullable: true)]
private ?string $password = null;
private array $roles = [];
#[ORM\Column(name: 'token', type: 'string', length: 32)]
private ?string $token = null;
#[ORM\Column(name: 'docapost_created_at', type: 'datetime', nullable: true)]
protected ?\DateTime $docapostCreatedAt = null;
#[ORM\Column(name: 'opt_in_modality', type: 'boolean', nullable: true)]
private ?bool $optInModality = null;
#[ORM\Column(name: 'opt_in_modality_2', type: 'boolean', nullable: true)]
private ?bool $optInModality2 = false;
#[ORM\Column(name: 'opt_in_modality_3', type: 'boolean', nullable: true)]
private ?bool $optInModality3 = false;
#[ORM\Column(type: 'integer', unique: true)]
private ?int $compteId = null;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Calculation::class)]
private Collection $calculations;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: DocapostReturn::class, cascade: ['persist', 'remove'])]
private DocapostReturn $docapostReturn;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'L’IBAN est obligatoire', groups: ['registration'])]
#[Assert\Iban(message: "L'IBAN n'est pas correct", groups: ['registration'])]
#[Serializer\SerializedName('iban')]
#[Serializer\Expose]
private ?string $iban = null;
#[ORM\Column(type: 'string', length: 11, nullable: true)]
#[Assert\NotBlank(message: 'Le BIC est obligatoire', groups: ['registration'])]
#[Assert\Bic(message: "Le format du BIC (Bank Identifier Code) n'est pas valide.", groups: ['registration'])]
#[Serializer\SerializedName('bic')]
#[Serializer\Expose]
private ?string $bic = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $start_new_settings = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[Assert\IsTrue(message: 'Ce champ est obligatoire', groups: ['registration'])]
private ?bool $newOptInModality = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[Assert\IsTrue(message: 'Ce champ est obligatoire', groups: ['registration'])]
private ?bool $newOptInModality2 = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: MonthlyCalculation::class, orphanRemoval: true)]
#[ORM\OrderBy(['year' => 'ASC', 'month' => 'ASC'])]
private Collection $monthlyCalculations;
/**
* @IsoCodesAssert\Siren(message="Cette valeur n'est pas un code SIREN valide",groups={"registration"})
*/
#[ORM\Column(type: 'string', length: 9, nullable: true)]
#[Assert\NotBlank(message: 'N° de SIREN est obligatoire', groups: ['registration'])]
#[Serializer\SerializedName('siren')]
#[Serializer\Expose]
private ?string $SIREN = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Forme Juridique est obligatoire', groups: ['registration'])]
private ?string $formeJuridique = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\NotBlank(message: 'Montant du capital social est obligatoire', groups: ['registration'])]
private ?int $capitalSocial = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'N° RCS et Ville du Greffe est obligatoire', groups: ['registration'])]
private ?string $noRCS = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'N° TVA obligatoire.', groups: ['registration'])]
private ?string $noTVA = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Dénomination sociale est obligatoire.', groups: ['registration'])]
private ?string $newCompanyName = null;
#[ORM\Column(type: 'string', length: 38, nullable: true)]
#[Assert\NotBlank(message: "L'adresse est obligatoire.", groups: ['registration'])]
#[Assert\Length(max: 38, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
private ?string $newAddress = null;
#[ORM\Column(type: 'string', length: 38, nullable: true)]
#[Assert\Length(max: 38, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
private ?string $newAddress2 = null;
#[ORM\Column(type: 'string', length: 38, nullable: true)]
#[Assert\Length(max: 38, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
private ?string $newAddress3 = null;
#[ORM\Column(type: 'string', length: 38, nullable: true)]
#[Assert\Length(max: 38, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
private ?string $newAddress4 = null;
#[ORM\Column(type: 'string', length: 5, nullable: true)]
#[Assert\NotBlank(message: 'Le code postal est obligatoire.', groups: ['registration'])]
#[Assert\Regex(pattern: '/^[0-9]+[a-z ]*$/i', message: 'Le code postal ne semble pas être au bon format.', groups: ['registration'])]
#[Assert\Length(min: 5, max: 5, exactMessage: 'Le code postal doit être à 5 chiffres.', groups: ['registration'])]
private ?string $newPostalCode = null;
#[ORM\Column(type: 'string', length: 38, nullable: true)]
#[Assert\NotBlank(message: 'La ville est obligatoire.', groups: ['registration'])]
#[Assert\Length(max: 38, exactMessage: 'Le nombre de caractères est trop important.', groups: ['registration'])]
#[Assert\Regex(pattern: "/^[a-zùûüÿàâæçéèêëïîôœ '\\-]+\$/i", message: 'La ville est incorrecte.', groups: ['registration'])]
private ?string $newCity = null;
#[ORM\Embedded(class: EmbeddedFile::class)]
private EmbeddedFile $invoice;
#[Vich\UploadableField(mapping: 'participation_invoice', fileNameProperty: 'invoice.name', size: 'invoice.size', mimeType: 'invoice.mimeType', originalName: 'invoice.originalName', dimensions: 'invoice.dimensions')]
private ?File $invoiceFile = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotBlank(message: 'La fonction est obligatoire.', groups: ['registration'])]
private ?string $position = null;
public function __construct()
{
$this->calculations = new ArrayCollection();
$this->monthlyCalculations = new ArrayCollection();
$this->invoice = new EmbeddedFile();
}
/**
* @throws \Exception
*/
#[ORM\PrePersist]
public function prePersist(): void
{
$this->token = md5(random_bytes(20));
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updatedTimestamps(): void
{
$dateTimeNow = new \DateTime('now');
$this->setUpdatedAt($dateTimeNow);
if (null === $this->getCreatedAt()) {
$this->setCreatedAt($dateTimeNow);
}
}
public function getId(): int
{
return $this->id;
}
public function setCivility(?string $civility): static
{
$this->civility = $civility;
return $this;
}
public function getCivility(): int
{
return (int) $this->civility;
}
public function setLastname(?string $lastname): static
{
$this->lastname = $lastname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function getFullName(): string
{
return $this->firstname.' '.$this->lastname;
}
public function getUrlPassword(): ?string
{
return $this->token;
}
public function getStringCivility(): string
{
if (1 === $this->getCivility()) {
return 'Mr';
} else {
return 'Mme';
}
}
public function setFirstname(?string $firstname): static
{
$this->firstname = $firstname;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setPostalCode(?string $postalCode): static
{
$this->postalCode = $postalCode;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): static
{
$this->address = $address;
return $this;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(?string $address2): static
{
$this->address2 = $address2;
return $this;
}
public function setToken(string $token): static
{
$this->token = $token;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function getRoles(): array
{
return ['ROLE_USER'];
}
public function getPassword(): ?string
{
return $this->password;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*/
public function getSalt(): ?string
{
return null;
}
/**
* Returns the username used to authenticate the user.
*/
public function getUsername(): string
{
return $this->getUserIdentifier();
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials(): void
{
// TODO: Implement eraseCredentials() method.
}
public function setPassword(?string $password): static
{
$this->password = $password;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): void
{
$this->companyName = $companyName;
}
public function getCodeAurige(): ?string
{
return $this->codeAurige;
}
public function setCodeAurige(?string $codeAurige): static
{
$this->codeAurige = $codeAurige;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getAddress3(): ?string
{
return $this->address3;
}
public function setAddress3(?string $address3): static
{
$this->address3 = $address3;
return $this;
}
public function getAddress4(): ?string
{
return $this->address4;
}
public function setAddress4(?string $address4): static
{
$this->address4 = $address4;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): static
{
$this->city = $city;
return $this;
}
public function getDocapostCreatedAt(): ?\DateTime
{
return $this->docapostCreatedAt;
}
public function setDocapostCreatedAt(\DateTime $docapostCreatedAt): static
{
$this->docapostCreatedAt = $docapostCreatedAt;
return $this;
}
public function getOptInModality(): ?bool
{
return $this->optInModality;
}
public function setOptInModality(bool $optInModality): static
{
$this->optInModality = $optInModality;
return $this;
}
public function isOptInModality2(): ?bool
{
return $this->optInModality2;
}
public function setOptInModality2(?bool $optInModality2): static
{
$this->optInModality2 = $optInModality2;
return $this;
}
public function isOptInModality3(): ?bool
{
return $this->optInModality3;
}
public function setOptInModality3(?bool $optInModality3): static
{
$this->optInModality3 = $optInModality3;
return $this;
}
public function getWordingCivility(): string
{
if ('1' === $this->civility) {
return 'M';
}
return 'Mme';
}
public function getCompteId(): ?int
{
return $this->compteId;
}
public function setCompteId(?int $compteId): self
{
$this->compteId = $compteId;
return $this;
}
public function getCalculations(): Collection
{
return $this->calculations;
}
public function addCalculation(Calculation $calculation): self
{
if (!$this->calculations->contains($calculation)) {
$this->calculations[] = $calculation;
$calculation->setUser($this);
}
return $this;
}
public function removeCalculation(Calculation $calculation): self
{
if ($this->calculations->removeElement($calculation)) {
// set the owning side to null (unless already changed)
if ($calculation->getUser() === $this) {
$calculation->setUser(null);
}
}
return $this;
}
public function getDocapostReturn(): ?DocapostReturn
{
return $this->docapostReturn;
}
public function setDocapostReturn(DocapostReturn $docapostReturn): self
{
$this->docapostReturn = $docapostReturn;
// set the owning side of the relation if necessary
if ($docapostReturn->getUser() !== $this) {
$docapostReturn->setUser($this);
}
return $this;
}
public function getIban(): ?string
{
return $this->iban;
}
public function setIban(?string $iban): self
{
$this->iban = $iban;
return $this;
}
public function getBic(): ?string
{
return $this->bic;
}
public function setBic(?string $bic): self
{
$this->bic = $bic;
return $this;
}
public function getStartNewSettings(): ?\DateTime
{
return $this->start_new_settings;
}
public function setStartNewSettings(?\DateTime $start_new_settings): self
{
$this->start_new_settings = $start_new_settings;
return $this;
}
public function getNewOptInModality(): ?bool
{
return $this->newOptInModality;
}
public function setNewOptInModality(?bool $newOptInModality): self
{
$this->newOptInModality = $newOptInModality;
return $this;
}
public function getNewOptInModality2(): ?bool
{
return $this->newOptInModality2;
}
public function setNewOptInModality2(?bool $newOptInModality2): self
{
$this->newOptInModality2 = $newOptInModality2;
return $this;
}
public function getMonthlyCalculations(): Collection
{
return $this->monthlyCalculations;
}
public function addMonthlyCalculation(MonthlyCalculation $monthlyCalculation): self
{
if (!$this->monthlyCalculations->contains($monthlyCalculation)) {
$this->monthlyCalculations[] = $monthlyCalculation;
$monthlyCalculation->setUser($this);
}
return $this;
}
public function removeMonthlyCalculation(MonthlyCalculation $monthlyCalculation): self
{
if ($this->monthlyCalculations->removeElement($monthlyCalculation)) {
// set the owning side to null (unless already changed)
if ($monthlyCalculation->getUser() === $this) {
$monthlyCalculation->setUser(null);
}
}
return $this;
}
public function getSIREN(): ?string
{
return $this->SIREN;
}
public function setSIREN(?string $SIREN): self
{
$this->SIREN = $SIREN;
return $this;
}
public function getFormeJuridique(): ?string
{
return $this->formeJuridique;
}
public function setFormeJuridique(?string $formeJuridique): self
{
$this->formeJuridique = $formeJuridique;
return $this;
}
public function getCapitalSocial(): ?int
{
return $this->capitalSocial;
}
public function setCapitalSocial(?int $capitalSocial): self
{
$this->capitalSocial = $capitalSocial;
return $this;
}
public function getNoRCS(): ?string
{
return $this->noRCS;
}
public function setNoRCS(?string $noRCS): self
{
$this->noRCS = $noRCS;
return $this;
}
public function getNoTVA(): ?string
{
return $this->noTVA;
}
public function setNoTVA(?string $noTVA): self
{
$this->noTVA = $noTVA;
return $this;
}
public function getNewCompanyName(): ?string
{
return $this->newCompanyName;
}
public function setNewCompanyName(?string $newCompanyName): self
{
$this->newCompanyName = $newCompanyName;
return $this;
}
public function getNewAddress(): ?string
{
return $this->newAddress;
}
public function setNewAddress(?string $newAddress): self
{
$this->newAddress = $newAddress;
return $this;
}
public function getNewAddress2(): ?string
{
return $this->newAddress2;
}
public function setNewAddress2(?string $newAddress2): self
{
$this->newAddress2 = $newAddress2;
return $this;
}
public function getNewAddress3(): ?string
{
return $this->newAddress3;
}
public function setNewAddress3(?string $newAddress3): self
{
$this->newAddress3 = $newAddress3;
return $this;
}
public function getNewAddress4(): ?string
{
return $this->newAddress4;
}
public function setNewAddress4(?string $newAddress4): self
{
$this->newAddress4 = $newAddress4;
return $this;
}
public function getNewPostalCode(): ?string
{
return $this->newPostalCode;
}
public function setNewPostalCode(?string $newPostalCode): self
{
$this->newPostalCode = $newPostalCode;
return $this;
}
public function getNewCity(): ?string
{
return $this->newCity;
}
public function setNewCity(?string $newCity): self
{
$this->newCity = $newCity;
return $this;
}
public function setInvoice(EmbeddedFile $invoice): self
{
$this->invoice = $invoice;
return $this;
}
public function getInvoice(): EmbeddedFile
{
return $this->invoice;
}
public function setInvoiceFile(?File $invoice = null): static
{
$this->invoiceFile = $invoice;
if (null !== $invoice) {
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
public function getInvoiceFile(): ?File
{
return $this->invoiceFile;
}
public function serialize(): ?string
{
return serialize([$this->id, $this->email, $this->password]);
}
public function unserialize($data): void
{
[$this->id, $this->email, $this->password] = unserialize($data);
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getUserIdentifier(): string
{
return (string) $this->email;
}
}