<?php
namespace App\Entity;
use App\Repository\UserRepository;
use App\Traits\TimestampableTrait;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="Cette adresse e-mail est déjà utilisée à un autre compte !")
* @Vich\Uploadable
*/
class User implements UserInterface, \Serializable, PasswordAuthenticatedUserInterface
{
use TimestampableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Email(message="Votre adresse e-mail n'est pas correct !")
*/
protected $email;
/**
* @ORM\Column(type="json")
*/
protected $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
* @Assert\Length(min=8, minMessage="Un mot de passe doit contenir au moins 8 caractères ! ")
*/
protected $password;
/**
* @ORM\Column(type="boolean")
*/
protected $isVerified = false;
/**
* @ORM\Column(type="boolean")
*/
protected $isConnected = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $firstName;
/**
* @ORM\OneToOne(targetEntity=Company::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $company;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="images_user", fileNameProperty="image")
* @var File | null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $profession;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $companyname;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $birthday;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nationality;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $gender;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $currency;
/**
* @ORM\Column(type="json", length=255, nullable=true)
*/
private $languages = [];
/**
* @ORM\OneToMany(targetEntity=Abonnement::class, mappedBy="prestataireid", cascade={"persist", "remove"})
*/
private $abonnements;
/**
* @ORM\OneToMany(targetEntity=Avis::class, mappedBy="user")
*/
private $avis;
/**
* @ORM\OneToMany(targetEntity=Reclamationpresta::class, mappedBy="user")
*/
private $reclamationprestas;
/**
* @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="prestataireid")
*/
private $annonces;
/**
* @ORM\OneToMany(targetEntity=InfoLog::class, mappedBy="user")
*/
private $infologs;
/**
* @ORM\OneToMany(targetEntity=Publication::class, mappedBy="author")
*/
private $publications;
/**
* @ORM\OneToMany(targetEntity=ReclamationCustomer::class, mappedBy="user")
*/
private $reclamationCustomers;
public function __construct()
{
$this->annonces = new ArrayCollection();
$this->abonnements = new ArrayCollection();
$this->avis = new ArrayCollection();
$this->reclamationprestas = new ArrayCollection();
$this->infologs = new ArrayCollection();
$this->publications = new ArrayCollection();
$this->reclamationCustomers = new ArrayCollection();
}
public function preUpdate()
{
$this->lastName = ucwords(strtolower($this->lastName));
$this->firstName = ucwords(strtolower($this->firstName));
$this->email = strtolower($this->email);
}
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;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole($role)
{
$role = strtoupper($role);
$roles = $this->getRoles();
if ($role === '') {
return $this;
}
if (!in_array($role, $roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function hasRole($role)
{
if (in_array($role, $this->roles)) {
return true;
}
return false;
}
public function removeRole($role)
{
if ($this->hasRole($role)) {
unset($this->roles[array_search($role, $this->roles)]);
}
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return bool
*/
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
/**
* @param bool $isVerified
*/
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return bool
*/
public function getIsConnected(): ?bool
{
return $this->isConnected;
}
/**
* @param bool $isConnected
*/
public function setIsConnected(bool $isConnected): self
{
$this->isConnected = $isConnected;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getSalt()
{
return null;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername()
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
public function unserialize($serialized)
{
list(
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$this->updatedAt = new \DateTime('now');
}
}
public function getImageFile()
{
return $this->imageFile;
}
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 getProfession(): ?string
{
return $this->profession;
}
public function setProfession(?string $profession): self
{
$this->profession = $profession;
return $this;
}
public function getCompanyname(): ?string
{
return $this->companyname;
}
public function setCompanyname(?string $companyname): self
{
$this->companyname = $companyname;
return $this;
}
public function getNationality(): ?string
{
return $this->nationality;
}
public function setNationality(?string $nationality): self
{
$this->nationality = $nationality;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getBirthday(): ?\DateTimeInterface
{
return $this->birthday;
}
public function setBirthday(?\DateTimeInterface $birthday): self
{
$this->birthday = $birthday;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getLanguages(): ?array
{
return $this->languages;
}
public function setLanguages(?array $languages): self
{
$this->languages = $languages;
return $this;
}
/**
* @return Collection<int, Abonnement>
*/
public function getAbonnements(): Collection
{
return $this->abonnements;
}
public function addAbonnement(Abonnement $abonnement): self
{
if (!$this->abonnements->contains($abonnement)) {
$this->abonnements[] = $abonnement;
$abonnement->setPrestataireid($this);
}
return $this;
}
public function removeAbonnement(Abonnement $abonnement): self
{
if ($this->abonnements->removeElement($abonnement)) {
// set the owning side to null (unless already changed)
if ($abonnement->getPrestataireid() === $this) {
$abonnement->setPrestataireid(null);
}
}
return $this;
}
/**
* @return Collection<int, Avis>
*/
public function getAvis(): Collection
{
return $this->avis;
}
public function addAvi(Avis $avi): self
{
if (!$this->avis->contains($avi)) {
$this->avis[] = $avi;
$avi->setUser($this);
}
return $this;
}
public function removeAvi(Avis $avi): self
{
if ($this->avis->removeElement($avi)) {
// set the owning side to null (unless already changed)
if ($avi->getUser() === $this) {
$avi->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Reclamationpresta>
*/
public function getReclamationprestas(): Collection
{
return $this->reclamationprestas;
}
public function addReclamationpresta(Reclamationpresta $reclamationpresta): self
{
if (!$this->reclamationprestas->contains($reclamationpresta)) {
$this->reclamationprestas[] = $reclamationpresta;
$reclamationpresta->setUser($this);
}
return $this;
}
public function removeReclamationpresta(Reclamationpresta $reclamationpresta): self
{
if ($this->reclamationprestas->removeElement($reclamationpresta)) {
// set the owning side to null (unless already changed)
if ($reclamationpresta->getUser() === $this) {
$reclamationpresta->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Infolog>
*/
public function getInfologs(): Collection
{
return $this->infologs;
}
public function addInfolog(Infolog $infolog): self
{
if (!$this->infologs->contains($infolog)) {
$this->infologs->add($infolog);
$infolog->setUser($this);
}
return $this;
}
public function removeInfolog(Infolog $infolog): self
{
if ($this->infologs->removeElement($infolog)) {
// set the owning side to null (unless already changed)
if ($infolog->getUser() === $this) {
$infolog->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Publication>
*/
public function getPublications(): Collection
{
return $this->publications;
}
public function addPublication(Publication $publication): self
{
if (!$this->publications->contains($publication)) {
$this->publications[] = $publication;
$publication->setAuthor($this);
}
return $this;
}
public function removePublication(Publication $publication): self
{
if ($this->publications->removeElement($publication)) {
// set the owning side to null (unless already changed)
if ($publication->getAuthor() === $this) {
$publication->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, ReclamationCustomer>
*/
public function getReclamationCustomers(): Collection
{
return $this->reclamationCustomers;
}
public function addReclamationCustomer(ReclamationCustomer $reclamationCustomer): self
{
if (!$this->reclamationCustomers->contains($reclamationCustomer)) {
$this->reclamationCustomers[] = $reclamationCustomer;
$reclamationCustomer->setUser($this);
}
return $this;
}
public function removeReclamationCustomer(ReclamationCustomer $reclamationCustomer): self
{
if ($this->reclamationCustomers->removeElement($reclamationCustomer)) {
// set the owning side to null (unless already changed)
if ($reclamationCustomer->getUser() === $this) {
$reclamationCustomer->setUser(null);
}
}
return $this;
}
}