src/Controller/Frontend/RecruitmentController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Misc\CaptchaHelper;
  4. use App\Repository\CampusRepository;
  5. use App\Utilities\ServiceUtil;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use App\Exception\BadRequestException;
  10. use App\Repository\CountryRepository;
  11. use App\Repository\RecruitmentThemeRepository;
  12. use App\Annotation\Log;
  13. class RecruitmentController extends BaseFrontendController
  14. {
  15.     /**
  16.      * @Route("/{_locale}/collaborer-avec-estiam", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="recruitmemt.index")
  17.      */
  18.     public function index(
  19.         TranslatorInterface $translator,
  20.         RecruitmentThemeRepository $recruitmentThemeRepository,
  21.         CampusRepository $campusRepository,
  22.         CountryRepository $countryRepository
  23.     ) {
  24.         $siteName $translator->trans('siteName');
  25.         $this->addTitle($translator->trans(
  26.             'recruitment.title',
  27.             [
  28.                 '%siteName%' => $siteName
  29.             ]
  30.         ));
  31.         $this->setDescription($translator->trans(
  32.             'recruitment.desc',
  33.             [
  34.                 '%siteName%' => $siteName
  35.             ]
  36.         ));
  37.         $data['themes'] = $recruitmentThemeRepository->findBy([], ['name' => 'asc']);
  38.         $data['campuses'] = $campusRepository->findBy(['status' => 1], ['name' => 'asc']);
  39.         $data['countries'] = $countryRepository->findBy([], ['ordering' => 'asc']);
  40.         return $this->render(
  41.             'recrutement/index.html.twig',
  42.             $data
  43.         );
  44.     }
  45.     /**
  46.      * @Route("/save-recruitmemt", name="recruitmemt.save")
  47.      * @Log
  48.      */
  49.     public function saveRecruitmemt(
  50.         Request $request,
  51.         CaptchaHelper $captchaHelper,
  52.         TranslatorInterface $translator
  53.     ) {
  54.         try {
  55.             if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  56.                 return $this->json(ServiceUtil::processFailed([
  57.                     'errorMessage' => $translator->trans('message.captcha_is_not_valid')
  58.                 ]));
  59.             }
  60.             $this->currentService->addEntity($request);
  61.             return $this->json(ServiceUtil::processSuccessful());
  62.         } catch (BadRequestException $badRequestException) {
  63.             $messagesArr $badRequestException->getMessages();
  64.             foreach ($messagesArr['data'] as $message) {
  65.                 $errorMessage $message;
  66.                 break;
  67.             }
  68.         }
  69.         $data['errorMessage'] = $errorMessage;
  70.         return $this->json(ServiceUtil::processFailed($data));
  71.     }
  72. }