<?php
namespace App\Controller\GrandPublic;
use App\Entity\AssistantMaternel\AssistantMaternel;
use App\Entity\MAM\MAM;
use App\Entity\OffreAccueil\Categorie;
use App\Entity\Parametrage\EnumModule;
use App\Entity\Parametrage\EnumParametre;
use App\Entity\Referentiel\EnumLieuAccueil;
use App\Entity\Referentiel\EnumRemplissageAccueil;
use App\Entity\Referentiel\FrequenceAccueil;
use App\Entity\Referentiel\JourSemaine;
use App\Entity\Referentiel\LieuAccueil;
use App\Entity\Referentiel\Periode;
use App\Entity\Referentiel\TrancheHoraire;
use App\Service\AssistantMaternel\AssistantMaternelService;
use App\Service\Parametrage\ParametrageService;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class IndexGrandPublicController extends AbstractController
{
const EST_ACTIF = 'est_actif';
const ARR_PLANNING = 'arrPlanning';
const HAS_DEPASSEMENT = 'hasDepassement';
const ASSMAT = 'assmat';
const MAM = 'mam';
const ACTIVE_BUREAU_DISTRIB = 'active_bureau_distrib';
const ACTIVE_ENFANTS_11ANS = 'active_enfants_11ans';
const PREFERENCE = 'preferences_publication';
private $logger;
private $parametrageService;
private $assmatService;
public function __construct(LoggerInterface $logger, ParametrageService $parametrageService, AssistantMaternelService $assmatService)
{
$this->logger = $logger;
$this->parametrageService = $parametrageService;
$this->assmatService = $assmatService;
}
private function verifierActivationModule()
{
if (!$this->parametrageService->estModuleActif(EnumModule::GRANDPUBLIC)) {
throw $this->createAccessDeniedException();
}
}
/**
* Obtient la chaîne du client EFC à utiliser dans les nom des twigs
* @return string la chaîne correspondant au client efc compatible avec les twig customs
*/
private function getClientEFCForTwig()
{
$clientEnv = $this->getParameter('clientEFC'); //cf .env et services.yaml
if ($clientEnv == '' || $clientEnv == 'efc' || $clientEnv == 'efclocal' || $clientEnv == 'efcXX') {
return '';
} else {
return $clientEnv;
}
}
/**
* Point d'entrée grand public
*
* @Route("/grandpublic", name="gp_index")
*/
public function index()
{
$this->verifierActivationModule();
//obtient l'information comme quoi la recherche cartographique est disponible
$isCartoAvailable = $this->parametrageService->getParametre(EnumParametre::URL_CARTO_CONTENT)->getValeur();
$textePresentation = $this->parametrageService->getParametre(EnumParametre::CONTENU_PRES_CARTO)->getValeur();
$urlLogoEntete = $this->parametrageService->getParametre(EnumParametre::URL_LOGO_ENTETE_GRANDPUBLIC)->getValeur();
return $this->render('grand_public/index_' . $this->getClientEFCForTwig() . '.html.twig', [
'isCartoAvailable' => $isCartoAvailable != '',
'textePresentation' => $textePresentation,
'urlLogoEntete' => $urlLogoEntete
]);
}
/**
* Point d'entrée carto
*
* @Route("/grandpublic/carto", name="gp_carto")
*/
public function rechercheCarto()
{
$this->verifierActivationModule();
//récupération de la configuration de cartographie
$urlCartoIframe = $this->parametrageService->getParametre(EnumParametre::URL_CARTO_CONTENT)->getValeur();
$urlCartoJs = $this->parametrageService->getParametre(EnumParametre::URL_CARTO_JS)->getValeur();
$urlLogoEntete = $this->parametrageService->getParametre(EnumParametre::URL_LOGO_ENTETE_GRANDPUBLIC)->getValeur();
return $this->render('grand_public/carto/evermaps.html.twig', [
'urlCartoIframe' => $urlCartoIframe,
'urlCartoJs' => $urlCartoJs,
'urlLogoEntete' => $urlLogoEntete
]);
}
/**
* @Route("/grandpublic/mentions_legales/", name="gp_mentions_legales")
*/
public function mentionsLegales()
{
$this->verifierActivationModule();
$urlLogoEntete = $this->parametrageService->getParametre(EnumParametre::URL_LOGO_ENTETE_GRANDPUBLIC)->getValeur();
$content = $this->parametrageService->getParametre(EnumParametre::CONTENU_MENTIONS_LEGALES_GRANDPUBLIC)->getValeur();
return $this->render('grand_public/commun/mentions_legales.html.twig', [
'urlLogoEntete' => $urlLogoEntete,
'content' => $content
]);
}
/**
* @Route("/grandpublic/protection_donnees/", name="gp_protection_donnees")
*/
public function protectionDonnees()
{
$this->verifierActivationModule();
$urlLogoEntete = $this->parametrageService->getParametre(EnumParametre::URL_LOGO_ENTETE_GRANDPUBLIC)->getValeur();
$num = $this->getClientEFCForTwig();
if ($num == '') {
return $this->mentionsLegales();
}
return $this->render('grand_public/commun/protection_donnees_' . $num . '.html.twig', [
'urlLogoEntete' => $urlLogoEntete
]);
}
/**
* @Route("/grandpublic/accessibilite/", name="gp_accessibilite")
*/
public function accessibilite()
{
$this->verifierActivationModule();
$urlLogoEntete = $this->parametrageService->getParametre(EnumParametre::URL_LOGO_ENTETE_GRANDPUBLIC)->getValeur();
$num = $this->getClientEFCForTwig();
if ($num == '') {
$num = 'efc';
}
return $this->render('grand_public/commun/accessibilite_' . $num . '.html.twig', [
'urlLogoEntete' => $urlLogoEntete
]);
}
/**
* Afficher la modale en lecture seule de la fiche d'une MAM
*
* @Route("/grandpublic/mam/fiche/{idFonctionnel}", defaults={"idFonctionnel"=0}, name="mod_mam_fiche_gp")
*/
public function voirFicheMamLectureSeule($idFonctionnel)
{
$this->verifierActivationModule();
if (is_null($idFonctionnel)) {
throw new InvalidArgumentException("Le paramètre id est obligatoire.");
}
$active_bureau_distrib = $this->parametrageService->getParametre(EnumParametre::ACTIVE_BUREAU_DISTRIBUTEUR)->getValeur();
$em = $this->getDoctrine()->getManager();
$repo_mam = $em->getRepository(MAM::class);
$mam = $repo_mam->findOneBy(['id_fonctionnel' => $idFonctionnel]);
if (!$mam) {
throw $this->createNotFoundException('Cette MAM n\'existe pas.');
}
$preferences_publication = $mam->getPreferencesPublication();
$presentation_mam = $mam->getPresentationMAM();
$active_atypique = $this->parametrageService->getParametre(EnumParametre::ACTIVE_OA_ATYPIQUE)->getValeur();
$active_handicap = $this->parametrageService->getParametre(EnumParametre::ACTIVE_OA_HANDICAP)->getValeur();
$active_enfants_11ans = $this->parametrageService->getParametre(EnumParametre::ACTIVE_ENFANTS_11_ANS)->getValeur();
return $this->render('offre_accueil/mam/_mod_index.html.twig', [
self::MAM => $mam,
'preferences_publication' => $preferences_publication,
'presentation_mam' => $presentation_mam,
'active_atypique' => $active_atypique,
'active_handicap' => $active_handicap,
'lecture_seule' => true,
self::ACTIVE_BUREAU_DISTRIB => $active_bureau_distrib,
'photos' => $mam->getPhotosValidees(),
self::ACTIVE_ENFANTS_11ANS => $active_enfants_11ans
]);
}
/**
* obtient la vue partielle pour représenter l'offre d'accueil grand public
* d'une assmat, selon son lieu d'accueil
* @param type $assmat
* @param type $idLieuAccueil
* @return type
*/
private function offreAccueilAssmatByLieu($assmat, $idLieuAccueil)
{
$this->verifierActivationModule();
$edition = false;
$active_bureau_distrib = $this->parametrageService->getParametre(EnumParametre::ACTIVE_BUREAU_DISTRIBUTEUR)->getValeur();
$active_atypique = $this->parametrageService->getParametre(EnumParametre::ACTIVE_OA_ATYPIQUE)->getValeur();
$active_handicap = $this->parametrageService->getParametre(EnumParametre::ACTIVE_OA_HANDICAP)->getValeur();
$active_enfants_11ans = $this->parametrageService->getParametre(EnumParametre::ACTIVE_ENFANTS_11_ANS)->getValeur();
$preferences_publication = $assmat->getPreferencesPublication();
$presentation_assmat = $assmat->getPresentationAssmat();
$dispos_prev_assmat = $assmat->getDisposPrev();
$em = $this->getDoctrine()->getManager();
$dispos_vacances_assmat = $em->createQueryBuilder()
->from(\App\Entity\OffreAccueil\PeriodeVacances::class, 'p')
->select('p')
->join('p.semaines', 's')
->addSelect('s')
->join('s.dispos', 'd')
->addSelect('d')
->join('d.assmat', 'a')
->andWhere('a = :assmat')
->setParameter('assmat', $assmat)
->getQuery()
->getResult();
$categoriesCadreAccueil = $em->getRepository(Categorie::class)->categoriesOngletAvecSaisieAssmat(Categorie::ONGLET_CADRE_ACCUEIL, $assmat);
$categoriesTarifs = $em->getRepository(Categorie::class)->categoriesOngletAvecSaisieAssmat(Categorie::ONGLET_TARIFS, $assmat);
$listeJours = $em->getRepository(JourSemaine::class)->findBy(array(self::EST_ACTIF => true), array('id' => 'ASC'));
$listeTranches = $em->getRepository(TrancheHoraire::class)->findBy(array(self::EST_ACTIF => true), array('id' => 'ASC'));
$listeFrequences = $em->getRepository(FrequenceAccueil::class)->findBy(array(self::EST_ACTIF => true));
$tranchesAge = $assmat->getTranchesAgeAgreesByIdLieu($idLieuAccueil);
$lieuAccueil = $em->getRepository(LieuAccueil::class)->findOneById($idLieuAccueil);
$dispos_public_assmat = $assmat->getDisposPublicByLieuAccueil($lieuAccueil);
//gère le conteneur d'édition de l'offre d'accueil de l'assmat
return $this->render('offre_accueil/assistant_maternel/_mod_index.html.twig', [
'choix' => 'choix',
self::ASSMAT => $assmat,
self::ACTIVE_BUREAU_DISTRIB => $active_bureau_distrib,
'edition' => $edition,
'idLieuAccueil' => $idLieuAccueil,
'categoriesCadreAccueil' => $categoriesCadreAccueil,
'categoriesTarifs' => $categoriesTarifs,
'preferences_publication' => $preferences_publication,
'presentation_assmat' => $presentation_assmat,
'active_atypique' => $active_atypique,
'active_handicap' => $active_handicap,
'dispos_prev_assmat' => $dispos_prev_assmat,
'dispos_public_assmat' => $dispos_public_assmat,
'dispos_vacances_assmat' => $dispos_vacances_assmat,
'liste_jours' => $listeJours,
'liste_tranches' => $listeTranches,
'liste_frequences' => $listeFrequences,
'tranches_age_assmat' => $tranchesAge,
'photos' => $assmat->getPhotosValidees(),
self::ACTIVE_ENFANTS_11ANS => $active_enfants_11ans
]);
}
/**
* @Route("/grandpublic/asm/oa/{idFonctionnel}/{idLieuAccueil}", defaults={"idFonctionnel"=0, "idLieuAccueil"=0 }, name="mod_assmat_oa_gp")
*/
public function offreAccueilAssmat($idFonctionnel, $idLieuAccueil)
{
$this->verifierActivationModule();
if (is_null($idFonctionnel)) {
throw new InvalidArgumentException("Le paramètre id est obligatoire.");
}
$em = $this->getDoctrine()->getManager();
$repo_assmat = $em->getRepository(AssistantMaternel::class);
$assmat = $repo_assmat->findOneBy(['id_fonctionnel' => $idFonctionnel]);
if (!$assmat) {
throw $this->createNotFoundException('Cet assistant maternel n\'existe pas.');
}
if ($idLieuAccueil == 0) {
$lieuxAggrees = $assmat->getLieuxAccueilAgrees();
$nbLieux = count($lieuxAggrees);
if ($nbLieux == 0) {
throw new InvalidArgumentException("L'asssistant maternel n'a aucun lieu d'accueil aggréé.");
} else if ($nbLieux > 1) {
//par défaut, en cas de double agrément, on fait accéer à l'offre en MAM
$idLieuAccueil = EnumLieuAccueil::MAM;
} else {
$idLieuAccueil = reset($lieuxAggrees)->getId();
}
}
return $this->offreAccueilAssmatByLieu($assmat, $idLieuAccueil);
}
/**
* Afficher la modale en lecture seule de la fiche d'un Assmat
*
* @Route("/grandpublic/asm/fiche/{id}", defaults={"id"=0}, name="mod_assmat_fiche_gp")
*/
public function voirFicheAssmatLectureSeule($id)
{
$this->verifierActivationModule();
if (is_null($id)) {
throw new InvalidArgumentException("Le paramètre id est obligatoire.");
}
$active_bureau_distrib = $this->parametrageService->getParametre(EnumParametre::ACTIVE_BUREAU_DISTRIBUTEUR)->getValeur();
$active_coche_nuit = $this->parametrageService->getParametre(EnumParametre::ACTIVE_GERE_ACCUEIL_NUIT)->getValeur();
$active_enfants_11ans = $this->parametrageService->getParametre(EnumParametre::ACTIVE_ENFANTS_11_ANS)->getValeur();
$em = $this->getDoctrine()->getManager();
$listePeriodes = $em->getRepository(Periode::class)->findBy(array(self::EST_ACTIF => true), array('ordre' => 'ASC'));
$listeJours = $em->getRepository(JourSemaine::class)->findBy(array(self::EST_ACTIF => true), array('id' => 'ASC'));
$listeTranches = $em->getRepository(TrancheHoraire::class)->findBy(array(self::EST_ACTIF => true), array('id' => 'ASC'));
$listeFrequences = $em->getRepository(FrequenceAccueil::class)->findBy(array(self::EST_ACTIF => true));
$repo_assmat = $em->getRepository(AssistantMaternel::class);
$assmat = $repo_assmat->find($id);
if (!$assmat) {
throw $this->createNotFoundException('Cet assistant maternel n\'existe pas.');
}
$recap_accueil = $this->assmatService->getRecapAccueil($assmat); //affichage planning
return $this->render('assistant_maternel/_mod_fiche_lecture_seule.html.twig', [
self::ASSMAT => $assmat,
self::ARR_PLANNING => $recap_accueil[self::ARR_PLANNING],
self::HAS_DEPASSEMENT => $recap_accueil[self::HAS_DEPASSEMENT],
'liste_enfants_assmat_gardes' => $recap_accueil['listeEnfantsAssmatGardes'],
'liste_enfants' => $recap_accueil['listeEnfants'],
'liste_lieux_accueils' => $recap_accueil['listeLieux'],
'liste_types_agrem' => $recap_accueil['listeTypes'],
'liste_tranches_agrem' => $recap_accueil['listeTranchesAge'],
'liste_periodes' => $listePeriodes,
'liste_jours' => $listeJours,
'liste_tranches' => $listeTranches,
'liste_frequences' => $listeFrequences,
'liste_remplissages' => EnumRemplissageAccueil::GetRemplissageAccueilClassName(),
self::ACTIVE_BUREAU_DISTRIB => $active_bureau_distrib,
'active_coche_nuit' => $active_coche_nuit,
'allow_link_enfant' => false,
'lecture_seule' => true,
self::ACTIVE_ENFANTS_11ANS => $active_enfants_11ans,
]);
}
}