src/Controller/Frontend/OfferController.php line 23

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