<?php
namespace App\Entity;
use App\Entity\Actualites\Actualites;
use App\Entity\Articles\Articles;
use App\Entity\Common\IdTrait;
use App\Entity\Hotels\Hotels;
use App\Entity\Logs\Logs;
use App\Entity\Posts\Posts;
use App\Entity\Restaurants\Restaurants;
use App\Entity\Salons\Salons;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Exception;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherAwareInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @Vich\Uploadable
* @UniqueEntity("email", message="Cet utilisateur existe déjà, veuillez réessayer")
* @method string getUserIdentifier()
*/
class User implements UserInterface, PasswordHasherAwareInterface, PasswordAuthenticatedUserInterface
{
const ROLES = [
'ROLE_SUPER_ADMIN' => 'Super administrateur',
'ROLE_ADMIN' => 'Administrateur',
'ROLE_USER' => 'Utilisateur',
];
const ROLESPUBLIC = [
'ROLE_HOTELLERIE' => 'Hôtelleries',
'ROLE_RESTAURATION' => 'Restaurations',
'ROLE_AGENCEVOYAGE' => 'Agence de voyages',
'ROLE_LOISIR' => 'Loisirs',
'ROLE_TRANSPORT' => 'Transports',
];
use IdTrait;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank(message="Veuillez saisir une adresse email")
* @Assert\Email(message="Veuillez saisir un email valide")
*/
private $email;
/**
* @ORM\Column(type="array")
*/
private $roles;
/**
* @var string
*/
private $role;
/**
* @var string The hashed password
* @ORM\Column(type="string")
* @Assert\NotBlank(message="Veuillez saisir un mot de passe")
* @Assert\Length(min="6", minMessage="Votre mot de passe doit comporter au minimum 6 cataères")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Veuillez saisir un nom d'utilisateur")
*/
private $username;
/**
* @ORM\Column(type="string", length=50, nullable=true)
* @Assert\NotBlank(message="Veuillez saisir un numéro de téléphone")
*/
private $contacts;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="photos", fileNameProperty="filename")
* @var File|null
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png"},
* maxHeight=500,
* maxWidth=600,
* )
*/
private $imageFile;
/**
* @var string|null
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $filename;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $enabled;
/**
* @var DateTime $createdAt
* @ORM\Column(type="datetime")
*
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @var DateTime $updatedAt
* @ORM\Column(type="datetime", nullable=true)
*
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Actualites\Actualites", mappedBy="user")
*/
private $actualites;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank(message="Veuillez saisir votre nom de famille")
* @Assert\Length(
* min="3", minMessage="Le nom doit comporter au minimum 3 cataères",
* max="15", maxMessage="Le nom doit comporter au plus 15 cataères",
* )
*/
private $nom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank(message="Veuillez saisir votre prenom")
* @Assert\Length(
* min="3", minMessage="Le prenom doit comporter au minimum 3 cataères",
* max="100", maxMessage="Le prenom doit comporter au plus 100 cataères",
* )
*/
private $prenoms;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Logs\Logs", mappedBy="user")
*/
private $logs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Institutions", mappedBy="user")
*/
private $institutions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Actualites\Actualites", mappedBy="updatedBy")
*/
private $actualitesUpatedBy;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Brochures", mappedBy="user")
*/
private $brochures;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Articles\Articles", mappedBy="user")
*/
private $articles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Posts\Posts", mappedBy="user")
*/
private $posts;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Directions", mappedBy="user")
*/
private $directions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Partenaires", mappedBy="user")
*/
private $partenaires;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Documentations", mappedBy="user")
*/
private $documentations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Salons\Salons", mappedBy="user")
*/
private $salons;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Seminaires", mappedBy="user")
*/
private $seminaires;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Categorieacteurs", inversedBy="user")
*/
private $domaines;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Hotels\Hotels", mappedBy="user")
*/
private $hotels;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Restaurants\Restaurants", mappedBy="user")
*/
private $restaurants;
public function __construct()
{
$this->roles = ['ROLE_USER'];
$this->actualites = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->institutions = new ArrayCollection();
$this->actualitesUpatedBy = new ArrayCollection();
$this->brochures = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->directions = new ArrayCollection();
$this->partenaires = new ArrayCollection();
$this->documentations = new ArrayCollection();
$this->salons = new ArrayCollection();
$this->seminaires = new ArrayCollection();
$this->hotels = new ArrayCollection();
$this->restaurants = new ArrayCollection();
}
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 getUsername(): ?string
{
return $this->username;
}
/**
* @return string|null
*/
public function getFullname(): ?string
{
return $this->nom. ' '.$this->prenoms;
}
/**
* @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;
}
/**
* @return string
*/
public function getRole(): ?string
{
return $this->role;
}
/**
* @param string|null $role
* @return User
*/
public function setRole(?string $role): User
{
$this->role = $role;
return $this;
}
public function getRolesType(): string {
return self::ROLESPUBLIC[$this->role];
}
/**
* @see UserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt(): ?string
{
return '';
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getContacts(): ?string
{
return $this->contacts;
}
public function setContacts(?string $contacts): self
{
$this->contacts = $contacts;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return User
* @throws Exception
*/
public function setImageFile(?File $imageFile): User
{
$this->imageFile = $imageFile;
if ($this->imageFile instanceof UploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable('now');
}
return $this;
}
/**
* @return string|null
*/
public function getFilename(): ?string
{
return $this->filename;
}
/**
* @param string|null $filename
* @return User
*/
public function setFilename(?string $filename): User
{
$this->filename = $filename;
return $this;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
* @return User
*/
public function setEnabled($enabled): User
{
$this->enabled = $enabled;
return $this;
}
public function getCreatedAt(): ?DateTimeInterface
{
return $this->createdAt;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function getLastLogin(): ?DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
/**
* @return Collection|Actualites[]
*/
public function getActualites(): Collection
{
return $this->actualites;
}
/**
* @param Actualites $actualite
* @return $this
*/
public function addActualite(Actualites $actualite): self
{
if (!$this->actualites->contains($actualite)) {
$this->actualites[] = $actualite;
$actualite->setUser($this);
}
return $this;
}
public function removeActualite(Actualites $actualite): self
{
if ($this->actualites->contains($actualite)) {
$this->actualites->removeElement($actualite);
// set the owning side to null (unless already changed)
if ($actualite->getUser() === $this) {
$actualite->setUser(null);
}
}
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenoms(): ?string
{
return $this->prenoms;
}
public function setPrenoms(string $prenoms): self
{
$this->prenoms = $prenoms;
return $this;
}
/**
* @return Collection|Logs[]
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(Logs $log): self
{
if (!$this->logs->contains($log)) {
$this->logs[] = $log;
$log->setUser($this);
}
return $this;
}
public function removeLog(Logs $log): self
{
if ($this->logs->contains($log)) {
$this->logs->removeElement($log);
// set the owning side to null (unless already changed)
if ($log->getUser() === $this) {
$log->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Institutions[]
*/
public function getInstitutions(): Collection
{
return $this->institutions;
}
public function addInstitution(Institutions $institution): self
{
if (!$this->institutions->contains($institution)) {
$this->institutions[] = $institution;
$institution->setUser($this);
}
return $this;
}
public function removeInstitution(Institutions $institution): self
{
if ($this->institutions->contains($institution)) {
$this->institutions->removeElement($institution);
// set the owning side to null (unless already changed)
if ($institution->getUser() === $this) {
$institution->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Actualites[]
*/
public function getActualitesUpatedBy(): Collection
{
return $this->actualitesUpatedBy;
}
public function addActualitesUpatedBy(Actualites $actualitesUpatedBy): self
{
if (!$this->actualitesUpatedBy->contains($actualitesUpatedBy)) {
$this->actualitesUpatedBy[] = $actualitesUpatedBy;
$actualitesUpatedBy->setUpdatedBy($this);
}
return $this;
}
public function removeActualitesUpatedBy(Actualites $actualitesUpatedBy): self
{
if ($this->actualitesUpatedBy->contains($actualitesUpatedBy)) {
$this->actualitesUpatedBy->removeElement($actualitesUpatedBy);
// set the owning side to null (unless already changed)
if ($actualitesUpatedBy->getUpdatedBy() === $this) {
$actualitesUpatedBy->setUpdatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Brochures[]
*/
public function getBrochures(): Collection
{
return $this->brochures;
}
public function addBrochure(Brochures $brochure): self
{
if (!$this->brochures->contains($brochure)) {
$this->brochures[] = $brochure;
$brochure->setUser($this);
}
return $this;
}
public function removeBrochure(Brochures $brochure): self
{
if ($this->brochures->contains($brochure)) {
$this->brochures->removeElement($brochure);
// set the owning side to null (unless already changed)
if ($brochure->getUser() === $this) {
$brochure->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Articles[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Articles $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setUser($this);
}
return $this;
}
public function removeArticle(Articles $article): self
{
if ($this->articles->contains($article)) {
$this->articles->removeElement($article);
// set the owning side to null (unless already changed)
if ($article->getUser() === $this) {
$article->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Posts[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Posts $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setUser($this);
}
return $this;
}
public function removePost(Posts $post): self
{
if ($this->posts->contains($post)) {
$this->posts->removeElement($post);
// set the owning side to null (unless already changed)
if ($post->getUser() === $this) {
$post->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Directions[]
*/
public function getDirections(): Collection
{
return $this->directions;
}
public function addDirection(Directions $direction): self
{
if (!$this->directions->contains($direction)) {
$this->directions[] = $direction;
$direction->setUser($this);
}
return $this;
}
public function removeDirection(Directions $direction): self
{
if ($this->directions->contains($direction)) {
$this->directions->removeElement($direction);
// set the owning side to null (unless already changed)
if ($direction->getUser() === $this) {
$direction->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Partenaires[]
*/
public function getPartenaires(): Collection
{
return $this->partenaires;
}
public function addPartenaire(Partenaires $partenaire): self
{
if (!$this->partenaires->contains($partenaire)) {
$this->partenaires[] = $partenaire;
$partenaire->setUser($this);
}
return $this;
}
public function removePartenaire(Partenaires $partenaire): self
{
if ($this->partenaires->contains($partenaire)) {
$this->partenaires->removeElement($partenaire);
// set the owning side to null (unless already changed)
if ($partenaire->getUser() === $this) {
$partenaire->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Documentations[]
*/
public function getDocumentations(): Collection
{
return $this->documentations;
}
public function addDocumentation(Documentations $documentation): self
{
if (!$this->documentations->contains($documentation)) {
$this->documentations[] = $documentation;
$documentation->setUser($this);
}
return $this;
}
public function removeDocumentation(Documentations $documentation): self
{
if ($this->documentations->contains($documentation)) {
$this->documentations->removeElement($documentation);
// set the owning side to null (unless already changed)
if ($documentation->getUser() === $this) {
$documentation->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Salons[]
*/
public function getSalons(): Collection
{
return $this->salons;
}
public function addSalon(Salons $salon): self
{
if (!$this->salons->contains($salon)) {
$this->salons[] = $salon;
$salon->setUser($this);
}
return $this;
}
public function removeSalon(Salons $salon): self
{
if ($this->salons->contains($salon)) {
$this->salons->removeElement($salon);
// set the owning side to null (unless already changed)
if ($salon->getUser() === $this) {
$salon->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Seminaires[]
*/
public function getSeminaires(): Collection
{
return $this->seminaires;
}
public function addSeminaire(Seminaires $seminaire): self
{
if (!$this->seminaires->contains($seminaire)) {
$this->seminaires[] = $seminaire;
$seminaire->setUser($this);
}
return $this;
}
public function removeSeminaire(Seminaires $seminaire): self
{
if ($this->seminaires->contains($seminaire)) {
$this->seminaires->removeElement($seminaire);
// set the owning side to null (unless already changed)
if ($seminaire->getUser() === $this) {
$seminaire->setUser(null);
}
}
return $this;
}
public function getDomaines(): ?Categorieacteurs
{
return $this->domaines;
}
public function setDomaines(?Categorieacteurs $domaines): self
{
$this->domaines = $domaines;
return $this;
}
/**
* @return Collection|Hotels[]
*/
public function getHotels(): Collection
{
return $this->hotels;
}
public function addHotel(Hotels $hotel): self
{
if (!$this->hotels->contains($hotel)) {
$this->hotels[] = $hotel;
$hotel->setUser($this);
}
return $this;
}
public function removeHotel(Hotels $hotel): self
{
if ($this->hotels->contains($hotel)) {
$this->hotels->removeElement($hotel);
// set the owning side to null (unless already changed)
if ($hotel->getUser() === $this) {
$hotel->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Restaurants[]
*/
public function getRestaurants(): Collection
{
return $this->restaurants;
}
public function addRestaurant(Restaurants $restaurant): self
{
if (!$this->restaurants->contains($restaurant)) {
$this->restaurants[] = $restaurant;
$restaurant->setUser($this);
}
return $this;
}
public function removeRestaurant(Restaurants $restaurant): self
{
if ($this->restaurants->contains($restaurant)) {
$this->restaurants->removeElement($restaurant);
// set the owning side to null (unless already changed)
if ($restaurant->getUser() === $this) {
$restaurant->setUser(null);
}
}
return $this;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->nom. ' '. $this->prenoms;
}
public function getPasswordHasherName(): ?string
{
return null;
}
public function __call($name, $arguments): void
{
// TODO: Implement @method string getUserIdentifier()
}
}