<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="Users")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $nom;
/**
* @ORM\Column(type="string", length=255)
*/
private $prenom;
/**
* @ORM\Column(type="string", length=15)
*/
private $tel;
/**
* @ORM\Column(type="integer")
*/
private $civilite;
/**
* @ORM\Column(type="boolean")
*/
private $status;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated_at;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Pays", inversedBy="users")
*/
private $pays;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Loginattemp", mappedBy="user", orphanRemoval=true)
*/
private $loginattemps;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Tracking", mappedBy="user")
*/
private $trackings;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Evenement", mappedBy="user")
*/
private $evenements;
/**
* @ORM\OneToMany(targetEntity="App\Entity\News", mappedBy="user")
*/
private $news;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Formation", mappedBy="user", orphanRemoval=true)
*/
private $formations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ChapitreFormation", mappedBy="user")
*/
private $chapitresFormation;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FichierFormation", mappedBy="user")
*/
private $fichierFormations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Video", mappedBy="user")
*/
private $videos;
/**
* @ORM\OneToMany(targetEntity=ResetPassword::class, mappedBy="user")
*/
private $resetPasswords;
/**
* @ORM\OneToMany(targetEntity=NewsletterTypeUsers::class, mappedBy="user", orphanRemoval=true)
*/
private $newsletterTypeUsers;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
/**
* @ORM\OneToMany(targetEntity=Package::class, mappedBy="user")
*/
private $packages;
/**
* @ORM\OneToMany(targetEntity=Souscription::class, mappedBy="user", orphanRemoval=true)
*/
private $souscriptions;
/**
* @ORM\OneToMany(targetEntity=Facture::class, mappedBy="user")
*/
private $factures;
/**
* @ORM\OneToMany(targetEntity=UserSubscription::class, mappedBy="user")
*/
private $userSubscriptions;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $profil;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $societe;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $categorie;
/**
* @ORM\OneToMany(targetEntity=Update::class, mappedBy="user")
*/
private $updates;
/**
* @ORM\OneToMany(targetEntity=UserBookmark::class, mappedBy="user", orphanRemoval=true)
*/
private $bookmarks;
const civilites = ['M','Mme','Mlle'],
civilites_long =['Monsieur','Madame','Mademoiselle'];
/**
* User constructor. setting status to true
*/
function __construct()
{
$this->status=true;
$this->roles = ['ROLE_USER'];
$this->created_at=new \DateTime();
$this->loginattemps = new ArrayCollection();
$this->trackings = new ArrayCollection();
$this->evenements = new ArrayCollection();
$this->news = new ArrayCollection();
$this->formations = new ArrayCollection();
$this->chapitresFormation = new ArrayCollection();
$this->fichierFormations = new ArrayCollection();
$this->videos = new ArrayCollection();
$this->resetPasswords = new ArrayCollection();
$this->newsletterTypeUsers = new ArrayCollection();
$this->packages = new ArrayCollection();
$this->souscriptions = new ArrayCollection();
$this->factures = new ArrayCollection();
$this->userSubscriptions = new ArrayCollection();
$this->updates = new ArrayCollection();
$this->bookmarks = new ArrayCollection();
}
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 getUsername(): string
// public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getroles(): array
{
$roles=$this->roles;
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function getFullRole(): string
{
if(in_array('ROLE_SUPER_ADMIN',$this->roles)){
return "Super Admin";
}else if(in_array('ROLE_TECH',$this->roles)){
return "Technicien";
}else if(in_array('ROLE_ADMIN',$this->roles)){
return "Editeur";
}else return "Membre";
}
public function setroles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*
* @return String
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
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 getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getCivilite(): ?int
{
return $this->civilite;
}
public function getFullCivilite(): ?string
{
return self::civilites[$this->civilite];
}
public function getFullCiviliteLong(): ?string
{
return self::civilites_long[$this->civilite];
}
public function setCivilite(int $civilite): self
{
$this->civilite = $civilite;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
//privates ---------------<
/**
* @ORM\PrePersist
*/
private function setPreCreated(){
$this->status=true;
$this->roles = 'ROLE_USER';
$this->created_at=new \DateTime();
}
/**
* @ORM\PreUpdate
*/
private function setPreUpdate(){
$this->updated_at=new \DateTime();
}
public function getPays(): ?Pays
{
return $this->pays;
}
public function setPays(?Pays $pays): self
{
$this->pays = $pays;
return $this;
}
/**
* @return Collection|Loginattemp[]
*/
public function getLoginattemps(): Collection
{
return $this->loginattemps;
}
public function addLoginattemp(Loginattemp $loginattemp): self
{
if (!$this->loginattemps->contains($loginattemp)) {
$this->loginattemps[] = $loginattemp;
$loginattemp->setUser($this);
}
return $this;
}
public function removeLoginattemp(Loginattemp $loginattemp): self
{
if ($this->loginattemps->contains($loginattemp)) {
$this->loginattemps->removeElement($loginattemp);
// set the owning side to null (unless already changed)
if ($loginattemp->getUser() === $this) {
$loginattemp->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Tracking[]
*/
public function getTrackings(): Collection
{
return $this->trackings;
}
public function addTracking(Tracking $tracking): self
{
if (!$this->trackings->contains($tracking)) {
$this->trackings[] = $tracking;
$tracking->setUser($this);
}
return $this;
}
public function removeTracking(Tracking $tracking): self
{
if ($this->trackings->contains($tracking)) {
$this->trackings->removeElement($tracking);
// set the owning side to null (unless already changed)
if ($tracking->getUser() === $this) {
$tracking->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Evenement[]
*/
public function getEvenements(): Collection
{
return $this->evenements;
}
public function addEvenement(Evenement $evenement): self
{
if (!$this->evenements->contains($evenement)) {
$this->evenements[] = $evenement;
$evenement->setUser($this);
}
return $this;
}
public function removeEvenement(Evenement $evenement): self
{
if ($this->evenements->contains($evenement)) {
$this->evenements->removeElement($evenement);
// set the owning side to null (unless already changed)
if ($evenement->getUser() === $this) {
$evenement->setUser(null);
}
}
return $this;
}
/**
* @return Collection|News[]
*/
public function getNews(): Collection
{
return $this->news;
}
public function addNews(News $news): self
{
if (!$this->news->contains($news)) {
$this->news[] = $news;
$news->setUser($this);
}
return $this;
}
public function removeNews(News $news): self
{
if ($this->news->contains($news)) {
$this->news->removeElement($news);
// set the owning side to null (unless already changed)
if ($news->getUser() === $this) {
$news->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Formation[]
*/
public function getFormations(): Collection
{
return $this->formations;
}
public function addFormation(Formation $formation): self
{
if (!$this->formations->contains($formation)) {
$this->formations[] = $formation;
$formation->setUser($this);
}
return $this;
}
public function removeFormation(Formation $formation): self
{
if ($this->formations->contains($formation)) {
$this->formations->removeElement($formation);
// set the owning side to null (unless already changed)
if ($formation->getUser() === $this) {
$formation->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ChapitreFormation[]
*/
public function getChapitresFormation(): Collection
{
return $this->chapitresFormation;
}
public function addChapitresFormation(ChapitreFormation $chapitresFormation): self
{
if (!$this->chapitresFormation->contains($chapitresFormation)) {
$this->chapitresFormation[] = $chapitresFormation;
$chapitresFormation->setUser($this);
}
return $this;
}
public function removeChapitresFormation(ChapitreFormation $chapitresFormation): self
{
if ($this->chapitresFormation->contains($chapitresFormation)) {
$this->chapitresFormation->removeElement($chapitresFormation);
// set the owning side to null (unless already changed)
if ($chapitresFormation->getUser() === $this) {
$chapitresFormation->setUser(null);
}
}
return $this;
}
/**
* @return Collection|FichierFormation[]
*/
public function getFichierFormations(): Collection
{
return $this->fichierFormations;
}
public function addFichierFormation(FichierFormation $fichierFormation): self
{
if (!$this->fichierFormations->contains($fichierFormation)) {
$this->fichierFormations[] = $fichierFormation;
$fichierFormation->setUser($this);
}
return $this;
}
public function removeFichierFormation(FichierFormation $fichierFormation): self
{
if ($this->fichierFormations->contains($fichierFormation)) {
$this->fichierFormations->removeElement($fichierFormation);
// set the owning side to null (unless already changed)
if ($fichierFormation->getUser() === $this) {
$fichierFormation->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Video[]
*/
public function getVideos(): Collection
{
return $this->videos;
}
public function addVideo(Video $video): self
{
if (!$this->videos->contains($video)) {
$this->videos[] = $video;
$video->setUser($this);
}
return $this;
}
public function removeVideo(Video $video): self
{
if ($this->videos->contains($video)) {
$this->videos->removeElement($video);
// set the owning side to null (unless already changed)
if ($video->getUser() === $this) {
$video->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ResetPassword[]
*/
public function getResetPasswords(): Collection
{
return $this->resetPasswords;
}
public function addResetPassword(ResetPassword $resetPassword): self
{
if (!$this->resetPasswords->contains($resetPassword)) {
$this->resetPasswords[] = $resetPassword;
$resetPassword->setUser($this);
}
return $this;
}
public function removeResetPassword(ResetPassword $resetPassword): self
{
if ($this->resetPasswords->contains($resetPassword)) {
$this->resetPasswords->removeElement($resetPassword);
// set the owning side to null (unless already changed)
if ($resetPassword->getUser() === $this) {
$resetPassword->setUser(null);
}
}
return $this;
}
/**
* @return Collection|NewsletterTypeUsers[]
*/
public function getNewsletterTypeUsers(): Collection
{
return $this->newsletterTypeUsers;
}
public function addNewsletterTypeUser(NewsletterTypeUsers $newsletterTypeUser): self
{
if (!$this->newsletterTypeUsers->contains($newsletterTypeUser)) {
$this->newsletterTypeUsers[] = $newsletterTypeUser;
$newsletterTypeUser->setUser($this);
}
return $this;
}
public function removeNewsletterTypeUser(NewsletterTypeUsers $newsletterTypeUser): self
{
if ($this->newsletterTypeUsers->contains($newsletterTypeUser)) {
$this->newsletterTypeUsers->removeElement($newsletterTypeUser);
// set the owning side to null (unless already changed)
if ($newsletterTypeUser->getUser() === $this) {
$newsletterTypeUser->setUser(null);
}
}
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection|Package[]
*/
public function getPackages(): Collection
{
return $this->packages;
}
public function addPackage(Package $package): self
{
if (!$this->packages->contains($package)) {
$this->packages[] = $package;
$package->setUser($this);
}
return $this;
}
public function removePackage(Package $package): self
{
if ($this->packages->contains($package)) {
$this->packages->removeElement($package);
// set the owning side to null (unless already changed)
if ($package->getUser() === $this) {
$package->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Souscription[]
*/
public function getSouscriptions(): Collection
{
return $this->souscriptions;
}
public function addSouscription(Souscription $souscription): self
{
if (!$this->souscriptions->contains($souscription)) {
$this->souscriptions[] = $souscription;
$souscription->setUser($this);
}
return $this;
}
public function removeSouscription(Souscription $souscription): self
{
if ($this->souscriptions->contains($souscription)) {
$this->souscriptions->removeElement($souscription);
// set the owning side to null (unless already changed)
if ($souscription->getUser() === $this) {
$souscription->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Facture[]
*/
public function getFactures(): Collection
{
return $this->factures;
}
public function addFacture(Facture $facture): self
{
if (!$this->factures->contains($facture)) {
$this->factures[] = $facture;
$facture->setUser($this);
}
return $this;
}
public function removeFacture(Facture $facture): self
{
if ($this->factures->contains($facture)) {
$this->factures->removeElement($facture);
// set the owning side to null (unless already changed)
if ($facture->getUser() === $this) {
$facture->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserSubscription[]
*/
public function getUserSubscriptions(): Collection
{
return $this->userSubscriptions;
}
public function addUserSubscription(UserSubscription $userSubscription): self
{
if (!$this->userSubscriptions->contains($userSubscription)) {
$this->userSubscriptions[] = $userSubscription;
$userSubscription->setUser($this);
}
return $this;
}
public function removeUserSubscription(UserSubscription $userSubscription): self
{
if ($this->userSubscriptions->contains($userSubscription)) {
$this->userSubscriptions->removeElement($userSubscription);
// set the owning side to null (unless already changed)
if ($userSubscription->getUser() === $this) {
$userSubscription->setUser(null);
}
}
return $this;
}
public function getProfil(): ?string
{
return $this->profil;
}
public function setProfil(?string $profil): self
{
$this->profil = $profil;
return $this;
}
public function getSociete(): ?string
{
return $this->societe;
}
public function setSociete(?string $societe): self
{
$this->societe = $societe;
return $this;
}
public function getCategorie(): ?int
{
return $this->categorie;
}
public function setCategorie(?int $categorie): self
{
$this->categorie = $categorie;
return $this;
}
/**
* @return Collection|Update[]
*/
public function getUpdates(): Collection
{
return $this->updates;
}
public function addUpdate(Update $update): self
{
if (!$this->updates->contains($update)) {
$this->updates[] = $update;
$update->setUser($this);
}
return $this;
}
public function removeUpdate(Update $update): self
{
if ($this->updates->removeElement($update)) {
// set the owning side to null (unless already changed)
if ($update->getUser() === $this) {
$update->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserBookmark[]
*/
public function getBookmarks(): Collection
{
return $this->bookmarks;
}
public function addBookmark(UserBookmark $bookmark): self
{
if (!$this->bookmarks->contains($bookmark)) {
$this->bookmarks[] = $bookmark;
$bookmark->setUser($this);
}
return $this;
}
public function removeBookmark(UserBookmark $bookmark): self
{
if ($this->bookmarks->removeElement($bookmark)) {
// set the owning side to null (unless already changed)
if ($bookmark->getUser() === $this) {
$bookmark->setUser(null);
}
}
return $this;
}
}