src/Entrepreneurs/Bundle/AppBundle/Propel/Entrepreneur.php line 19

Open in your IDE?
  1. <?php
  2. namespace Entrepreneurs\Bundle\AppBundle\Propel;
  3. use Entrepreneurs\Bundle\AppBundle\Propel\Base\Entrepreneur as BaseEntrepreneur;
  4. use Entrepreneurs\Bundle\AppBundle\Propel\Map\EntrepreneurSecteursActiviteTableMap;
  5. use Entrepreneurs\Bundle\AppBundle\Propel\Map\SecteurActiviteTableMap;
  6. use Entrepreneurs\Bundle\AppBundle\Util\Password;
  7. use Propel\Runtime\ActiveQuery\Criteria;
  8. use Propel\Runtime\Collection\Collection;
  9. use Propel\Runtime\Collection\ObjectCollection;
  10. use Propel\Runtime\Connection\ConnectionInterface;
  11. use Propel\Runtime\Exception\PropelException;
  12. use Propel\Runtime\Propel;
  13. use Symfony\Component\Intl\Countries;
  14. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. class Entrepreneur extends BaseEntrepreneur implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     public const MONSIEUR 'Monsieur';
  19.     public const PK_PAS_DEVENIR_RT 'Pourquoi pas, je veux bien en savoir plus sur les missions';
  20.     public const ACCEPT_DEVENIR_RT "Oui ça m'intéresse et je peux dégager du temps";
  21.     public const REFUSE_DEVENIR_RT 'Non';
  22.     public const RT_VALIDE_NON 'Non';
  23.     public const RT_VALIDE_EN_COURS 'En cours';
  24.     public const RT_VALIDE_OUI 'Oui';
  25.     public const RT_VALIDE_ANCIEN 'Ancien RT';
  26.     protected $plainMotDePasse;
  27.     public function __toString()
  28.     {
  29.         return $this->getNomComplet();
  30.     }
  31.     public function getNomCompletStatut()
  32.     {
  33.         return $this->getNomComplet().' ('.$this->getStatut().')';
  34.     }
  35.     public function getNomComplet()
  36.     {
  37.         return $this->getCivilite().' '.$this->getPrenomNom();
  38.     }
  39.     public function getPrenomNom()
  40.     {
  41.         return $this->getPrenom().' '.mb_strtoupper($this->getNom(), 'UTF-8');
  42.     }
  43.     public function eraseCredentials()
  44.     {
  45.         $this->plainMotDePasse '';
  46.     }
  47.     public function getPassword(): ?string
  48.     {
  49.         return $this->getMotDePasse();
  50.     }
  51.     public function getRoles(): array
  52.     {
  53.         return ['ROLE_ENTREPRENEUR'];
  54.     }
  55.     public function getSalt(): ?string
  56.     {
  57.         return $this->getSel();
  58.     }
  59.     public function getUsername(): string
  60.     {
  61.         return $this->getEmail();
  62.     }
  63.     public function initMotDePasse(): string
  64.     {
  65.         $password Password::create();
  66.         $this->setMotDePasse($password);
  67.         return $password;
  68.     }
  69.     public function setMotDePasse($v$encode true$algorithm 'sha256'): self
  70.     {
  71.         if ($encode) {
  72.             $this->setSel(sha1(uniqid((string) time(), true)));
  73.             parent::setMotDePasse(hash($algorithm$v.'{'.$this->getSel().'}'));
  74.         } else {
  75.             parent::setMotDePasse($v);
  76.         }
  77.         return $this;
  78.     }
  79.     public function setPlainMotDePasse($v): void
  80.     {
  81.         $this->plainMotDePasse $v;
  82.     }
  83.     public function getPlainMotDePasse(): string
  84.     {
  85.         return $this->plainMotDePasse;
  86.     }
  87.     public function getCodePostal($short false): string
  88.     {
  89.         if ($short) {
  90.             return substr($this->code_postal02);
  91.         }
  92.         return $this->code_postal;
  93.     }
  94.     public function getReseaux(Criteria $criteria nullConnectionInterface $con null)
  95.     {
  96.         return parent::getReseaus($criteria$con);
  97.     }
  98.     public function setReseaux(Collection $reseausConnectionInterface $con null)
  99.     {
  100.         return parent::setReseaus($reseaus$con);
  101.     }
  102.     public function hasThisDepartement($departementReceive)
  103.     {
  104.         $flag false;
  105.         foreach ($this->getDepartements() as $departement) {
  106.             if ($departement->getNumero() == $departementReceive->getNumero()) {
  107.                 return true;
  108.             }
  109.         }
  110.         return $flag;
  111.     }
  112.     /**
  113.      * Retourne les demandes d'intervention dont les caractéristiques géographiques
  114.      * correspondent à la l'entrepreneur courrant.
  115.      */
  116.     public function getMatchingDemandesIntervention()
  117.     {
  118.         $ids = [];
  119.         foreach ($this->getInterventions() as $intervention) {
  120.             $ids[] = $intervention->getDemandeInterventionId();
  121.         }
  122.         return DemandeInterventionQuery::create()
  123.             ->filterById($idsCriteria::NOT_IN)
  124.             ->filterByStatutId(DemandeInterventionStatut::EN_ATTENTE_INTERVENANT)
  125.             ->filterByCreneau1Debut(new \DateTime(), Criteria::GREATER_THAN)
  126.             ->_or()
  127.             ->filterByCreneau2Debut(new \DateTime(), Criteria::GREATER_THAN)
  128.             ->_or()
  129.             ->filterByCreneau3Debut(new \DateTime(), Criteria::GREATER_THAN)
  130.             ->useEtablissementQuery()
  131.                 ->useVilleQuery()
  132.                     ->filterByDepartement($this->getDepartements())
  133.                 ->endUse()
  134.             ->endUse()
  135.             ->distinct()
  136.             ->find()
  137.         ;
  138.     }
  139.     /**
  140.      * Associe et enregistre les demandes d'intervention dont les caractéristiques
  141.      * géographiques correspondent à l'entrepreneur courrant.
  142.      */
  143.     public function matchDemandesIntervention()
  144.     {
  145.         $demandes $this->getMatchingDemandesIntervention();
  146.         foreach ($demandes as $demande) {
  147.             $intervention = new Intervention();
  148.             $intervention->setDemandeIntervention($demande);
  149.             $intervention->setEntrepreneur($this);
  150.             $intervention->setMatchingAuto(true);
  151.             $intervention->save();
  152.         }
  153.         return $demandes;
  154.     }
  155.     /**
  156.      * NB: EntrepreneurStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
  157.      */
  158.     public function isDisabled(): bool
  159.     {
  160.         return in_array($this->getStatutId(), [
  161.             EntrepreneurStatut::SUPPRIME,
  162.             EntrepreneurStatut::SUSPENDU,
  163.         ]);
  164.     }
  165.     /**
  166.      * NB: EntrepreneurStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
  167.      */
  168.     public function isEnabled(): bool
  169.     {
  170.         return in_array($this->getStatutId(), [
  171.             EntrepreneurStatut::ACTIF,
  172.             EntrepreneurStatut::MDP_REINITIALISE,
  173.         ]);
  174.     }
  175.     public function initQuestionnaire(): Entrepreneur
  176.     {
  177.         return $this
  178.             ->generateNewUID()
  179.             ->setStatutId(EntrepreneurStatut::EN_ATTENTE_ACTIVATION);
  180.     }
  181.     public function estForme(): ?bool
  182.     {
  183.         return $this->getEstForme();
  184.     }
  185.     public function getInscriptionFormationActive()
  186.     {
  187.         $query FormationInscriptionQuery::create()
  188.             ->filterByStatutId([
  189.                 FormationInscriptionStatut::ANNULEE,
  190.                 FormationInscriptionStatut::REFUSEE,
  191.             ], Criteria::NOT_IN)
  192.             ->useFormationQuery()
  193.                 ->filterByDate(['min' => new \DateTime()])
  194.             ->endUse()
  195.             ->orderByDateCreation(Criteria::DESC);
  196.         return $this->getFormationInscriptions($query)->getFirst();
  197.     }
  198.     /**
  199.      * @throws PropelException
  200.      */
  201.     public function getFormationInscriptionElearning()
  202.     {
  203.         return FormationInscriptionQuery::create()
  204.             ->useFormationQuery()
  205.             ->filterById(Formation::E_LEARNING)
  206.             ->endUse()
  207.             ->filterByEntrepreneur($this)
  208.             ->find()
  209.             ->getFirst()
  210.         ;
  211.     }
  212.     public function getFormationActive()
  213.     {
  214.         return $this->getInscriptionFormationActive() ? $this->getInscriptionFormationActive()->getFormation() : null;
  215.     }
  216.     public function hasAtLeastOneDepartementInterventionActif()
  217.     {
  218.         foreach ($this->getDepartements() as $departement) {
  219.             if ($departement->getActif()) {
  220.                 return true;
  221.             }
  222.         }
  223.         return false;
  224.     }
  225.     public function getAnnotations(Criteria $criteria nullConnectionInterface $con null)
  226.     {
  227.         if (!$criteria) {
  228.             $criteria AnnotationEntrepreneurQuery::create()->orderByDateCreation(Criteria::DESC);
  229.         }
  230.         return parent::getAnnotations($criteria$con);
  231.     }
  232.     public function hasMotdePasseAndSel()
  233.     {
  234.         return $this->getMotDePasse() && $this->getSalt();
  235.     }
  236.     public function getDelegue(): ?Gestionnaire
  237.     {
  238.         if ($departement $this->getDepartements()->getFirst()) {
  239.             return $departement->getDelegue();
  240.         }
  241.         return null;
  242.     }
  243.     public function getCoordinateur(): ?Gestionnaire
  244.     {
  245.         $cp substr($this->getEntrepriseCodePostal(), 02);
  246.         if ($cp >= 96) {
  247.             $cp substr($this->getEntrepriseCodePostal(), 03);
  248.         }
  249.         $organismeDepartement DepartementQuery::create()
  250.             ->filterByActif(true)
  251.             ->filterByNumero($cp)
  252.             ->findOne();
  253.         if ($organismeDepartement) {
  254.             return $organismeDepartement->getCoordinateur();
  255.         } elseif ($departementIntervention $this->getDepartementInterventions(DepartementQuery::create()->filterByActif(true))->getFirst()) {
  256.             if ($departement $departementIntervention->getDepartement()) {
  257.                 return $departement->getCoordinateur();
  258.             }
  259.         }
  260.         return null;
  261.     }
  262.     public function formationELearningEnCours()
  263.     {
  264.         foreach ($this->getFormationInscriptions() as $formationInscription) {
  265.             if (
  266.                 -=== $formationInscription->getFormationId()
  267.                 && $formationInscription->getStatutId()
  268.                 && FormationInscriptionStatut::EN_ATTENTE === $formationInscription->getStatutId()
  269.             ) {
  270.                 return true;
  271.             }
  272.         }
  273.         return false;
  274.     }
  275.     public function getTelephone(): string
  276.     {
  277.         return parent::getTelephone1();
  278.     }
  279.     public function getNombreInterventionParDate(\DateTime $date): int
  280.     {
  281.         return InterventionQuery::create()
  282.             ->filterByEntrepreneurAndDate($this$date)
  283.             ->find()
  284.             ->count();
  285.     }
  286.     public function logSurvey1(): void
  287.     {
  288.         $surveyStat = new SurveyStats();
  289.         $surveyStat->setEntrepreneur($this)
  290.             ->setsurveyEntrepreneur1(true);
  291.         $surveyStat->save();
  292.     }
  293.     public function logSurvey2(): void
  294.     {
  295.         $surveyStat = new SurveyStats();
  296.         $surveyStat->setEntrepreneur($this)
  297.             ->setsurveyEntrepreneur2(true);
  298.         $surveyStat->save();
  299.     }
  300.     public function logSurveySEF(): void
  301.     {
  302.         $surveyStat = new SurveyStats();
  303.         $surveyStat->setEntrepreneur($this)
  304.             ->setsurveyEntrepreneurSEF(true);
  305.         $surveyStat->save();
  306.     }
  307.     /**
  308.      * @throws PropelException
  309.      */
  310.     public function setStatutId($v): Entrepreneur
  311.     {
  312.         if (EntrepreneurStatut::SUSPENDU === $v) {
  313.             if (null !== $this->getDateReactivation()) {
  314.                 $duree = (int) ceil(($this->getDateReactivation()->getTimestamp() - time()) / (60 60 24));
  315.             }
  316.         }
  317.         return parent::setStatutId($v);
  318.     }
  319.     public function getSecteursActivitesLabels(): string
  320.     {
  321.         $con Propel::getConnection();
  322.         $sql 'SELECT '.SecteurActiviteTableMap::COL_LABEL.
  323.             ' FROM '.SecteurActiviteTableMap::TABLE_NAME.
  324.             ' INNER JOIN '.EntrepreneurSecteursActiviteTableMap::TABLE_NAME.
  325.             ' ON '.EntrepreneurSecteursActiviteTableMap::COL_SECTEUR_ACTIVITE_ID.' = '.SecteurActiviteTableMap::COL_ID.
  326.             ' WHERE '.EntrepreneurSecteursActiviteTableMap::COL_ENTREPRENEUR_ID.' = '.$this->getId();
  327.         $stmt $con->prepare($sql);
  328.         $stmt->execute();
  329.         $secteursActivites $stmt->fetchAll();
  330.         $secteursActivitesString '';
  331.         foreach ($secteursActivites as $secteurActivite) {
  332.             $secteursActivitesString .= $secteurActivite['label'].', ';
  333.         }
  334.         return '' !== $secteursActivitesString substr($secteursActivitesString0, -2) : '';
  335.     }
  336.     public function getFonctionLabel(): string
  337.     {
  338.         $fonction FonctionEntrepreneurQuery::create()->filterById($this->getFonctionId())->findOne();
  339.         return $fonction $fonction->getLabel() : '';
  340.     }
  341.     public function getEffectifLabel(): string
  342.     {
  343.         return $this->getEntrepriseEffectif() ? $this->getEntrepriseEffectif()->getLabel() : '';
  344.     }
  345.     public function getReseauxLabels(): string
  346.     {
  347.         $reseaux ReseauQuery::create()
  348.             ->useEntrepreneurReseauExistsQuery()
  349.                 ->filterByEntrepreneur($this)
  350.             ->endUse()
  351.             ->find();
  352.         $reseauString '';
  353.         /** @var Reseau $reseau */
  354.         foreach ($reseaux as $reseau) {
  355.             $reseauString .= $reseau->getNom().', ';
  356.         }
  357.         return '' !== $reseauString substr($reseauString0, -2) : '';
  358.     }
  359.     public function getModeCommunicationLabels(): string
  360.     {
  361.         $modeCommunication ModeCommunicationQuery::create()->
  362.         useEntrepreneurModeCommunicationExistsQuery()
  363.                 ->filterByEntrepreneur($this)
  364.             ->endUse()
  365.             ->find();
  366.         $modeCommunicationString '';
  367.         /** @var ModeCommunication $mode */
  368.         foreach ($modeCommunication as $mode) {
  369.             $modeCommunicationString .= $mode->getLabel().', ';
  370.         }
  371.         return '' !== $modeCommunicationString substr($modeCommunicationString0, -2) : '';
  372.     }
  373.     public function getDepartementsLabels(): string
  374.     {
  375.         $departements DepartementQuery::create()
  376.             ->useDepartementInterventionExistsQuery()
  377.                 ->filterByEntrepreneur($this)
  378.             ->endUse()
  379.             ->find();
  380.         $departementString '';
  381.         /** @var Departement $departement */
  382.         foreach ($departements as $departement) {
  383.             $departementString .= $departement->getLabel().', ';
  384.         }
  385.         return '' !== $departementString substr($departementString0, -2) : '';
  386.     }
  387.     public function getProvenanceLabel(): string
  388.     {
  389.         $provenance ProvenanceEntrepreneurQuery::create()->filterById($this->getProvenanceId())->findOne();
  390.         return $provenance $provenance->getLabel() : '';
  391.     }
  392.     public function getTelephoneLabel(): string
  393.     {
  394.         $tel $this->getTelephone();
  395.         $tel str_replace(' '''$tel);
  396.         $tel str_replace('.'''$tel);
  397.         $tel str_replace('/'''$tel);
  398.         return $tel;
  399.     }
  400.     public function getCollegeLabel(): string
  401.     {
  402.         return $this->getCollege() ? $this->getCollege()->getLabel() : '';
  403.     }
  404.     public function getLyceeLabel(): string
  405.     {
  406.         return $this->getLycee() ? $this->getLycee()->getLabel() : '';
  407.     }
  408.     public function getEtablissementsEnfantsLabels(): string
  409.     {
  410.         $etablissements EtablissementQuery::create()
  411.             ->useEntrepreneurEtablissementEnfantExistsQuery()
  412.                 ->filterByEntrepreneur($this)
  413.             ->endUse()
  414.             ->find();
  415.         $etablissementsLabels '';
  416.         /** @var Etablissement $etablissement */
  417.         foreach ($etablissements as $etablissement) {
  418.             $etablissementsLabels .= $etablissement->getLabel().', ';
  419.         }
  420.         return '' !== $etablissementsLabels substr($etablissementsLabels0, -2) : '';
  421.     }
  422.     public function getThematiquesLabels(): string
  423.     {
  424.         $evenements EvenementQuery::create()
  425.             ->useEntrepreneurEvenementQuery()
  426.                 ->filterByEntrepreneur($this)
  427.             ->endUse()
  428.             ->find();
  429.         $thematiques '';
  430.         /** @var Evenement $evenement */
  431.         foreach ($evenements as $evenement) {
  432.             $thematiques .= $evenement->getLabel().', ';
  433.         }
  434.         return '' !== $thematiques substr($thematiques0, -2) : '';
  435.     }
  436.     public function getLanguesEtrangeresLabels(): string
  437.     {
  438.         $langues LangueEtrangereQuery::create()
  439.             ->useEntrepreneurLangueEtrangereExistsQuery()
  440.                 ->filterByEntrepreneur($this)
  441.             ->endUse()
  442.             ->find();
  443.         $languesLabels '';
  444.         /** @var LangueEtrangere $langue */
  445.         foreach ($langues as $langue) {
  446.             $languesLabels .= $langue->getLabel().', ';
  447.         }
  448.         return '' !== $languesLabels substr($languesLabels0, -2) : '';
  449.     }
  450.     public function getFullAdress(): string
  451.     {
  452.         try {
  453.             $countryName $this->pays Countries::getName($this->pays'fr') : null;
  454.         } catch (\Exception $exception) {
  455.             $countryName $this->pays;
  456.         }
  457.         $fullAddress $this->adresse_1;
  458.         $fullAddress .= ($fullAddress && !empty($this->adresse_1) ? ' ' '').$this->adresse_2;
  459.         $fullAddress .= ($fullAddress ', ' '').$this->code_postal;
  460.         $fullAddress .= ($fullAddress && !empty($this->code_postal) ? ' ' '').$this->ville;
  461.         $fullAddress .= ($fullAddress && (!empty($this->ville) || !empty($this->code_postal)) && !empty($countryName) ? ', ' '').$countryName;
  462.         return $fullAddress;
  463.     }
  464.     public function getFullEntrepriseAdresse(): string
  465.     {
  466.         try {
  467.             $countryName $this->entreprise_pays Countries::getName($this->entreprise_pays'fr') : '';
  468.         } catch (\Exception $exception) {
  469.             $countryName $this->entreprise_pays;
  470.         }
  471.         $fullAddress $this->entreprise_adresse;
  472.         $fullAddress .= ($fullAddress ', ' '').$this->entreprise_code_postal;
  473.         $fullAddress .= ($fullAddress && !empty($this->entreprise_code_postal) ? ' ' '').$this->entreprise_ville;
  474.         $fullAddress .= ($fullAddress && (!empty($this->entreprise_ville) || !empty($this->entreprise_code_postal)) && !empty($countryName) ? ', ' '').$countryName;
  475.         return $fullAddress;
  476.     }
  477.     public function suspendre(\DateTime $dateReactivation): Entrepreneur
  478.     {
  479.         if (EntrepreneurStatut::SUSPENDU === $this->getStatutId()) {
  480.             return $this;
  481.         }
  482.         $this->setStatutId(EntrepreneurStatut::SUSPENDU);
  483.         $this->setDateReactivation($dateReactivation);
  484.         $this->setDureeSuspension(($dateReactivation->getTimestamp() - time()) / 86400);
  485.         return $this;
  486.     }
  487.     public function generateNewUID(): self
  488.     {
  489.         $this->setUid(sha1(uniqid((string) time(), true)));
  490.         return $this;
  491.     }
  492.     public function generateNewTokenReinitialisation(): self
  493.     {
  494.         $this->setTokenReinitialisation(sha1(uniqid((string) time(), true)));
  495.         return $this;
  496.     }
  497.     public function isDeletable()
  498.     {
  499.         $linkedInterventions InterventionQuery::create()
  500.             ->filterByEntrepreneur($this)
  501.             ->filterByStatutId([
  502.                 InterventionStatut::ACCEPTEE,
  503.                 InterventionStatut::EN_ATTENTE_EVALUATION,
  504.                 InterventionStatut::SUSPENDU,
  505.                 InterventionStatut::TERMINEE,
  506.             ])
  507.             ->count()
  508.         ;
  509.         return EntrepreneurStatut::SUPPRIME === $this->getStatutId() && !$linkedInterventions 0;
  510.     }
  511.     public function hasAlreadyOneReservation(): bool
  512.     {
  513.         return InterventionQuery::create()
  514.             ->filterByEntrepreneur($this)
  515.             ->filterByStatutId(InterventionStatut::RESERVED)
  516.             ->count() > 0;
  517.     }
  518.     /**
  519.      * @throws PropelException
  520.      */
  521.     public function getInterventionsWithEvaluationNotCompleted(): ObjectCollection
  522.     {
  523.         return InterventionQuery::create()
  524.             ->filterByEntrepreneur($this)
  525.             ->filterByStatutId(InterventionStatut::EN_ATTENTE_EVALUATION)
  526.             ->find();
  527.     }
  528.     public function getDateAdhesionReseau(int $reseauIdstring $format): string|null
  529.     {
  530.         $adhesionReseau EntrepreneurReseauQuery::create()
  531.             ->filterByEntrepreneur($this)
  532.             ->filterByReseauId($reseauId)
  533.             ->findOne();
  534.         return $adhesionReseau?->getDateCreation($format);
  535.     }
  536. }