<?php
namespace App\Entity;
use App\Repository\AssureRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Cofondateur\SocleTechniqueBundle\Annotation\CrudField;
/**
* @ORM\Entity(repositoryClass=AssureRepository::class)
* @UniqueEntity("clientCode")
* @UniqueEntity("contractNumber")
*/
class Assure implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Nom", index=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Prénom", index=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Adresse")
*/
private $adress;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Code postal")
*/
private $postalCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Ville")
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Portable")
*/
private $mobilePhone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Téléphone fixe")
*/
private $fixedPhone;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Code client", index=true)
*/
private $clientCode;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Numéro de contrat", index=true)
*/
private $contractNumber;
/**
* @ORM\Column(type="string", length=14, nullable=true)
* @CrudField(label="SIRET")
*/
private $siret;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email(message="L'adresse e-mail {{ value }} n'est pas une adresse email valide.")
* @CrudField(label="Email")
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @CrudField(label="Nouveau mot de passe")
*/
private $newPassword;
/**
* @ORM\Column(type="json")
*/
private $roles = ["ROLE_CLIENT"];
/**
* @ORM\Column(type="boolean", nullable=true)
* @CrudField(label="Compte validé", index=true)
*/
private $activate;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="client", orphanRemoval=true)
* @ORM\OrderBy({"date"="DESC"})
*/
private $documents;
/**
* @ORM\OneToMany(targetEntity=Sinister::class, mappedBy="user")
*/
private $sinisters;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->sinisters = new ArrayCollection();
}
public function __toString(): string
{
return $this->getName() . " " . $this->getFirstname() . " Code client: " . $this->getClientCode() ?? $this->getId() ?? "N/A";
}
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->clientCode;
}
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 getClientCode(): ?string
{
return $this->clientCode;
}
public function setClientCode(string $clientCode): self
{
$this->clientCode = $clientCode;
return $this;
}
public function getContractNumber(): ?string
{
return $this->contractNumber;
}
public function setContractNumber(string $contractNumber): self
{
$this->contractNumber = $contractNumber;
return $this;
}
public function getSiret(): ?string
{
return $this->siret;
}
public function setSiret(?string $siret): self
{
$this->siret = $siret;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getNewPassword(): ?string
{
return $this->newPassword;
}
public function setNewPassword(?string $password): self
{
$this->newPassword = $password;
return $this;
}
/**
* @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;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* 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 isActivate(): ?bool
{
return $this->activate;
}
public function setActivate(?bool $activate): self
{
$this->activate = $activate;
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setClient($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getClient() === $this) {
$document->setClient(null);
}
}
return $this;
}
public function getAdress(): ?string
{
return $this->adress;
}
public function setAdress(?string $adress): self
{
$this->adress = $adress;
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 getMobilePhone(): ?string
{
return $this->mobilePhone;
}
public function setMobilePhone(?string $mobilePhone): self
{
$this->mobilePhone = $mobilePhone;
return $this;
}
public function getFixedPhone(): ?string
{
return $this->fixedPhone;
}
public function setFixedPhone(string $fixedPhone): self
{
$this->fixedPhone = $fixedPhone;
return $this;
}
/**
* @return Collection<int, Sinister>
*/
public function getSinisters(): Collection
{
return $this->sinisters;
}
public function addSinister(Sinister $sinister): self
{
if (!$this->sinisters->contains($sinister)) {
$this->sinisters[] = $sinister;
$sinister->setUser($this);
}
return $this;
}
public function removeSinister(Sinister $sinister): self
{
if ($this->sinisters->removeElement($sinister)) {
// set the owning side to null (unless already changed)
if ($sinister->getUser() === $this) {
$sinister->setUser(null);
}
}
return $this;
}
}