<?php
namespace Entrepreneurs\Bundle\AppBundle\Propel;
use Entrepreneurs\Bundle\AppBundle\Propel\Base\Enseignant as BaseEnseignant;
use Entrepreneurs\Bundle\AppBundle\Propel\Interfaces\DemandeInterventionCreateur;
use Entrepreneurs\Bundle\AppBundle\Propel\Map\EnseignantTableMap;
use Entrepreneurs\Bundle\AppBundle\Util\Password;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class Enseignant extends BaseEnseignant implements DemandeInterventionCreateur, UserInterface, PasswordAuthenticatedUserInterface
{
public const PARTICIPATION_COMMUNAUTE_OUI = 'Oui';
public const PARTICIPATION_COMMUNAUTE_NON = 'Non';
public const PARTICIPATION_COMMUNAUTE_POURQUOI_PAS = 'Pourquoi pas';
public static function getParticipationCommunauteChoiceList()
{
$list[self::PARTICIPATION_COMMUNAUTE_OUI] = self::PARTICIPATION_COMMUNAUTE_OUI;
$list[self::PARTICIPATION_COMMUNAUTE_NON] = self::PARTICIPATION_COMMUNAUTE_NON;
$list[self::PARTICIPATION_COMMUNAUTE_POURQUOI_PAS] = self::PARTICIPATION_COMMUNAUTE_POURQUOI_PAS;
return $list;
}
protected $plainMotDePasse;
public function __toString()
{
return $this->getNomComplet();
}
public function getNomCompletCivilite()
{
return $this->civilite.' '.$this->prenom.' '.mb_strtoupper($this->nom, 'UTF-8');
}
public function getNomCompletStatut()
{
return $this->getNomComplet().' ('.$this->getStatut().')';
}
public function getNomComplet(): string
{
return $this->prenom.' '.mb_strtoupper($this->nom, 'UTF-8');
}
public function eraseCredentials()
{
$this->plainMotDePasse = '';
}
public function getPassword(): ?string
{
return $this->getMotDePasse();
}
public function getRoles()
{
return ['ROLE_ENSEIGNANT'];
}
public function getSalt()
{
return $this->getSel();
}
public function getUsername()
{
return $this->getEmail();
}
public function initMotDePasse()
{
$password = Password::create();
$this->setMotDePasse($password);
return $password;
}
public function setMotDePasse($v, $encode = true, $algorithm = 'sha256')
{
if ($encode) {
$this->setSel(sha1(uniqid((string) time(), true)));
parent::setMotDePasse(hash($algorithm, $v.'{'.$this->getSel().'}'));
} else {
parent::setMotDePasse($v);
}
return $this;
}
public function setPlainMotDePasse($v)
{
$this->plainMotDePasse = $v;
}
public function getPlainMotDePasse()
{
return $this->plainMotDePasse;
}
public function getDemandesIntervention(Criteria $criteria = null, ConnectionInterface $con = null)
{
return parent::getDemandeInterventions($criteria, $con);
}
public function getDemandesInterventionEnCours()
{
$c = DemandeInterventionQuery::create()
->filterByStatutId([
DemandeInterventionStatut::EN_ATTENTE_INTERVENANT,
DemandeInterventionStatut::INTERVENANT_POSITIONNE,
DemandeInterventionStatut::EN_ATTENTE_EVALUATION,
DemandeInterventionStatut::SUSPENDU,
], Criteria::IN)
->orderByDateMaj(Criteria::DESC);
return parent::getDemandeInterventions($c);
}
public function getDemandesInterventionHistorisees($criteria = null, ConnectionInterface $con = null)
{
$c = DemandeInterventionQuery::create()
->filterByStatutId([
DemandeInterventionStatut::TERMINEE,
DemandeInterventionStatut::ANNULEE,
DemandeInterventionStatut::IMPREVU,
], Criteria::IN)
->orderByDateMaj(Criteria::DESC);
return parent::getDemandeInterventions($c);
}
public function getPassedDemandesIntervention($criteria = null, ConnectionInterface $con = null)
{
$c = DemandeInterventionQuery::create()
->filterByStatutId([
DemandeInterventionStatut::TERMINEE,
DemandeInterventionStatut::EN_ATTENTE_EVALUATION,
], Criteria::IN)
->orderByDateMaj(Criteria::DESC);
return parent::getDemandeInterventions($c);
}
/**
* NB: EnseignantStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
*/
public function isDisabled(): bool
{
return in_array($this->getStatutId(), [
EnseignantStatut::SUPPRIME,
EnseignantStatut::SUSPENDU,
]);
}
/**
* NB: EnseignantStatut::EN_ATTENTE_ACTIVATION is not enabled, not disabled.
*/
public function isEnabled(): bool
{
return in_array($this->getStatutId(), [
EnseignantStatut::ACTIF,
EnseignantStatut::MDP_REINITIALISE,
]);
}
public function init(): self
{
return $this
->generateNewUID()
->setStatutId(EnseignantStatut::EN_ATTENTE_ACTIVATION);
}
public function initQuestionnaire(): self
{
return $this
->generateNewUID()
->setStatutId(EnseignantStatut::EN_ATTENTE_ACTIVATION);
}
public function getAnnotations(Criteria $criteria = null, ConnectionInterface $con = null)
{
if (!$criteria) {
$criteria = AnnotationEnseignantQuery::create()->orderByDateCreation(Criteria::DESC);
}
return parent::getAnnotations($criteria, $con);
}
public function hasMotdePasseAndSel(): bool
{
return $this->getMotDePasse() && $this->getSalt();
}
public function getDepartement(): ?Departement
{
return (($etablissement = $this->getEtablissement()) && $ville = $etablissement->getVille()) ? $ville->getDepartement() : null;
}
public function getCoordinateur(): ?Gestionnaire
{
return ($departement = $this->getDepartement()) ? $departement->getCoordinateur() : null;
}
public function getDelegue(): ?Gestionnaire
{
return ($departement = $this->getDepartement()) ? $departement->getDelegue() : null;
}
public function getTelephone(): ?string
{
return parent::getTelephone1();
}
public function logSurvey(): void
{
$surveyStat = new SurveyStats();
$surveyStat->setEnseignant($this)
->setsurveyEnseignant(true);
$surveyStat->save();
}
public function logSurveySEF(): void
{
$surveyStat = new SurveyStats();
$surveyStat->setEnseignant($this)
->setsurveyEnseignantSEF(true);
$surveyStat->save();
}
public function getIdCreerPar(): string
{
return EnseignantTableMap::TABLE_NAME.' '.$this->id;
}
public function getEtablissementsLabels(): string
{
if ($this->getEtablissementNonReference()) {
return 'Etablissement non renseignée: '.$this->getNomEtablissementNonReference().'( '
.($this->getDepartementAutreStructure() ? $this->getDepartementAutreStructure()->getLabel() : '').' )';
}
return $this->getEtablissement() ? $this->getEtablissement()->getLabel() : '';
}
public function getFonctionLabel(): string
{
$fonction = FonctionEnseignantQuery::create()->findOneById($this->getFonctionId());
return $fonction ? $fonction->getLabel() : '';
}
public function getPeriodesLabels(): string
{
$periodes = PeriodeInterventionQuery::create()
->useEnseignantPeriodeInterventionExistsQuery()
->filterByEnseignant($this)
->endUse()
->find();
$periodesLabels = '';
foreach ($periodes as $periode) {
$periodesLabels .= $periode->getLabel().', ';
}
return '' !== $periodesLabels ? substr($periodesLabels, 0, -2) : '';
}
public function getThematiquesLabels(): string
{
$thematiques = TypeInterventionQuery::create()
->useEnseignantTypeInterventionExistsQuery()
->filterByEnseignant($this)
->endUse()
->find();
$thematiquesLabels = '';
foreach ($thematiques as $thematique) {
$thematiquesLabels .= $thematique->getLabel().', ';
}
return '' !== $thematiquesLabels ? substr($thematiquesLabels, 0, -2) : '';
}
public function getActionsHorsMursLabels(): string
{
$actionsHorsMurs = ActionHorsDesMursQuery::create()
->useEnseignantActionHorsDesMursExistsQuery()
->filterByEnseignant($this)
->endUse()
->find();
$actionsHorsMursLabels = '';
foreach ($actionsHorsMurs as $actionHorsMurs) {
$actionsHorsMursLabels .= $actionHorsMurs->getLabel().', ';
}
return '' !== $actionsHorsMursLabels ? substr($actionsHorsMursLabels, 0, -2) : '';
}
/**
* @throws PropelException
*/
public function getActionsHorsMursSefLabels(): string
{
$actionsHorsMursSef = ActionHorsDesMursSefQuery::create()
->useEnseignantActionHorsDesMursSefExistsQuery()
->filterByEnseignantSef($this)
->endUse()
->find();
$actionsHorsMursSefLabels = '';
foreach ($actionsHorsMursSef as $actionHorsMursSef) {
$actionsHorsMursSefLabels .= $actionHorsMursSef->getLabel().', ';
}
return '' !== $actionsHorsMursSefLabels ? substr($actionsHorsMursSefLabels, 0, -2) : '';
}
public function getProvenanceLabel(): string
{
$provenance = ProvenanceEnseignantQuery::create()->findOneById($this->getProvenanceId());
return $this->getProvenanceId() ? $provenance->getLabel() : '';
}
public function getTelephoneLabel(): string
{
return str_replace(' ', '', $this->getTelephone());
}
public function setStatutId($v): self
{
if (EnseignantStatut::ACTIF === $v) {
$this->setDateReactivation(null);
$this->setDureeSuspension(null);
}
return parent::setStatutId($v);
}
public function suspendre(\DateTime $dateReactivation): self
{
if (EnseignantStatut::SUSPENDU === $this->getStatutId()) {
return $this;
}
$this->setStatutId(EnseignantStatut::SUSPENDU);
$this->setDateReactivation($dateReactivation);
$this->setDureeSuspension(($dateReactivation->getTimestamp() - time()) / 86400);
return $this;
}
public function generateNewUID(): self
{
$this->setUid(sha1(uniqid((string) time(), true)));
return $this;
}
public function generateNewTokenReinitialisation(): self
{
$this->setTokenReinitialisation(sha1(uniqid((string) time(), true)));
return $this;
}
public function isDeletable()
{
return EnseignantStatut::SUPPRIME === $this->getStatutId() && !$this->getDemandesIntervention()->count() > 0;
}
/**
* @throws PropelException
*/
public function getCodePostalOfEtablissement(): string
{
return $this->getEtablissement() && $this->getEtablissement()->getVille() ?
$this->getEtablissement()->getVille()->getCodePostal()
: '';
}
/**
* @throws PropelException
*/
public function getDemandeInterventionsWithEvaluationJeuneNotCompleted(): ObjectCollection
{
return DemandeInterventionQuery::create()
->distinct()
->filterByStatutId(DemandeInterventionStatut::EN_ATTENTE_EVALUATION)
->filterByEnseignant($this)
->filterByEvaluationJeuneNotCompleted()
->orderByDate(Criteria::DESC)
->find();
}
}