src/Controller/Frontend/OpenDayController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Misc\CaptchaHelper;
  4. use App\Utilities\ServiceUtil;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Exception\BadRequestException;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use App\Annotation\Log;
  10. class OpenDayController extends BaseFrontendController
  11. {
  12.     /**
  13.      * @Route("/{_locale}/portes-ouvertes-et-evenements", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="open_day")
  14.      */
  15.     public function openDay(
  16.         TranslatorInterface $translator,
  17.         Request $request
  18.     ) {
  19.         $siteName $translator->trans('siteName');
  20.         $metaTitle $translator->trans(
  21.             'openDay.title'
  22.         );
  23.         $this->addTitle($metaTitle);
  24.         $this->setDescription($translator->trans(
  25.             'openDay.desc'
  26.         ));
  27.         $data['campuses'] = $this->campusRepo->getAll(['filter_status' => 1'sort_asc' => 'ordering']);
  28.         $data['items'] = $this->openDayRepo->getOpendayInMonth($request);
  29.         return $this->render('open_day/index.html.twig'$data);
  30.     }
  31.     /**
  32.      * @Route("/filter-open-day", name="open_day.filter")
  33.      */
  34.     public function filterData(
  35.         Request $request
  36.     ) {
  37.         $items $this->openDayService->filter($request->request->all());
  38.         $campuses $this->campusRepo->findBy(['status' => 1], ['name' => 'desc']);
  39.         $view $this->renderView('open_day/_filter.html.twig', [
  40.             'items'    => $items,
  41.             'campuses' => $campuses
  42.         ]);
  43.         return $this->json([
  44.             'data' => $view
  45.         ]);
  46.     }
  47.     /**
  48.      * @Route("/{_locale}/inscription/{id}-{slug}", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="open_day.inscription")
  49.      */
  50.     public function inscription(
  51.         $slug,
  52.         $id,
  53.         TranslatorInterface $translator
  54.     ) {
  55.         $data['studyLevels'] = $this->studyLevelRepository->findAll();
  56.         $data['campuses'] = $this->campusRepo->findBy(['status' => 1], ['ordering' => 'DESC']);
  57.         $data['openDay'] = $this->openDayService->getById($id);
  58.         $this->addTitle($data['openDay']['name']);
  59.         $this->setDescription($data['openDay']['name']);
  60.         return $this->render('open_day/inscription.html.twig'$data);
  61.     }
  62.     /**
  63.      * @Route("/save-open-day", name="open_day.save")
  64.      * @Log
  65.      */
  66.     public function saveOpenDay(
  67.         Request $request,
  68.         CaptchaHelper $captchaHelper,
  69.         TranslatorInterface $translator
  70.     ) {
  71.         try {
  72.             // Check captcha is valid
  73.             if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  74.                 return $this->json(ServiceUtil::processFailed([
  75.                     'errorMessage' => $translator->trans('message.captcha_is_not_valid')
  76.                 ]));
  77.             }
  78.             $this->openDayPersonService->addPerson($request);
  79.             return $this->json(ServiceUtil::processSuccessful());
  80.         } catch (BadRequestException $badRequestException) {
  81.             $messagesArr $badRequestException->getMessages();
  82.             foreach ($messagesArr['data'] as $field => $message) {
  83.                 $errorMessage $message;
  84.                 break;
  85.             }
  86.         }
  87.         $data['errorMessage'] = $errorMessage;
  88.         return $this->json(ServiceUtil::processFailed($data));
  89.     }
  90. }