src/Entrepreneurs/Bundle/AppBundle/Propel/Enseignant.php line 16

Open in your IDE?
  1. <?php
  2. namespace Entrepreneurs\Bundle\AppBundle\Propel;
  3. use Entrepreneurs\Bundle\AppBundle\Propel\Base\Enseignant as BaseEnseignant;
  4. use Entrepreneurs\Bundle\AppBundle\Propel\Interfaces\DemandeInterventionCreateur;
  5. use Entrepreneurs\Bundle\AppBundle\Propel\Map\EnseignantTableMap;
  6. use Entrepreneurs\Bundle\AppBundle\Util\Password;
  7. use Propel\Runtime\ActiveQuery\Criteria;
  8. use Propel\Runtime\Collection\ObjectCollection;
  9. use Propel\Runtime\Connection\ConnectionInterface;
  10. use Propel\Runtime\Exception\PropelException;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. class Enseignant extends BaseEnseignant implements DemandeInterventionCreateurUserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     public const PARTICIPATION_COMMUNAUTE_OUI 'Oui';
  16.     public const PARTICIPATION_COMMUNAUTE_NON 'Non';
  17.     public const PARTICIPATION_COMMUNAUTE_POURQUOI_PAS 'Pourquoi pas';
  18.     public static function getParticipationCommunauteChoiceList()
  19.     {
  20.         $list[self::PARTICIPATION_COMMUNAUTE_OUI] = self::PARTICIPATION_COMMUNAUTE_OUI;
  21.         $list[self::PARTICIPATION_COMMUNAUTE_NON] = self::PARTICIPATION_COMMUNAUTE_NON;
  22.         $list[self::PARTICIPATION_COMMUNAUTE_POURQUOI_PAS] = self::PARTICIPATION_COMMUNAUTE_POURQUOI_PAS;
  23.         return $list;
  24.     }
  25.     protected $plainMotDePasse;
  26.     public function __toString()
  27.     {
  28.         return $this->getNomComplet();
  29.     }
  30.     public function getNomCompletCivilite()
  31.     {
  32.         return $this->civilite.' '.$this->prenom.' '.mb_strtoupper($this->nom'UTF-8');
  33.     }
  34.     public function getNomCompletStatut()
  35.     {
  36.         return $this->getNomComplet().' ('.$this->getStatut().')';
  37.     }
  38.     public function getNomComplet(): string
  39.     {
  40.         return $this->prenom.' '.mb_strtoupper($this->nom'UTF-8');
  41.     }
  42.     public function eraseCredentials()
  43.     {
  44.         $this->plainMotDePasse '';
  45.     }
  46.     public function getPassword(): ?string
  47.     {
  48.         return $this->getMotDePasse();
  49.     }
  50.     public function getRoles()
  51.     {
  52.         return ['ROLE_ENSEIGNANT'];
  53.     }
  54.     public function getSalt()
  55.     {
  56.         return $this->getSel();
  57.     }
  58.     public function getUsername()
  59.     {
  60.         return $this->getEmail();
  61.     }
  62.     public function initMotDePasse()
  63.     {
  64.         $password Password::create();
  65.         $this->setMotDePasse($password);
  66.         return $password;
  67.     }
  68.     public function setMotDePasse($v$encode true$algorithm 'sha256')
  69.     {
  70.         if ($encode) {
  71.             $this->setSel(sha1(uniqid((string) time(), true)));
  72.             parent::setMotDePasse(hash($algorithm$v.'{'.$this->getSel().'}'));
  73.         } else {
  74.             parent::setMotDePasse($v);
  75.         }
  76.         return $this;
  77.     }
  78.     public function setPlainMotDePasse($v)
  79.     {
  80.         $this->plainMotDePasse $v;
  81.     }
  82.     public function getPlainMotDePasse()
  83.     {
  84.         return $this->plainMotDePasse;
  85.     }
  86.     public function getDemandesIntervention(Criteria $criteria nullConnectionInterface $con null)
  87.     {
  88.         return parent::getDemandeInterventions($criteria$con);
  89.     }
  90.     public function getDemandesInterventionEnCours()
  91.     {
  92.         $c DemandeInterventionQuery::create()
  93.                 ->filterByStatutId([
  94.                     DemandeInterventionStatut::EN_ATTENTE_INTERVENANT,
  95.                     DemandeInterventionStatut::INTERVENANT_POSITIONNE,
  96.                     DemandeInterventionStatut::EN_ATTENTE_EVALUATION,
  97.                     DemandeInterventionStatut::SUSPENDU,
  98.                 ], Criteria::IN)
  99.                 ->orderByDateMaj(Criteria::DESC);
  100.         return parent::getDemandeInterventions($c);
  101.     }
  102.     public function getDemandesInterventionHistorisees($criteria nullConnectionInterface $con null)
  103.     {
  104.         $c DemandeInterventionQuery::create()
  105.                 ->filterByStatutId([
  106.                     DemandeInterventionStatut::TERMINEE,
  107.                     DemandeInterventionStatut::ANNULEE,
  108.                     DemandeInterventionStatut::IMPREVU,
  109.                 ], Criteria::IN)
  110.                 ->orderByDateMaj(Criteria::DESC);
  111.         return parent::getDemandeInterventions($c);
  112.     }
  113.     public function getPassedDemandesIntervention($criteria nullConnectionInterface $con null)
  114.     {
  115.         $c DemandeInterventionQuery::create()
  116.                 ->filterByStatutId([
  117.                     DemandeInterventionStatut::TERMINEE,
  118.                     DemandeInterventionStatut::EN_ATTENTE_EVALUATION,
  119.                 ], Criteria::IN)
  120.                 ->orderByDateMaj(Criteria::DESC);
  121.         return parent::getDemandeInterventions($c);
  122.     }
  123.     /**
  124.      * NB: EnseignantStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
  125.      */
  126.     public function isDisabled(): bool
  127.     {
  128.         return in_array($this->getStatutId(), [
  129.             EnseignantStatut::SUPPRIME,
  130.             EnseignantStatut::SUSPENDU,
  131.         ]);
  132.     }
  133.     /**
  134.      * NB: EnseignantStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
  135.      */
  136.     public function isEnabled(): bool
  137.     {
  138.         return in_array($this->getStatutId(), [
  139.             EnseignantStatut::ACTIF,
  140.             EnseignantStatut::MDP_REINITIALISE,
  141.         ]);
  142.     }
  143.     public function init(): self
  144.     {
  145.         return $this
  146.             ->generateNewUID()
  147.             ->setStatutId(EnseignantStatut::EN_ATTENTE_ACTIVATION);
  148.     }
  149.     public function initQuestionnaire(): self
  150.     {
  151.         return $this
  152.             ->generateNewUID()
  153.             ->setStatutId(EnseignantStatut::EN_ATTENTE_ACTIVATION);
  154.     }
  155.     public function getAnnotations(Criteria $criteria nullConnectionInterface $con null)
  156.     {
  157.         if (!$criteria) {
  158.             $criteria AnnotationEnseignantQuery::create()->orderByDateCreation(Criteria::DESC);
  159.         }
  160.         return parent::getAnnotations($criteria$con);
  161.     }
  162.     public function hasMotdePasseAndSel(): bool
  163.     {
  164.         return $this->getMotDePasse() && $this->getSalt();
  165.     }
  166.     public function getDepartement(): ?Departement
  167.     {
  168.         return (($etablissement $this->getEtablissement()) && $ville $etablissement->getVille()) ? $ville->getDepartement() : null;
  169.     }
  170.     public function getCoordinateur(): ?Gestionnaire
  171.     {
  172.         return ($departement $this->getDepartement()) ? $departement->getCoordinateur() : null;
  173.     }
  174.     public function getDelegue(): ?Gestionnaire
  175.     {
  176.         return ($departement $this->getDepartement()) ? $departement->getDelegue() : null;
  177.     }
  178.     public function getTelephone(): ?string
  179.     {
  180.         return parent::getTelephone1();
  181.     }
  182.     public function logSurvey(): void
  183.     {
  184.         $surveyStat = new SurveyStats();
  185.         $surveyStat->setEnseignant($this)
  186.             ->setsurveyEnseignant(true);
  187.         $surveyStat->save();
  188.     }
  189.     public function logSurveySEF(): void
  190.     {
  191.         $surveyStat = new SurveyStats();
  192.         $surveyStat->setEnseignant($this)
  193.             ->setsurveyEnseignantSEF(true);
  194.         $surveyStat->save();
  195.     }
  196.     public function getIdCreerPar(): string
  197.     {
  198.         return EnseignantTableMap::TABLE_NAME.' '.$this->id;
  199.     }
  200.     public function getEtablissementsLabels(): string
  201.     {
  202.         if ($this->getEtablissementNonReference()) {
  203.             return 'Etablissement non renseignée: '.$this->getNomEtablissementNonReference().'( '
  204.                 .($this->getDepartementAutreStructure() ? $this->getDepartementAutreStructure()->getLabel() : '').' )';
  205.         }
  206.         return $this->getEtablissement() ? $this->getEtablissement()->getLabel() : '';
  207.     }
  208.     public function getFonctionLabel(): string
  209.     {
  210.         $fonction FonctionEnseignantQuery::create()->findOneById($this->getFonctionId());
  211.         return $fonction $fonction->getLabel() : '';
  212.     }
  213.     public function getPeriodesLabels(): string
  214.     {
  215.         $periodes PeriodeInterventionQuery::create()
  216.             ->useEnseignantPeriodeInterventionExistsQuery()
  217.                 ->filterByEnseignant($this)
  218.             ->endUse()
  219.             ->find();
  220.         $periodesLabels '';
  221.         foreach ($periodes as $periode) {
  222.             $periodesLabels .= $periode->getLabel().', ';
  223.         }
  224.         return '' !== $periodesLabels substr($periodesLabels0, -2) : '';
  225.     }
  226.     public function getThematiquesLabels(): string
  227.     {
  228.         $thematiques TypeInterventionQuery::create()
  229.             ->useEnseignantTypeInterventionExistsQuery()
  230.                 ->filterByEnseignant($this)
  231.             ->endUse()
  232.             ->find();
  233.         $thematiquesLabels '';
  234.         foreach ($thematiques as $thematique) {
  235.             $thematiquesLabels .= $thematique->getLabel().', ';
  236.         }
  237.         return '' !== $thematiquesLabels substr($thematiquesLabels0, -2) : '';
  238.     }
  239.     public function getActionsHorsMursLabels(): string
  240.     {
  241.         $actionsHorsMurs ActionHorsDesMursQuery::create()
  242.             ->useEnseignantActionHorsDesMursExistsQuery()
  243.                 ->filterByEnseignant($this)
  244.             ->endUse()
  245.             ->find();
  246.         $actionsHorsMursLabels '';
  247.         foreach ($actionsHorsMurs as $actionHorsMurs) {
  248.             $actionsHorsMursLabels .= $actionHorsMurs->getLabel().', ';
  249.         }
  250.         return '' !== $actionsHorsMursLabels substr($actionsHorsMursLabels0, -2) : '';
  251.     }
  252.     /**
  253.      * @throws PropelException
  254.      */
  255.     public function getActionsHorsMursSefLabels(): string
  256.     {
  257.         $actionsHorsMursSef ActionHorsDesMursSefQuery::create()
  258.             ->useEnseignantActionHorsDesMursSefExistsQuery()
  259.                 ->filterByEnseignantSef($this)
  260.             ->endUse()
  261.             ->find();
  262.         $actionsHorsMursSefLabels '';
  263.         foreach ($actionsHorsMursSef as $actionHorsMursSef) {
  264.             $actionsHorsMursSefLabels .= $actionHorsMursSef->getLabel().', ';
  265.         }
  266.         return '' !== $actionsHorsMursSefLabels substr($actionsHorsMursSefLabels0, -2) : '';
  267.     }
  268.     public function getProvenanceLabel(): string
  269.     {
  270.         $provenance ProvenanceEnseignantQuery::create()->findOneById($this->getProvenanceId());
  271.         return $this->getProvenanceId() ? $provenance->getLabel() : '';
  272.     }
  273.     public function getTelephoneLabel(): string
  274.     {
  275.         return str_replace(' '''$this->getTelephone());
  276.     }
  277.     public function setStatutId($v): self
  278.     {
  279.         if (EnseignantStatut::ACTIF === $v) {
  280.             $this->setDateReactivation(null);
  281.             $this->setDureeSuspension(null);
  282.         }
  283.         return parent::setStatutId($v);
  284.     }
  285.     public function suspendre(\DateTime $dateReactivation): self
  286.     {
  287.         if (EnseignantStatut::SUSPENDU === $this->getStatutId()) {
  288.             return $this;
  289.         }
  290.         $this->setStatutId(EnseignantStatut::SUSPENDU);
  291.         $this->setDateReactivation($dateReactivation);
  292.         $this->setDureeSuspension(($dateReactivation->getTimestamp() - time()) / 86400);
  293.         return $this;
  294.     }
  295.     public function generateNewUID(): self
  296.     {
  297.         $this->setUid(sha1(uniqid((string) time(), true)));
  298.         return $this;
  299.     }
  300.     public function generateNewTokenReinitialisation(): self
  301.     {
  302.         $this->setTokenReinitialisation(sha1(uniqid((string) time(), true)));
  303.         return $this;
  304.     }
  305.     public function isDeletable()
  306.     {
  307.         return EnseignantStatut::SUPPRIME === $this->getStatutId() && !$this->getDemandesIntervention()->count() > 0;
  308.     }
  309.     /**
  310.      * @throws PropelException
  311.      */
  312.     public function getCodePostalOfEtablissement(): string
  313.     {
  314.         return $this->getEtablissement() && $this->getEtablissement()->getVille() ?
  315.             $this->getEtablissement()->getVille()->getCodePostal()
  316.             : '';
  317.     }
  318.     /**
  319.      * @throws PropelException
  320.      */
  321.     public function getDemandeInterventionsWithEvaluationJeuneNotCompleted(): ObjectCollection
  322.     {
  323.         return DemandeInterventionQuery::create()
  324.             ->distinct()
  325.             ->filterByStatutId(DemandeInterventionStatut::EN_ATTENTE_EVALUATION)
  326.             ->filterByEnseignant($this)
  327.             ->filterByEvaluationJeuneNotCompleted()
  328.             ->orderByDate(Criteria::DESC)
  329.             ->find();
  330.     }
  331. }