<?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;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="Il existe déjà un compte avec cette adresse.")
*/
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 = array();
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $nom;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $prenom;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $naissance;
/**
* @ORM\Column(type="string", length=5, nullable=true)
*/
private $cp;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $telephone;
/**
* @ORM\Column(type="integer")
*/
private $isVerified = false;
/**
* @ORM\Column(type="integer", options={"comment": "0: demande en cours, 1: approuvée, 2: refusée","default":0})
*/
private $isApprouved = false;
/**
* @ORM\Column(type="boolean")
*/
private $isSuspend = false;
/**
* @ORM\OneToMany(targetEntity=UserEleveDocument::class, mappedBy="users", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $documents;
/**
* @ORM\OneToMany(targetEntity=ShopPanier::class, mappedBy="user", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $shopPaniers;
/**
* @ORM\OneToMany(targetEntity=ShopOrder::class, mappedBy="user", orphanRemoval=true, cascade={"persist", "remove"})
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $shopOrders;
/**
* @ORM\OneToMany(targetEntity=ShopUserAdress::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $shopUserAdresses;
/**
* @ORM\OneToMany(targetEntity=UserEleveCredit::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $UserEleveCredits;
/**
* @ORM\OneToMany(targetEntity=ShopOrderProductConsommation::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $ShopOrderProductConsommations;
/**
* @ORM\Column(type="string", length=255)
*/
private $ville;
/**
* @ORM\OneToMany(targetEntity=UserEnseignantDocument::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $userEnseignantDocuments;
/**
* @ORM\OneToOne(targetEntity=UserEnseignantAccountDetail::class, mappedBy="user", cascade={"persist"})
*/
private $userEnseignantAccountDetail;
/**
* @ORM\OneToMany(targetEntity=UserEnseignantAccountVehicule::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $userEnseignantAccountVehicules;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
private $dpt;
/**
* @ORM\OneToMany(targetEntity=ActiviteDisponibilite::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $activiteDisponibilites;
/**
* @ORM\OneToMany(targetEntity=ActiviteDisponibiliteInscription::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $activiteDisponibiliteInscriptions;
/**
* @ORM\OneToMany(targetEntity=UserEnseignantLieu::class, mappedBy="user", orphanRemoval=true)
*/
private $userEnseignantLieux;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reference;
/**
* @ORM\OneToMany(targetEntity=UserEleveCreditConsommation::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $userEleveCreditConsommations;
/**
* @ORM\OneToMany(targetEntity=LivretEvaluation::class, mappedBy="eleve", orphanRemoval=true, cascade={"remove"})
*/
private $livretEvaluations;
/**
* @ORM\OneToMany(targetEntity=LivretEstimation::class, mappedBy="eleve", cascade={"remove"})
*/
private $estimations;
/**
* @ORM\OneToMany(targetEntity=UserEnseignantFacture::class, mappedBy="enseignant", cascade={"remove"})
*/
private $factures;
/**
* @ORM\Column(type="string", unique=true, nullable=true)
*/
private $apiToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
public function __construct() {
$this->documents = new ArrayCollection();
$this->shopPaniers = new ArrayCollection();
$this->shopOrders = new ArrayCollection();
$this->shopUserAdresses = new ArrayCollection();
$this->UserEleveCredits = new ArrayCollection();
$this->ShopOrderProductConsommations = new ArrayCollection();
$this->userEnseignantDocuments = new ArrayCollection();
$this->userEnseignantAccountVehicules = new ArrayCollection();
$this->activiteDisponibilites = new ArrayCollection();
$this->activiteDisponibiliteInscriptions = new ArrayCollection();
$this->userEnseignantLieux = new ArrayCollection();
$this->userEleveCreditConsommations = new ArrayCollection();
$this->livretEvaluations = new ArrayCollection();
$this->estimations = new ArrayCollection();
$this->factures = 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 getUserIdentifier(): string {
return (string) $this->email;
}
/**
* @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;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string {
return $this->password;
}
public function setPassword(string $password): self {
$this->password = $password;
return $this;
}
/**
* 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 getUsername(): string {
return $this->email;
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self {
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface {
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self {
$this->updatedAt = $updatedAt;
return $this;
}
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 getNaissance(): ?\DateTimeInterface {
return $this->naissance;
}
public function setNaissance(?\DateTimeInterface $naissance): self {
$this->naissance = $naissance;
return $this;
}
public function getCp(): ?string {
return $this->cp;
}
public function setCp(?string $cp): self {
$this->cp = $cp;
return $this;
}
public function getTelephone(): ?string {
return $this->telephone;
}
public function setTelephone(?string $telephone): self {
if(strlen($telephone) > 10){
$telephone = str_replace(' ', '', $telephone);
}
if(strlen($telephone) > 10){
$telephone = str_replace('+33', '0', $telephone);
}
$this->telephone = $telephone;
return $this;
}
public function isVerified(): bool {
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self {
$this->isVerified = $isVerified;
return $this;
}
public function isApprouved(): int {
return $this->isApprouved;
}
public function isDisapproved(): bool {
return $this->isApprouved == 2;
}
public function isApproved(): bool {
return $this->isApprouved == 1;
}
public function isPending(): bool {
return $this->isApprouved == 0;
}
public function setIsApprouved(int $isApprouved): self {
$this->isApprouved = $isApprouved;
return $this;
}
public function isSuspend(): bool {
return $this->isSuspend;
}
public function setIsSuspend(bool $isSuspend): self {
$this->isSuspend = $isSuspend;
return $this;
}
/**
* @return Collection|UserEleveDocument[]
*/
public function getDocuments(): Collection {
return $this->documents;
}
public function addDocument(UserEleveDocument $document): self {
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setUsers($this);
}
return $this;
}
public function removeDocument(UserEleveDocument $document): self {
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getUsers() === $this) {
$document->setUsers(null);
}
}
return $this;
}
/**
* @return Collection|ShopPanier[]
*/
public function getShopPaniers(): Collection {
return $this->shopPaniers;
}
public function addShopPanier(ShopPanier $shopPanier): self {
if (!$this->shopPaniers->contains($shopPanier)) {
$this->shopPaniers[] = $shopPanier;
$shopPanier->setUser($this);
}
return $this;
}
public function removeShopPanier(ShopPanier $shopPanier): self {
if ($this->shopPaniers->removeElement($shopPanier)) {
// set the owning side to null (unless already changed)
if ($shopPanier->getUser() === $this) {
$shopPanier->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ShopOrder[]
*/
public function getShopOrders(): Collection {
return $this->shopOrders;
}
public function addShopOrder(ShopOrder $shopOrder): self {
if (!$this->shopOrders->contains($shopOrder)) {
$this->shopOrders[] = $shopOrder;
$shopOrder->setUser($this);
}
return $this;
}
public function removeShopOrder(ShopOrder $shopOrder): self {
if ($this->shopOrders->removeElement($shopOrder)) {
// set the owning side to null (unless already changed)
if ($shopOrder->getUser() === $this) {
$shopOrder->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ShopUserAdress[]
*/
public function getShopUserAdresses(): Collection {
return $this->shopUserAdresses;
}
public function addShopUserAdress(ShopUserAdress $shopUserAdress): self {
if (!$this->shopUserAdresses->contains($shopUserAdress)) {
$this->shopUserAdresses[] = $shopUserAdress;
$shopUserAdress->setUser($this);
}
return $this;
}
public function removeShopUserAdress(ShopUserAdress $shopUserAdress): self {
if ($this->shopUserAdresses->removeElement($shopUserAdress)) {
// set the owning side to null (unless already changed)
if ($shopUserAdress->getUser() === $this) {
$shopUserAdress->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserEleveCredit[]
*/
public function getUserEleveCredits(): Collection {
return $this->UserEleveCredits;
}
public function addUserEleveCredit(UserEleveCredit $UserEleveCredit): self {
if (!$this->UserEleveCredits->contains($UserEleveCredit)) {
$this->UserEleveCredits[] = $UserEleveCredit;
$UserEleveCredit->setUser($this);
}
return $this;
}
public function removeUserEleveCredit(UserEleveCredit $UserEleveCredit): self {
if ($this->UserEleveCredits->removeElement($UserEleveCredit)) {
// set the owning side to null (unless already changed)
if ($UserEleveCredit->getUser() === $this) {
$UserEleveCredit->setUser(null);
}
}
return $this;
}
public function getUserEleveCredit(ShopCategorie $Category): ?UserEleveCredit {
$UserEleveCredit = $this->UserEleveCredits->filter(function($element) use($Category) {
return $element->getCategorie()->getId() == $Category->getId();
})->first();
if ($UserEleveCredit) {
return $UserEleveCredit;
}
return null;
}
/**
* @return Collection|ShopOrderProductConsommation[]
*/
public function getShopOrderProductConsommations(): Collection {
return $this->ShopOrderProductConsommations;
}
public function addShopOrderProductConsommation(ShopOrderProductConsommation $ShopOrderProductConsommation): self {
if (!$this->ShopOrderProductConsommations->contains($ShopOrderProductConsommation)) {
$this->ShopOrderProductConsommations[] = $ShopOrderProductConsommation;
$ShopOrderProductConsommation->setUser($this);
}
return $this;
}
public function removeShopOrderProductConsommation(ShopOrderProductConsommation $ShopOrderProductConsommation): self {
if ($this->ShopOrderProductConsommations->removeElement($ShopOrderProductConsommation)) {
// set the owning side to null (unless already changed)
if ($ShopOrderProductConsommation->getUser() === $this) {
$ShopOrderProductConsommation->setUser(null);
}
}
return $this;
}
public function getVille(): ?string {
return $this->ville;
}
public function setVille(string $ville): self {
$this->ville = $ville;
return $this;
}
/**
* @return Collection|UserEnseignantDocument[]
*/
public function getUserEnseignantDocuments(): Collection {
return $this->userEnseignantDocuments;
}
public function addUserEnseignantDocument(UserEnseignantDocument $userEnseignantDocument): self {
if (!$this->userEnseignantDocuments->contains($userEnseignantDocument)) {
$this->userEnseignantDocuments[] = $userEnseignantDocument;
$userEnseignantDocument->setUser($this);
}
return $this;
}
public function removeUserEnseignantDocument(UserEnseignantDocument $userEnseignantDocument): self {
if ($this->userEnseignantDocuments->removeElement($userEnseignantDocument)) {
// set the owning side to null (unless already changed)
if ($userEnseignantDocument->getUser() === $this) {
$userEnseignantDocument->setUser(null);
}
}
return $this;
}
public function getDocument($doc): ?UserEnseignantDocument {
$elements = $this->getUserEnseignantDocuments()->filter(function($Document) use ($doc) {return $Document->getDoc() == $doc;});
if(count($elements))
return $elements[0];
return null;
}
/**
* @return Collection|UserEnseignantAccountVehicule[]
*/
public function getUserEnseignantAccountVehicules(): Collection {
return $this->userEnseignantAccountVehicules;
}
public function addUserEnseignantAccountVehicule(UserEnseignantAccountVehicule $userEnseignantAccountVehicule): self {
if (!$this->userEnseignantAccountVehicules->contains($userEnseignantAccountVehicule)) {
$this->userEnseignantAccountVehicules[] = $userEnseignantAccountVehicule;
$userEnseignantAccountVehicule->setUser($this);
}
return $this;
}
public function removeUserEnseignantAccountVehicule(UserEnseignantAccountVehicule $userEnseignantAccountVehicule): self {
if ($this->userEnseignantAccountVehicules->removeElement($userEnseignantAccountVehicule)) {
// set the owning side to null (unless already changed)
if ($userEnseignantAccountVehicule->getUser() === $this) {
$userEnseignantAccountVehicule->setUser(null);
}
}
return $this;
}
public function getAccountDetail(): ?UserEnseignantAccountDetail {
return $this->getUserEnseignantAccountDetail();
}
public function getUserEnseignantAccountDetail(): ?UserEnseignantAccountDetail {
return $this->userEnseignantAccountDetail;
}
public function setUserEnseignantAccountDetail(UserEnseignantAccountDetail $userEnseignantAccountDetail): self {
// set the owning side of the relation if necessary
if ($userEnseignantAccountDetail->getUser() !== $this) {
$userEnseignantAccountDetail->setUser($this);
}
$this->userEnseignantAccountDetail = $userEnseignantAccountDetail;
return $this;
}
public function getDpt(): ?string
{
return $this->dpt;
}
public function setDpt(?string $dpt): self
{
$this->dpt = $dpt;
return $this;
}
/**
* @return Collection|ActiviteDisponibilite[]
*/
public function getActiviteDisponibilites(): Collection
{
return $this->activiteDisponibilites;
}
public function addActiviteDisponibilite(ActiviteDisponibilite $activiteDisponibilite): self
{
if (!$this->activiteDisponibilites->contains($activiteDisponibilite)) {
$this->activiteDisponibilites[] = $activiteDisponibilite;
$activiteDisponibilite->setUser($this);
}
return $this;
}
public function removeActiviteDisponibilite(ActiviteDisponibilite $activiteDisponibilite): self
{
if ($this->activiteDisponibilites->removeElement($activiteDisponibilite)) {
// set the owning side to null (unless already changed)
if ($activiteDisponibilite->getUser() === $this) {
$activiteDisponibilite->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ActiviteDisponibiliteInscription[]
*/
public function getActiviteDisponibiliteInscriptions(): Collection
{
return $this->activiteDisponibiliteInscriptions;
}
public function addActiviteDisponibiliteInscription(ActiviteDisponibiliteInscription $activiteDisponibiliteInscription): self
{
if (!$this->activiteDisponibiliteInscriptions->contains($activiteDisponibiliteInscription)) {
$this->activiteDisponibiliteInscriptions[] = $activiteDisponibiliteInscription;
$activiteDisponibiliteInscription->setUser($this);
}
return $this;
}
public function removeActiviteDisponibiliteInscription(ActiviteDisponibiliteInscription $activiteDisponibiliteInscription): self
{
if ($this->activiteDisponibiliteInscriptions->removeElement($activiteDisponibiliteInscription)) {
// set the owning side to null (unless already changed)
if ($activiteDisponibiliteInscription->getUser() === $this) {
$activiteDisponibiliteInscription->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserEnseignantLieu[]
*/
public function getUserEnseignantLieux(): Collection
{
return $this->userEnseignantLieux;
}
public function addUserEnseignantLieux(UserEnseignantLieu $userEnseignantLieux): self
{
if (!$this->userEnseignantLieux->contains($userEnseignantLieux)) {
$this->userEnseignantLieux[] = $userEnseignantLieux;
$userEnseignantLieux->setUser($this);
}
return $this;
}
public function removeUserEnseignantLieux(UserEnseignantLieu $userEnseignantLieux): self
{
if ($this->userEnseignantLieux->removeElement($userEnseignantLieux)) {
// set the owning side to null (unless already changed)
if ($userEnseignantLieux->getUser() === $this) {
$userEnseignantLieux->setUser(null);
}
}
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getDir(): string {
$path = realpath(__DIR__ . '/../../');
$path .= '/var';
$path .= '/user';
$slugger = new \Symfony\Component\String\Slugger\AsciiSlugger;
$path .= '/'.$slugger->slug($this->getUserIdentifier());
return $path;
}
/**
* @return Collection<int, UserEleveCreditConsommation>
*/
public function getUserEleveCreditConsommations(): Collection
{
return $this->userEleveCreditConsommations;
}
public function addUserEleveCreditConsommation(UserEleveCreditConsommation $userEleveCreditConsommation): self
{
if (!$this->userEleveCreditConsommations->contains($userEleveCreditConsommation)) {
$this->userEleveCreditConsommations[] = $userEleveCreditConsommation;
$userEleveCreditConsommation->setUser($this);
}
return $this;
}
public function removeUserEleveCreditConsommation(UserEleveCreditConsommation $userEleveCreditConsommation): self
{
if ($this->userEleveCreditConsommations->removeElement($userEleveCreditConsommation)) {
// set the owning side to null (unless already changed)
if ($userEleveCreditConsommation->getUser() === $this) {
$userEleveCreditConsommation->setUser(null);
}
}
return $this;
}
public function isRole(string $role):bool {
return in_array('ROLE_'.strtoupper($role), $this->getRoles());
}
public function isEleve():bool {
return $this->isRole('eleve');
}
public function isProf():bool {
return $this->isRole('prof');
}
public function isAdmin():bool {
return $this->isRole('admin')||$this->isRole('super_admin');
}
public function isSalarie():bool {
if(!$this->isProf())return false;
if(!$this->getUserEnseignantAccountDetail())return false;
return $this->getUserEnseignantAccountDetail()->isSalarie();
}
public function isIndependant():bool {
if(!$this->isProf())return false;
if(!$this->getUserEnseignantAccountDetail())return false;
return $this->getUserEnseignantAccountDetail()->isIndependant();
}
public function getType() : ?string
{
if($this->isSalarie())return 'salarie';
if($this->isIndependant())return 'independant';
return null;
}
/**
* @return Collection<int, LivretEvaluation>
*/
public function getLivretEvaluations(): Collection
{
return $this->livretEvaluations;
}
public function addLivretEvaluation(LivretEvaluation $livretEvaluation): self
{
if (!$this->livretEvaluations->contains($livretEvaluation)) {
$this->livretEvaluations[] = $livretEvaluation;
$livretEvaluation->setEleve($this);
}
return $this;
}
public function removeLivretEvaluation(LivretEvaluation $livretEvaluation): self
{
if ($this->livretEvaluations->removeElement($livretEvaluation)) {
// set the owning side to null (unless already changed)
if ($livretEvaluation->getEleve() === $this) {
$livretEvaluation->setEleve(null);
}
}
return $this;
}
/**
* @return Collection<int, LivretEstimation>
*/
public function getEstimations(): Collection
{
return $this->estimations;
}
public function addEstimation(LivretEstimation $estimation): self
{
if (!$this->estimations->contains($estimation)) {
$this->estimations[] = $estimation;
$estimation->setEleve($this);
}
return $this;
}
public function removeEstimation(LivretEstimation $estimation): self
{
if ($this->estimations->removeElement($estimation)) {
// set the owning side to null (unless already changed)
if ($estimation->getEleve() === $this) {
$estimation->setEleve(null);
}
}
return $this;
}
/**
* @return Collection<int, UserEnseignantFacture>
*/
public function getFactures(): Collection
{
return $this->factures;
}
public function addFacture(UserEnseignantFacture $facture): self
{
if (!$this->factures->contains($facture)) {
$this->factures[] = $facture;
$facture->setEnseignant($this);
}
return $this;
}
public function removeFacture(UserEnseignantFacture $facture): self
{
if ($this->factures->removeElement($facture)) {
// set the owning side to null (unless already changed)
if ($facture->getEnseignant() === $this) {
$facture->setEnseignant(null);
}
}
return $this;
}
public function getFacture(\DateTimeInterface $periode_debut, \DateTimeInterface $periode_fin): ?UserEnseignantFacture
{
$Facture = $this->factures->filter(function($element) use($periode_debut, $periode_fin) {
if($element->getExport())return false;
if($element->getPeriodeDebut()->format('c') != $periode_debut->format('c'))return false;
if($element->getPeriodeFin()->format('c') != $periode_fin->format('c'))return false;
return true;
})->first();
if ($Facture) {
return $Facture;
}
return null;
}
public function getApiToken(): ?string
{
return $this->apiToken;
}
public function setApiToken(?string $apiToken): self
{
$this->apiToken = $apiToken;
return $this;
}
public function isDeleted(): bool
{
return ($this->deletedAt !== null);
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
}