src/Controller/InscriptionController.php line 334

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Model\Document;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Pimcore\Model\WebsiteSetting;
  12. use App\Form\ExpertiseFormType;
  13. use App\Form\InscriptionFormType;
  14. use App\Form\ContactModalFormType;
  15. use Pimcore\Mail;
  16. use Carbon\Carbon;
  17. use Pimcore\Model\DataObject\Folder;
  18. use App\Service\Akimedia;
  19. use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse;
  20. use GuzzleHttp\Client;
  21. use Pimcore\Tool\Session;
  22. class InscriptionController extends FrontendController
  23. {
  24.     /**
  25.      * @Template
  26.      * @param Request $request
  27.      * @route("/{_locale}/inscription-centre/{id}", name="inscriptionCentre",methods={"GET", "POST"})
  28.      * @return \Symfony\Component\HttpFoundation\Response
  29.      *
  30.      */
  31.     public function inscriptionCentreAction(Request $request\Symfony\Contracts\Translation\TranslatorInterface $translator)
  32.     {
  33.         $session $request->getSession();
  34.         $CentreId $request->get('id');
  35.         $token $session->get('akimedia-token');
  36.         $errorMessage "";
  37.         if(!$token){
  38.             $token Akimedia::login();
  39.             $session->set("akimedia-token"$token);
  40.         }
  41.         $dateComponents getdate();
  42.         $month date("n");
  43.         $year $dateComponents['year'];
  44.         for($i=0;$i<6;$i++){
  45.             $currentMonth $month+$i;
  46.             if($currentMonth>12):
  47.                 $m $currentMonth-12;
  48.                 $y $year+1;
  49.             else:
  50.                 $m $currentMonth;
  51.                 $y $year;
  52.             endif;
  53.             $cal[$i] = $this->build_calendar($m,$y,$CentreId,$translator);
  54.         }
  55.         // to comment start
  56.         $calJuillet $this->build_calendar($month,$year,$CentreId,$translator);
  57.         if($month >= 11){
  58.             if($month==12){
  59.                 $calAout $this->build_calendar(1,$year+1,$CentreId,$translator);
  60.                 $calSeptembre $this->build_calendar(2,$year+1,$CentreId,$translator);
  61.             }else{
  62.                 $calAout $this->build_calendar($month+1,$year,$CentreId,$translator);
  63.                 $calSeptembre $this->build_calendar(1,$year+1,$CentreId,$translator);
  64.             }
  65.         }else{
  66.             $calAout $this->build_calendar($month+1,$year,$CentreId,$translator);
  67.             $calSeptembre $this->build_calendar($month+2,$year,$CentreId,$translator);
  68.         }
  69.         $tomorrow Carbon::now()->addDay();
  70.         $date['weekStartDate'] = $tomorrow->startOfWeek()->format('d/m/Y');
  71.         $date['weekEndDate'] = $tomorrow->endOfWeek()->format('d/m/Y');
  72.         $yearAllowed = [];
  73.         $yearAllowed['year'] = 18;
  74.         $settingYearAllowed WebsiteSetting::getByName('InscriptionYearAllowed');
  75.         if($settingYearAllowed) {
  76.             $yearAllowed['max'] = Carbon::now()->subYears($settingYearAllowed->getData());
  77.             $yearAllowed['year'] = $settingYearAllowed->getData();
  78.         } else {
  79.             $yearAllowed['max'] = Carbon::now()->subYears($yearAllowed['year']);
  80.         }
  81.         $yearAllowed['min'] = Carbon::now()->subYears(130);
  82.         $horaires Akimedia::getSiteAvailabilities($request$CentreId);
  83.         $centre Akimedia::getSiteInfos($request$CentreId);
  84.         //dd($centre);
  85.         if ($request->isMethod("POST")) {
  86.             $data = [
  87.                 'datenaissance' => $request->get("dtenaissance"),
  88.                 'token' => uniqid(),
  89.                 'date' => $request->get("date"),
  90.                 'heure' => $request->get("heure"),
  91.                 'firstname' => $request->get("firstname"),
  92.                 'lastname' => $request->get("lastname"),
  93.                 'email' => $request->get("email"),
  94.                 'phone' => $request->get("phone"),
  95.                 'dejaDonnePlasma' => $request->get("alreadyPlasma"),
  96.                 'dejaDonneSang' => $request->get("alreadyBlood"),
  97.                 'type' => 'plasma',
  98.             ];
  99.             $return Akimedia::sendIncriptionSite($request$data$request->get("akimedia-centre"));
  100.             if($return !== true){
  101.                 $errorMessage $return;
  102.             }else{
  103.                 // redirect vers merci
  104.                 return $this->redirectToRoute("merci");
  105.             }
  106.         }
  107.         return $this->render('inscription/inscription-centre.html.twig',[
  108.             "centre" => $centre,
  109.             "dates" => $horaires,
  110.             "calendriers" => $cal,
  111.             "Juillet" => $calJuillet,
  112.             "Aout" => $calAout,
  113.             "Septembre" => $calSeptembre,
  114.             "errorMessage" => $errorMessage,
  115.             "date" => $date,
  116.             "yearAllowed" => $yearAllowed
  117.         ]);
  118.     }
  119.     /**
  120.      * @Template
  121.      * @param Request $request
  122.      * @return \Symfony\Component\HttpFoundation\Response
  123.      *
  124.      */
  125.     #[Route(path:[
  126.         'fr' => '/{_locale}/merci',
  127.         'de' => '/{_locale}/danke',
  128.         'nl' => '/{_locale}/bedankt',
  129.     ], name'merci')]
  130.     public function merciAction(Request $request)
  131.     {
  132.         return $this->render('inscription/merci.html.twig',[
  133.         ]);
  134.     }
  135.     //new full akimedia logic
  136.     /**
  137.      * @Route("gethorairecentreakimedia", name="getHoraireCentreAkimedia")
  138.      *
  139.      */
  140.     public function gethorairecentreakimediaAction(Request $request\Symfony\Contracts\Translation\TranslatorInterface $translator)
  141.     {
  142.         $session $request->getSession();
  143.         $token $session->get('akimedia-token');
  144.         if(!$token){
  145.             $token Akimedia::login();
  146.             $session->set('akimedia-token'$token);
  147.         }
  148.         $lang $request->get('lang');
  149.         $CentreId $request->get("centreid");
  150.         $GetDate $request->get("date");
  151.         $date $GetDate " 00:00";
  152.         $date1 $GetDate " 23:59";
  153.         $horairesResults Akimedia::getSiteHorairesByDate($request$CentreId);
  154.         $horaires $horairesResults["plages"];
  155.         $objectif $horairesResults["objectif_plasma_atteint"];
  156.         if($objectif){
  157.             $HoraireControle "<span style='background:#fff6ee; border:1px solid #F6A507; padding:5px 10px;'>".$translator->trans('Nos objectifs sont atteints pour ce jour.')."</span>";
  158.         }elseif ($horaires && count($horaires) > 0) {
  159.             $HoraireControle '';
  160.             $HoraireList '';
  161.             $HoraireControle .= '<div>';
  162.             $HoraireControle .= '<label class="control-label">Choisissez votre horaire de départ</label>';
  163.             $count 1;
  164.             foreach ($horaires as $h) {
  165.                 if (strtotime($GetDate." ".$h['horaire']) >= strtotime($date) && strtotime($GetDate." ".$h['horaire']) <= strtotime($date1)) {
  166.                     if ($h['horaire']) {
  167.                         $horaire_i 1;
  168.                         $PlaceLibrre $h['available'];
  169.                         if($PlaceLibrre <= 0){
  170.                             continue;
  171.                         }
  172.                         $now Carbon::now();
  173.                         $dateCalendar Carbon::parse($GetDate." ".$h['horaire']);
  174.                         $cuurentTime date($h['horaire']);
  175.                         if($now->gt($dateCalendar)){
  176.                             continue;
  177.                         }
  178.                         $checked '';
  179.                         if ($PlaceLibrre <= 0) {
  180.                             $checked ' disabled ';
  181.                         }
  182.                         if ($PlaceLibrre <= 0) {
  183.                             $class_state "is-disabled";
  184.                         } else {
  185.                             $class_state "is-active";
  186.                         }
  187.                         $HoraireList .= '<div class="uk-width-1-1 schedule-item-container"><div class="schedule-item ' $class_state '">
  188.                             <label for="Hdeb' $horaire_i '">' $cuurentTime ' <small style="    font-size: 15px;">(' $PlaceLibrre ' ' $translator->trans('places restantes', [], null$lang) . ')';
  189.                         $HoraireList .='</small></label>';
  190.                         if ($PlaceLibrre 0) {
  191.                             $HoraireList .= '<input data-id="' $GetDate '" type="radio" required name="inscription"
  192.                               value="' $cuurentTime '" ' $checked ' ' '
  193.                               id="Hdeb' $horaire_i '" class="uk-radio" />';
  194.                         }
  195.                         $HoraireList .= '</div></div>';
  196.                         if ($count == 0):
  197.                             $HoraireList .= '</div></div></li><li><div><div class="uk-grid-small" uk-grid>';
  198.                         endif;
  199.                         $horaire_i++;
  200.                         $count++;
  201.                     }
  202.                 }
  203.             }
  204.             if($HoraireList){
  205.                 $HoraireControle .= '<div uk-slider="finite: true;">
  206.                                                     <div class="uk-position-relative">
  207.                                                         <div class="uk-slider-container uk-light">
  208.                                                             <ul class="uk-slider-items uk-child-width-1-2@s uk-grid-small">
  209.                                                                 <li><div><div class="uk-grid-small" uk-grid>';
  210.                 $HoraireControle .= $HoraireList;
  211.                 $HoraireControle .= '</div></div></li></ul></div>';
  212.                 $HoraireControle .= '<div class="uk-hidden@s uk-light">
  213.                                                             <a class="uk-position-center-left uk-position-small" href="#" uk-slidenav-previous uk-slider-item="previous"></a>
  214.                                                             <a class="uk-position-center-right uk-position-small" href="#" uk-slidenav-next uk-slider-item="next"></a>
  215.                                                         </div>
  216.                                                         <div class="uk-visible@s">
  217.                                                             <a class="uk-position-center-left-out uk-position-small" href="#" uk-slidenav-previous uk-slider-item="previous"></a>
  218.                                                             <a class="uk-position-center-right-out uk-position-small" href="#" uk-slidenav-next uk-slider-item="next"></a>
  219.                                                         </div>
  220.                                                     </div>
  221.                                                     <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
  222.                                                 </div>';
  223.                 $HoraireControle .= '</div>';
  224.             }else{
  225.                 $HoraireControle "<span style='color: red'>".$translator->trans("Nous n’avons pas de possibilités de rendez-vous pour la date choisie.")."</span>";
  226.             }
  227.         } else {
  228.             $HoraireControle "<span style='color: red'>".$translator->trans("Nous n’avons pas de possibilités de rendez-vous pour le date choisie.")."</span>";
  229.         }
  230.         $msg2 "ok";
  231.         $response = array('type' => 'succes''msg' => $HoraireControle'resultat' => $CentreId ' ' $date'msg2' => $msg2);
  232.         return new JsonResponse($response);
  233.     }
  234.     /**
  235.      * @Template
  236.      *
  237.      * @param Request $request
  238.      *
  239.      * @param DataObject $object
  240.      * @Route("/{_locale}/inscription-plasma", name="formEligibleInscription")
  241.      *
  242.      * @return response
  243.      *
  244.      */
  245.     public function formEligibleInscriptionAction(Request $request) {
  246.         /*
  247.         if(WebsiteSetting::getByName('akimediaActivate')) {
  248.             $id = $request->get('id');
  249.             if($this->editmode){
  250.                 $id = 1;
  251.             }
  252.             if($id){
  253.                 return $this->render('inscription/form-eligibilite-inscription.html.twig',[
  254.                     'centre' => $id
  255.                 ]);
  256.             }else{
  257.                 if($this->document->getProperty('listeCentresPlasma')) {
  258.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  259.                 } else {
  260.                     return $this->redirect('/');
  261.                 }
  262.             }
  263.         } else {
  264.             $session = $request->getSession();
  265.             if($request->get('centre') && $request->get('centre')){
  266.                 $session->set('centre', $request->get('centre'));
  267.                 $url = explode("?", $_SERVER['REQUEST_URI']);
  268.                 return $this->redirect($url[0]);
  269.             }
  270.             if($this->editmode){
  271.                 $session->set('centre', 2559);
  272.             }
  273.             if($session->get('centre')>0){
  274.                 return $this->render('inscription/form-eligibilite-inscription.html.twig',[
  275.                     'centre' => $session->get('centre')
  276.                 ]);
  277.             }else{
  278.                 if($this->document->getProperty('listeCentresPlasma')) {
  279.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  280.                 } else {
  281.                     return $this->redirect('/'. $request->getLocale());
  282.                 }
  283.             }
  284.         }
  285.         */
  286.         $id $request->get('id');
  287.         if(!$id) {
  288.             //Recherche du param envoyé au snippet
  289.             $id $request->attributes->get('id');
  290.         }
  291.         $session $request->getSession();
  292.         $session->set('centre'$request->get('id'));
  293.         if($this->editmode){
  294.             $id 1;
  295.         }
  296.         if($id){
  297.             return $this->render('snippets/form-eligibilite-inscription.html.twig',[
  298.                 'centre' => $id
  299.             ]);
  300.         }else{
  301.             if($this->document->getProperty('listeCentresPlasma')) {
  302.                 return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  303.             } else {
  304.                 return $this->redirect('/');
  305.             }
  306.         }
  307.     }
  308.     /**
  309.      * @Template
  310.      * @param Request $request
  311.      * @param DataObject $object
  312.      * @return response
  313.      *
  314.      */
  315.     public function defaultContactAction(Request $request)
  316.     {
  317.         if(!WebsiteSetting::getByName('akimediaActivate')) {
  318.             $centres null// On ne récupère plus plusieurs centres mais un seul
  319.             //Formulaire d'inscription
  320.             $formStatus false;
  321.             $ddsHoraires false;
  322.             $centre false;
  323.             $lang $request->getLocale();
  324.             $session $request->getSession();
  325.             $CentreId $session->get('centre');
  326.             $token $session->get('akimedia-token');
  327.             $errorMessage "";
  328.             if(!$token){
  329.                 $token Akimedia::login();
  330.                 $session->set("akimedia-token"$token);
  331.             }
  332.             $centre Akimedia::getSiteInfos($request$CentreId);
  333.             if(!$centre) {
  334.                 if($this->document->getProperty('listeCentresPlasma')) {
  335.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  336.                 } else {
  337.                     return $this->redirect('/'$lang);
  338.                 }
  339.             }
  340.         } else {
  341.             $session $request->getSession();
  342.             $CentreId $session->get('centre');
  343.             //Formulaire d'inscription
  344.             $formStatus false;
  345.             $ddsHoraires false;
  346.             $centre false;
  347.             $lang $request->getLocale();
  348.             if(strpos(WebsiteSetting::getByName('horairesCentresApi')->getData(), 'dds') !== false) {
  349.                 $ddsHoraires true;
  350.                 $centres null// On ne récupère plus plusieurs centres mais un seul
  351.                 //gestion guzzle
  352.                 $client = new Client();
  353.                 $response $client->request('POST'"https://www.donneurdesang.be/"$request->getLocale() ."/api/centres-by-provinces", [
  354.                     'headers' => [
  355.                         'Content-Type' => 'application/x-www-form-urlencoded',
  356.                     ]
  357.                 ]);
  358.                 $results json_decode($response->getBody(), true);
  359.                 $apiCentres $results;
  360.                 //Boucle pour récupérer le bon centre
  361.                 foreach($apiCentres as $apiCentre) {
  362.                     if($apiCentre["o_id"] == $CentreId) {
  363.                         $centre $apiCentre;
  364.                         continue;
  365.                     }
  366.                 }
  367.             } else {
  368.                 $centres = new DataObject\Centres\Listing();
  369.                 $centres->load();
  370.             }
  371.             //Suppression des paramètres et redirect
  372.             if($request->get('centre') && $request->get('centre')){
  373.                 $session->set('centre'$request->get('centre'));
  374.                 $url explode("?"$_SERVER['REQUEST_URI']);
  375.                 return $this->redirect($url[0]);
  376.             }
  377.             if($this->editmode){
  378.                 $session->set('centre'2559);
  379.             }
  380.             if(!$centre) {
  381.                 if($this->document->getProperty('listeCentresPlasma')) {
  382.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  383.                 } else {
  384.                     return $this->redirect('/'$lang);
  385.                 }
  386.             }
  387.         }
  388.         //////////////////////////////////////////////////
  389.         // initialize form and handle request data
  390.         $formContact $this->createForm(InscriptionFormType::class, null);
  391.         $formContact->handleRequest($request);
  392.         // On vérifie si un POST a bien été effectué et donc si le formulaire a été envoyé
  393.         if ($formContact->isSubmitted() && $formContact->isValid()) {
  394.             $data $formContact->getData();
  395.             $email                 $data['email'];
  396.             $phone                 $data['phone'];
  397.             $firstname             $data['firstname'];
  398.             $lastname             $data['lastname'];
  399.             $birthday             $data['birthday'];
  400.             $sang                 $data['sang'];
  401.             $plasma                $data['plasma'];
  402.             $gdpr                 $data['gdpr'];
  403.             $data['centreId']    = $request->get("inscription_form_centre");
  404.             if(WebsiteSetting::getByName('akimediaActivate')) {
  405.                 if($ddsHoraires) {
  406.                     //$centre = DataObject\Centres::getByCodeCentre($data['centreId']);
  407.                     $convertCentre DataObject\Centres::getByCodeCentre($centre['codeCentre']);
  408.                     $convertCentre $convertCentre->load();
  409.                     $data['centre'] = $convertCentre[0];
  410.                 } else {
  411.                     $centre DataObject\Centres::getByAkimediaId($data['centreId']);
  412.                     $centre $centre->load();
  413.                     $data['centre'] = $centre[0];
  414.                 }
  415.             } else {
  416.                 $centreObj DataObject\Centres::getByAkimediaId($data['centreId']);
  417.                 $centreObj $centreObj->load();
  418.                 $data['centre'] = $centreObj[0];
  419.             }
  420.             if($email != $request->get("inscription_form_confirmation")){
  421.                 $viewContactForm $formContact->createView();
  422.                 return[
  423.                     'centre' => $centre// Ajout Greg pour reprendre la data depuis dds
  424.                     'centres' => $centres,
  425.                     'form' => $viewContactForm,
  426.                     'formStatus' => $formStatus,
  427.                     'error' => true,
  428.                     'lang' => $lang
  429.                 ];
  430.             }
  431.             // On vérifie que tous les champs sont bien complétés
  432.             if($firstname !== "" && $lastname !== "" && $email !== ""){
  433.                 // reCaptcha verification
  434.                 $recaptchaKeyPrivate WebsiteSetting::getByName('recaptchaKeyPrivate');
  435.                 $recaptcha_url 'https://www.google.com/recaptcha/api/siteverify';
  436.                 $recaptcha_response $data['recaptcha'];
  437.                 $recaptcha file_get_contents($recaptcha_url '?secret=' $recaptchaKeyPrivate->getData() . '&response=' $recaptcha_response);
  438.                 $recaptcha json_decode($recaptcha);
  439.                 if ($recaptcha->success)
  440.                 {
  441.                     if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  442.                         // condition pour changer le folder d'enregistrement de concours dans les assets
  443.                         $folderPath Folder::getByPath("/Inscription");
  444.                         if(!$folderPath){
  445.                             $folderPath = new Folder();
  446.                             $folderPath->setKey("Inscription");
  447.                             $folderPath->setParentId(1);
  448.                             $folderPath->save();
  449.                         }
  450.                         if($this->document->getProperty('objectFormFolder')) {
  451.                             $folderPath Folder::getByPath($this->document->getProperty('objectFormFolder'));
  452.                         }
  453.                         $contact = new DataObject\Inscription();
  454.                         $contact->setLastname($lastname);
  455.                         $contact->setFirstname($firstname);
  456.                         $contact->setEmail($email);
  457.                         $contact->setPhone($phone);
  458.                         $contact->setBirthday($birthday);
  459.                         $contact->setSang($sang);
  460.                         $contact->setPlasma($plasma);
  461.                         $contact->setGdpr($gdpr);
  462.                         $contact->setCentre($data['centre']);
  463.                         /*$contact->setLang($request->getLocale());*/
  464.                         $contact->setKey($email.'_'.uniqid());
  465.                         $contact->setParent($folderPath);
  466.                         $contact->setPublished(true);
  467.                         $contact->save();
  468.                         //email au centre
  469.                         // JDS On envoie à l'adresse définie dans les settings et plus vers le centre comme c'était demandé initialement.
  470.                         $mail = new \Pimcore\Mail();
  471.                         $mail->setDocument('/emails/inscription');
  472.                         //$mail->to($data['centre']->getEmail());
  473.                         $mail->setParams($data);
  474.                         $mail->send();
  475.                         //Copie au visiteur
  476.                         $mail = new \Pimcore\Mail();
  477.                         $mail->setDocument('/emails/'.$request->getLocale().'/inscription-confirmation');
  478.                         $mail->to($email);
  479.                         $mail->setParams($data);
  480.                         $mail->send();
  481.                         $formStatus 'success';
  482.                     }else{
  483.                         $formStatus 'invalid-email';
  484.                     }
  485.                 }else{
  486.                     $formStatus 'robot';
  487.                 }
  488.             }else{
  489.                 $formStatus 'required-empty';
  490.             }
  491.         }
  492.         $viewContactForm $formContact->createView();
  493.         return $this->render('inscription/default.html.twig',[
  494.             'centre' => $centre// Ajout Greg pour reprendre la data depuis dds
  495.             'centres' => $centres,
  496.             'form' => $viewContactForm,
  497.             'formStatus' => $formStatus,
  498.             'ddsHoraires' => $ddsHoraires,
  499.             'error' => false,
  500.             'lang' => $lang
  501.         ]);
  502.     }
  503.     /**
  504.      * @Template
  505.      * @param Request $request
  506.      * @param DataObject $object
  507.      * @return response
  508.      */
  509.     public function fastContactAction(Request $request)
  510.     {
  511.         //Formulaire d'inscription
  512.         $formStatus false;
  513.         $ddsHoraires false;
  514.         $centres = new DataObject\Centres\Listing();
  515.         $centres->load();
  516.         if(strpos(WebsiteSetting::getByName('horairesCentresApi')->getData(), 'dds') !== false) {
  517.             $ddsHoraires true;
  518.         }
  519.         // initialize form and handle request data
  520.         $formContact $this->createForm(InscriptionFormType::class, null);
  521.         $formContact->handleRequest($request);
  522.         // On vérifie si un POST a bien été effectué et donc si le formulaire a été envoyé
  523.         if ($formContact->isSubmitted() && $formContact->isValid()) {
  524.             $data $formContact->getData();
  525.             $email                 $data['email'];
  526.             $phone                 $data['phone'];
  527.             $firstname             $data['firstname'];
  528.             $lastname             $data['lastname'];
  529.             $birthday             $data['birthday'];
  530.             $sang                 $data['sang'];
  531.             $plasma                $data['plasma'];
  532.             $gdpr                 $data['gdpr'];
  533.             $data['centreId']    = $request->get("inscription_form_centre");
  534.             if($ddsHoraires) {
  535.                 $centre DataObject\Centres::getByCodeCentre($data['centreId']);
  536.             } else {
  537.                 $centre DataObject\Centres::getByAkimediaId($data['centreId']);
  538.             }
  539.             $centre $centre->load();
  540.             $data['centre'] = $centre[0];
  541.             if($email != $request->get("inscription_form_confirmation")){
  542.                 $viewContactForm $formContact->createView();
  543.                 return $this->render('inscription/fast-inscription.html.twig',[
  544.                     'centres' => $centres,
  545.                     'form' => $viewContactForm,
  546.                     'formStatus' => $formStatus,
  547.                     'ddsHoraires' => $ddsHoraires,
  548.                     'error' => true,
  549.                 ]);
  550.             }
  551.             // On vérifie que tous les champs sont bien complétés
  552.             if($firstname !== "" && $lastname !== "" && $email !== ""){
  553.                 // reCaptcha verification
  554.                 $recaptchaKeyPrivate WebsiteSetting::getByName('recaptchaKeyPrivate');
  555.                 $recaptcha_url 'https://www.google.com/recaptcha/api/siteverify';
  556.                 $recaptcha_response $data['recaptcha'];
  557.                 $recaptcha file_get_contents($recaptcha_url '?secret=' $recaptchaKeyPrivate->getData() . '&response=' $recaptcha_response);
  558.                 $recaptcha json_decode($recaptcha);
  559.                 if ($recaptcha->success)
  560.                 {
  561.                     if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  562.                         // condition pour changer le folder d'enregistrement de concours dans les assets
  563.                         $folderPath Folder::getByPath("/Inscription");
  564.                         if(!$folderPath){
  565.                             $folderPath = new Folder();
  566.                             $folderPath->setKey("Inscription");
  567.                             $folderPath->setParentId(1);
  568.                             $folderPath->save();
  569.                         }
  570.                         if($this->document->getProperty('objectFormFolder')) {
  571.                             $folderPath Folder::getByPath($this->document->getProperty('objectFormFolder'));
  572.                         }
  573.                         $contact = new DataObject\Inscription();
  574.                         $contact->setLastname($lastname);
  575.                         $contact->setFirstname($firstname);
  576.                         $contact->setEmail($email);
  577.                         $contact->setPhone($phone);
  578.                         $contact->setBirthday($birthday);
  579.                         $contact->setSang($sang);
  580.                         $contact->setPlasma($plasma);
  581.                         $contact->setGdpr($gdpr);
  582.                         $contact->setCentre($data['centre']);
  583.                         /*$contact->setLang($request->getLocale());*/
  584.                         $contact->setKey($email.'_'.uniqid());
  585.                         $contact->setParent($folderPath);
  586.                         $contact->setPublished(true);
  587.                         $contact->save();
  588.                         //email au centre
  589.                         // JDS On envoie à l'adresse définie dans les settings et plus vers le centre comme c'était demandé initialement.
  590.                         $mail = new \Pimcore\Mail();
  591.                         $mail->setDocument('/emails/inscription');
  592.                         //$mail->to($data['centre']->getEmail());
  593.                         $mail->setParams($data);
  594.                         $mail->send();
  595.                         //Copie au visiteur
  596.                         $mail = new \Pimcore\Mail();
  597.                         $mail->setDocument('/emails/'.$request->getLocale().'/inscription-confirmation');
  598.                         $mail->to($email);
  599.                         $mail->setParams($data);
  600.                         $mail->send();
  601.                         $formStatus 'success';
  602.                     }else{
  603.                         $formStatus 'invalid-email';
  604.                     }
  605.                 }else{
  606.                     $formStatus 'robot';
  607.                 }
  608.             }else{
  609.                 $formStatus 'required-empty';
  610.             }
  611.         }
  612.         $viewContactForm $formContact->createView();
  613.         return $this->render('inscription/fast-inscription.html.twig',[
  614.             'centres' => $centres,
  615.             'form' => $viewContactForm,
  616.             'formStatus' => $formStatus,
  617.             'ddsHoraires' => $ddsHoraires,
  618.             'error' => false
  619.         ]);
  620.     }
  621.     /**
  622.      * @Template
  623.      * @param Request $request
  624.      * @route("/{_locale}/api/akimedia/site/{id}", name="apiAkimediaSite",methods={"GET"})
  625.      * @return array
  626.      */
  627.     public function detailAction(Request $request)
  628.     {
  629.         $session $request->getSession();
  630.         $token $session->get('akimedia-token');
  631.         if(!$token){
  632.             $token Akimedia::login();
  633.             $session->set('akimedia-token'$token);
  634.         }
  635.         $id $request->get('id');
  636.         $site Akimedia::getSiteInfos($request$id);
  637.         return new JsonResponse($site);
  638.     }
  639.     private function build_calendar($month,$year,$CentreId,$trans) {
  640.         // Create array containing abbreviations of days of week.
  641.         $daysOfWeek = array('L','M','M','J','V','S','D');
  642.         // What is the first day of the month in question?
  643.         $firstDayOfMonth mktime(0,0,0,$month,1,$year);
  644.         // How many days does this month contain?
  645.         $numberDays date('t',$firstDayOfMonth);
  646.         // Retrieve some information about the first day of the
  647.         // month in question.
  648.         $dateComponents getdate($firstDayOfMonth);
  649.         // What is the name of the month in question?
  650.         $monthName $trans->trans($dateComponents['month']);
  651.         // What is the index value (0-6) of the first day of the
  652.         // month in question.
  653.         $dayOfWeek $dateComponents['wday'] - 1;
  654.         if($dayOfWeek==-1){
  655.             $dayOfWeek=6;
  656.         }
  657.         // Create the table tag opener and day headers
  658.         $calendar "<table class='calendar'>";
  659.         $calendar .= "<caption>$monthName $year</caption>";
  660.         $calendar .= "<tr>";
  661.         // Create the calendar headers
  662.         foreach($daysOfWeek as $day) {
  663.             $calendar .= "<th class='header'>$day</th>";
  664.         }
  665.         // Create the rest of the calendar
  666.         // Initiate the day counter, starting with the 1st.
  667.         $currentDay 1;
  668.         $calendar .= "</tr><tr>";
  669.         // The variable $dayOfWeek is used to
  670.         // ensure that the calendar
  671.         // display consists of exactly 7 columns.
  672.         if ($dayOfWeek 0) {
  673.             $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>";
  674.         }
  675.         $month str_pad($month2"0"STR_PAD_LEFT);
  676.         while ($currentDay <= $numberDays) {
  677.             // Seventh column (Saturday) reached. Start a new row.
  678.             if ($dayOfWeek == 7) {
  679.                 $dayOfWeek 0;
  680.                 $calendar .= "</tr><tr>";
  681.             }
  682.             $currentDayRel str_pad($currentDay2"0"STR_PAD_LEFT);
  683.             $date "$year-$month-$currentDayRel";
  684.             $calendar .= "<td class='day' data-centre-id='$CentreId' data-date-format='".date("d-m-Y"strtotime($date))."' data-date='$date'>$currentDay</td>";
  685.             // Increment counters
  686.             $currentDay++;
  687.             $dayOfWeek++;
  688.         }
  689.         // Complete the row of the last week in month, if necessary
  690.         if ($dayOfWeek != 7) {
  691.             $remainingDays $dayOfWeek;
  692.             $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";
  693.         }
  694.         $calendar .= "</tr>";
  695.         $calendar .= "</table>";
  696.         return $calendar;
  697.     }
  698. }