src/Controller/InscriptionController.php line 330

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.         $session $request->getSession();
  288.         $session->set('centre'$request->get('id'));
  289.         if($this->editmode){
  290.             $id 1;
  291.         }
  292.         if($id){
  293.             return $this->render('inscription/form-eligibilite-inscription.html.twig',[
  294.                 'centre' => $id
  295.             ]);
  296.         }else{
  297.             if($this->document->getProperty('listeCentresPlasma')) {
  298.                 return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  299.             } else {
  300.                 return $this->redirect('/');
  301.             }
  302.         }
  303.     }
  304.     /**
  305.      * @Template
  306.      * @param Request $request
  307.      * @param DataObject $object
  308.      * @return response
  309.      *
  310.      */
  311.     public function defaultContactAction(Request $request)
  312.     {
  313.         if(!WebsiteSetting::getByName('akimediaActivate')) {
  314.             $centres null// On ne récupère plus plusieurs centres mais un seul
  315.             //Formulaire d'inscription
  316.             $formStatus false;
  317.             $ddsHoraires false;
  318.             $centre false;
  319.             $lang $request->getLocale();
  320.             $session $request->getSession();
  321.             $CentreId $session->get('centre');
  322.             $token $session->get('akimedia-token');
  323.             $errorMessage "";
  324.             if(!$token){
  325.                 $token Akimedia::login();
  326.                 $session->set("akimedia-token"$token);
  327.             }
  328.             $centre Akimedia::getSiteInfos($request$CentreId);
  329.             if(!$centre) {
  330.                 if($this->document->getProperty('listeCentresPlasma')) {
  331.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  332.                 } else {
  333.                     return $this->redirect('/'$lang);
  334.                 }
  335.             }
  336.         } else {
  337.             $session $request->getSession();
  338.             $CentreId $session->get('centre');
  339.             //Formulaire d'inscription
  340.             $formStatus false;
  341.             $ddsHoraires false;
  342.             $centre false;
  343.             $lang $request->getLocale();
  344.             if(strpos(WebsiteSetting::getByName('horairesCentresApi')->getData(), 'dds') !== false) {
  345.                 $ddsHoraires true;
  346.                 $centres null// On ne récupère plus plusieurs centres mais un seul
  347.                 //gestion guzzle
  348.                 $client = new Client();
  349.                 $response $client->request('POST'"https://www.donneurdesang.be/"$request->getLocale() ."/api/centres-by-provinces", [
  350.                     'headers' => [
  351.                         'Content-Type' => 'application/x-www-form-urlencoded',
  352.                     ]
  353.                 ]);
  354.                 $results json_decode($response->getBody(), true);
  355.                 $apiCentres $results;
  356.                 //Boucle pour récupérer le bon centre
  357.                 foreach($apiCentres as $apiCentre) {
  358.                     if($apiCentre["o_id"] == $CentreId) {
  359.                         $centre $apiCentre;
  360.                         continue;
  361.                     }
  362.                 }
  363.             } else {
  364.                 $centres = new DataObject\Centres\Listing();
  365.                 $centres->load();
  366.             }
  367.             //Suppression des paramètres et redirect
  368.             if($request->get('centre') && $request->get('centre')){
  369.                 $session->set('centre'$request->get('centre'));
  370.                 $url explode("?"$_SERVER['REQUEST_URI']);
  371.                 return $this->redirect($url[0]);
  372.             }
  373.             if($this->editmode){
  374.                 $session->set('centre'2559);
  375.             }
  376.             if(!$centre) {
  377.                 if($this->document->getProperty('listeCentresPlasma')) {
  378.                     return $this->redirect($this->document->getProperty('listeCentresPlasma'));
  379.                 } else {
  380.                     return $this->redirect('/'$lang);
  381.                 }
  382.             }
  383.         }
  384.         //////////////////////////////////////////////////
  385.         // initialize form and handle request data
  386.         $formContact $this->createForm(InscriptionFormType::class, null);
  387.         $formContact->handleRequest($request);
  388.         // On vérifie si un POST a bien été effectué et donc si le formulaire a été envoyé
  389.         if ($formContact->isSubmitted() && $formContact->isValid()) {
  390.             $data $formContact->getData();
  391.             $email                 $data['email'];
  392.             $phone                 $data['phone'];
  393.             $firstname             $data['firstname'];
  394.             $lastname             $data['lastname'];
  395.             $birthday             $data['birthday'];
  396.             $sang                 $data['sang'];
  397.             $plasma                $data['plasma'];
  398.             $gdpr                 $data['gdpr'];
  399.             $data['centreId']    = $request->get("inscription_form_centre");
  400.             if(WebsiteSetting::getByName('akimediaActivate')) {
  401.                 if($ddsHoraires) {
  402.                     //$centre = DataObject\Centres::getByCodeCentre($data['centreId']);
  403.                     $convertCentre DataObject\Centres::getByCodeCentre($centre['codeCentre']);
  404.                     $convertCentre $convertCentre->load();
  405.                     $data['centre'] = $convertCentre[0];
  406.                 } else {
  407.                     $centre DataObject\Centres::getByAkimediaId($data['centreId']);
  408.                     $centre $centre->load();
  409.                     $data['centre'] = $centre[0];
  410.                 }
  411.             } else {
  412.                 $centreObj DataObject\Centres::getByAkimediaId($data['centreId']);
  413.                 $centreObj $centreObj->load();
  414.                 $data['centre'] = $centreObj[0];
  415.             }
  416.             if($email != $request->get("inscription_form_confirmation")){
  417.                 $viewContactForm $formContact->createView();
  418.                 return[
  419.                     'centre' => $centre// Ajout Greg pour reprendre la data depuis dds
  420.                     'centres' => $centres,
  421.                     'form' => $viewContactForm,
  422.                     'formStatus' => $formStatus,
  423.                     'error' => true,
  424.                     'lang' => $lang
  425.                 ];
  426.             }
  427.             // On vérifie que tous les champs sont bien complétés
  428.             if($firstname !== "" && $lastname !== "" && $email !== ""){
  429.                 // reCaptcha verification
  430.                 $recaptchaKeyPrivate WebsiteSetting::getByName('recaptchaKeyPrivate');
  431.                 $recaptcha_url 'https://www.google.com/recaptcha/api/siteverify';
  432.                 $recaptcha_response $data['recaptcha'];
  433.                 $recaptcha file_get_contents($recaptcha_url '?secret=' $recaptchaKeyPrivate->getData() . '&response=' $recaptcha_response);
  434.                 $recaptcha json_decode($recaptcha);
  435.                 if ($recaptcha->success)
  436.                 {
  437.                     if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  438.                         // condition pour changer le folder d'enregistrement de concours dans les assets
  439.                         $folderPath Folder::getByPath("/Inscription");
  440.                         if(!$folderPath){
  441.                             $folderPath = new Folder();
  442.                             $folderPath->setKey("Inscription");
  443.                             $folderPath->setParentId(1);
  444.                             $folderPath->save();
  445.                         }
  446.                         if($this->document->getProperty('objectFormFolder')) {
  447.                             $folderPath Folder::getByPath($this->document->getProperty('objectFormFolder'));
  448.                         }
  449.                         $contact = new DataObject\Inscription();
  450.                         $contact->setLastname($lastname);
  451.                         $contact->setFirstname($firstname);
  452.                         $contact->setEmail($email);
  453.                         $contact->setPhone($phone);
  454.                         $contact->setBirthday($birthday);
  455.                         $contact->setSang($sang);
  456.                         $contact->setPlasma($plasma);
  457.                         $contact->setGdpr($gdpr);
  458.                         $contact->setCentre($data['centre']);
  459.                         /*$contact->setLang($request->getLocale());*/
  460.                         $contact->setKey($email.'_'.uniqid());
  461.                         $contact->setParent($folderPath);
  462.                         $contact->setPublished(true);
  463.                         $contact->save();
  464.                         //email au centre
  465.                         // JDS On envoie à l'adresse définie dans les settings et plus vers le centre comme c'était demandé initialement.
  466.                         $mail = new \Pimcore\Mail();
  467.                         $mail->setDocument('/emails/inscription');
  468.                         //$mail->to($data['centre']->getEmail());
  469.                         $mail->setParams($data);
  470.                         $mail->send();
  471.                         //Copie au visiteur
  472.                         $mail = new \Pimcore\Mail();
  473.                         $mail->setDocument('/emails/'.$request->getLocale().'/inscription-confirmation');
  474.                         $mail->to($email);
  475.                         $mail->setParams($data);
  476.                         $mail->send();
  477.                         $formStatus 'success';
  478.                     }else{
  479.                         $formStatus 'invalid-email';
  480.                     }
  481.                 }else{
  482.                     $formStatus 'robot';
  483.                 }
  484.             }else{
  485.                 $formStatus 'required-empty';
  486.             }
  487.         }
  488.         $viewContactForm $formContact->createView();
  489.         return $this->render('inscription/default.html.twig',[
  490.             'centre' => $centre// Ajout Greg pour reprendre la data depuis dds
  491.             'centres' => $centres,
  492.             'form' => $viewContactForm,
  493.             'formStatus' => $formStatus,
  494.             'ddsHoraires' => $ddsHoraires,
  495.             'error' => false,
  496.             'lang' => $lang
  497.         ]);
  498.     }
  499.     /**
  500.      * @Template
  501.      * @param Request $request
  502.      * @param DataObject $object
  503.      * @return response
  504.      */
  505.     public function fastContactAction(Request $request)
  506.     {
  507.         //Formulaire d'inscription
  508.         $formStatus false;
  509.         $ddsHoraires false;
  510.         $centres = new DataObject\Centres\Listing();
  511.         $centres->load();
  512.         if(strpos(WebsiteSetting::getByName('horairesCentresApi')->getData(), 'dds') !== false) {
  513.             $ddsHoraires true;
  514.         }
  515.         // initialize form and handle request data
  516.         $formContact $this->createForm(InscriptionFormType::class, null);
  517.         $formContact->handleRequest($request);
  518.         // On vérifie si un POST a bien été effectué et donc si le formulaire a été envoyé
  519.         if ($formContact->isSubmitted() && $formContact->isValid()) {
  520.             $data $formContact->getData();
  521.             $email                 $data['email'];
  522.             $phone                 $data['phone'];
  523.             $firstname             $data['firstname'];
  524.             $lastname             $data['lastname'];
  525.             $birthday             $data['birthday'];
  526.             $sang                 $data['sang'];
  527.             $plasma                $data['plasma'];
  528.             $gdpr                 $data['gdpr'];
  529.             $data['centreId']    = $request->get("inscription_form_centre");
  530.             if($ddsHoraires) {
  531.                 $centre DataObject\Centres::getByCodeCentre($data['centreId']);
  532.             } else {
  533.                 $centre DataObject\Centres::getByAkimediaId($data['centreId']);
  534.             }
  535.             $centre $centre->load();
  536.             $data['centre'] = $centre[0];
  537.             if($email != $request->get("inscription_form_confirmation")){
  538.                 $viewContactForm $formContact->createView();
  539.                 return $this->render('inscription/fast-inscription.html.twig',[
  540.                     'centres' => $centres,
  541.                     'form' => $viewContactForm,
  542.                     'formStatus' => $formStatus,
  543.                     'ddsHoraires' => $ddsHoraires,
  544.                     'error' => true,
  545.                 ]);
  546.             }
  547.             // On vérifie que tous les champs sont bien complétés
  548.             if($firstname !== "" && $lastname !== "" && $email !== ""){
  549.                 // reCaptcha verification
  550.                 $recaptchaKeyPrivate WebsiteSetting::getByName('recaptchaKeyPrivate');
  551.                 $recaptcha_url 'https://www.google.com/recaptcha/api/siteverify';
  552.                 $recaptcha_response $data['recaptcha'];
  553.                 $recaptcha file_get_contents($recaptcha_url '?secret=' $recaptchaKeyPrivate->getData() . '&response=' $recaptcha_response);
  554.                 $recaptcha json_decode($recaptcha);
  555.                 if ($recaptcha->success)
  556.                 {
  557.                     if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  558.                         // condition pour changer le folder d'enregistrement de concours dans les assets
  559.                         $folderPath Folder::getByPath("/Inscription");
  560.                         if(!$folderPath){
  561.                             $folderPath = new Folder();
  562.                             $folderPath->setKey("Inscription");
  563.                             $folderPath->setParentId(1);
  564.                             $folderPath->save();
  565.                         }
  566.                         if($this->document->getProperty('objectFormFolder')) {
  567.                             $folderPath Folder::getByPath($this->document->getProperty('objectFormFolder'));
  568.                         }
  569.                         $contact = new DataObject\Inscription();
  570.                         $contact->setLastname($lastname);
  571.                         $contact->setFirstname($firstname);
  572.                         $contact->setEmail($email);
  573.                         $contact->setPhone($phone);
  574.                         $contact->setBirthday($birthday);
  575.                         $contact->setSang($sang);
  576.                         $contact->setPlasma($plasma);
  577.                         $contact->setGdpr($gdpr);
  578.                         $contact->setCentre($data['centre']);
  579.                         /*$contact->setLang($request->getLocale());*/
  580.                         $contact->setKey($email.'_'.uniqid());
  581.                         $contact->setParent($folderPath);
  582.                         $contact->setPublished(true);
  583.                         $contact->save();
  584.                         //email au centre
  585.                         // JDS On envoie à l'adresse définie dans les settings et plus vers le centre comme c'était demandé initialement.
  586.                         $mail = new \Pimcore\Mail();
  587.                         $mail->setDocument('/emails/inscription');
  588.                         //$mail->to($data['centre']->getEmail());
  589.                         $mail->setParams($data);
  590.                         $mail->send();
  591.                         //Copie au visiteur
  592.                         $mail = new \Pimcore\Mail();
  593.                         $mail->setDocument('/emails/'.$request->getLocale().'/inscription-confirmation');
  594.                         $mail->to($email);
  595.                         $mail->setParams($data);
  596.                         $mail->send();
  597.                         $formStatus 'success';
  598.                     }else{
  599.                         $formStatus 'invalid-email';
  600.                     }
  601.                 }else{
  602.                     $formStatus 'robot';
  603.                 }
  604.             }else{
  605.                 $formStatus 'required-empty';
  606.             }
  607.         }
  608.         $viewContactForm $formContact->createView();
  609.         return $this->render('inscription/fast-inscription.html.twig',[
  610.             'centres' => $centres,
  611.             'form' => $viewContactForm,
  612.             'formStatus' => $formStatus,
  613.             'ddsHoraires' => $ddsHoraires,
  614.             'error' => false
  615.         ]);
  616.     }
  617.     /**
  618.      * @Template
  619.      * @param Request $request
  620.      * @route("/{_locale}/api/akimedia/site/{id}", name="apiAkimediaSite",methods={"GET"})
  621.      * @return array
  622.      */
  623.     public function detailAction(Request $request)
  624.     {
  625.         $session $request->getSession();
  626.         $token $session->get('akimedia-token');
  627.         if(!$token){
  628.             $token Akimedia::login();
  629.             $session->set('akimedia-token'$token);
  630.         }
  631.         $id $request->get('id');
  632.         $site Akimedia::getSiteInfos($request$id);
  633.         return new JsonResponse($site);
  634.     }
  635.     private function build_calendar($month,$year,$CentreId,$trans) {
  636.         // Create array containing abbreviations of days of week.
  637.         $daysOfWeek = array('L','M','M','J','V','S','D');
  638.         // What is the first day of the month in question?
  639.         $firstDayOfMonth mktime(0,0,0,$month,1,$year);
  640.         // How many days does this month contain?
  641.         $numberDays date('t',$firstDayOfMonth);
  642.         // Retrieve some information about the first day of the
  643.         // month in question.
  644.         $dateComponents getdate($firstDayOfMonth);
  645.         // What is the name of the month in question?
  646.         $monthName $trans->trans($dateComponents['month']);
  647.         // What is the index value (0-6) of the first day of the
  648.         // month in question.
  649.         $dayOfWeek $dateComponents['wday'] - 1;
  650.         if($dayOfWeek==-1){
  651.             $dayOfWeek=6;
  652.         }
  653.         // Create the table tag opener and day headers
  654.         $calendar "<table class='calendar'>";
  655.         $calendar .= "<caption>$monthName $year</caption>";
  656.         $calendar .= "<tr>";
  657.         // Create the calendar headers
  658.         foreach($daysOfWeek as $day) {
  659.             $calendar .= "<th class='header'>$day</th>";
  660.         }
  661.         // Create the rest of the calendar
  662.         // Initiate the day counter, starting with the 1st.
  663.         $currentDay 1;
  664.         $calendar .= "</tr><tr>";
  665.         // The variable $dayOfWeek is used to
  666.         // ensure that the calendar
  667.         // display consists of exactly 7 columns.
  668.         if ($dayOfWeek 0) {
  669.             $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>";
  670.         }
  671.         $month str_pad($month2"0"STR_PAD_LEFT);
  672.         while ($currentDay <= $numberDays) {
  673.             // Seventh column (Saturday) reached. Start a new row.
  674.             if ($dayOfWeek == 7) {
  675.                 $dayOfWeek 0;
  676.                 $calendar .= "</tr><tr>";
  677.             }
  678.             $currentDayRel str_pad($currentDay2"0"STR_PAD_LEFT);
  679.             $date "$year-$month-$currentDayRel";
  680.             $calendar .= "<td class='day' data-centre-id='$CentreId' data-date-format='".date("d-m-Y"strtotime($date))."' data-date='$date'>$currentDay</td>";
  681.             // Increment counters
  682.             $currentDay++;
  683.             $dayOfWeek++;
  684.         }
  685.         // Complete the row of the last week in month, if necessary
  686.         if ($dayOfWeek != 7) {
  687.             $remainingDays $dayOfWeek;
  688.             $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";
  689.         }
  690.         $calendar .= "</tr>";
  691.         $calendar .= "</table>";
  692.         return $calendar;
  693.     }
  694. }