src/Controller/Frontend/IndexController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Misc\CaptchaHelper;
  4. use App\Entity\Partner;
  5. use App\Entity\OurStudent;
  6. use Exception;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use FOS\RestBundle\Controller\Annotations as Rest;
  10. use App\Exception\BadRequestException;
  11. use Symfony\Component\HttpFoundation\Session\Session;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. class IndexController extends BaseFrontendController
  15. {
  16.     /**
  17.      * @Route("/{_locale}", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="home")
  18.      */
  19.     public function index(
  20.         TranslatorInterface $translator
  21.     ): Response {
  22.         $siteName $this->getParameter('site_name');
  23.         $metaTitle $translator->trans(
  24.             'home.title',
  25.             [
  26.                 '%siteName%' => $siteName
  27.             ]
  28.         );
  29.         $this->addTitle($metaTitle);
  30.         $this->setDescription($translator->trans(
  31.             'home.desc',
  32.             [
  33.                 '%siteName%' => $siteName
  34.             ]
  35.         ));
  36.         $data['jobs'] = $this->offerRepo->getListLasted();
  37.         $data['totalJob'] = $this->offerRepo->getTotalJobActive();
  38.         $data['campuses'] = $this->campusRepo->getAll(['filter_status' => 1'sort_asc' => 'ordering']);
  39.         $data['partners'] = $this->partnerRepo->getAll(['filter_status' => Partner::STATUS_ACTIVE], 'App\DTO\Partner\PartnerOutput');
  40.         $data['outStudentVideos']   = $this->ourStudentRepo->getAllOurStudentByType(OurStudent::TYPE_VIDEO3);
  41.         $data['jpos'] = $this->openDayRepo->getOpenDayLatest(4);
  42.         return $this->render('home/home.html.twig'$data);
  43.     }
  44.     /**
  45.      * @Route("/{_locale}/contact", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="contact_page")
  46.      */
  47.     public function contact(
  48.         Request $request,
  49.         TranslatorInterface $translator,
  50.         CaptchaHelper $captchaHelper,
  51.         Session $session
  52.     ) {
  53.         $siteName $this->getParameter('site_name');
  54.         $this->addTitle($translator->trans(
  55.             'contact.title',
  56.             [
  57.                 '%siteName%' => $siteName
  58.             ]
  59.         ));
  60.         $this->setDescription($translator->trans(
  61.             'contact.desc',
  62.             [
  63.                 '%siteName%' => $siteName
  64.             ]
  65.         ));
  66.         $this->get('session')->getFlashBag()->clear();
  67.         $errorMessage null;
  68.         $campuses $this->campusRepo->getAll(['filter_status' => 1'sort_asc' => 'ordering']);
  69.         if ($request->isMethod('POST')) {
  70.             $session->getFlashBag()->set('messages''Message sent successfully');
  71.             try {
  72.                 if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  73.                     throw new Exception($translator->trans('message.captcha_is_not_valid'));
  74.                 }
  75.                 if ($this->contactService->sendContactEmail($request->request->all())) {
  76.                     $session->getFlashBag()->set('messages''Message sent successfully');
  77.                 }
  78.             } catch (Exception $exception) {
  79.                 $errorMessage $exception->getMessage();
  80.             }
  81.         }
  82.         return $this->render('pages/contact.html.twig', [
  83.             'errorMessage' => $errorMessage,
  84.             'campuses' => $campuses
  85.         ]);
  86.     }
  87.     /**
  88.      * @Rest\Get("/404", name="404")
  89.      */
  90.     public function notFound(): Response
  91.     {
  92.         return $this->render('pages/404.html.twig');
  93.     }
  94. }