src/Controller/Frontend/EntreprisesController.php line 21

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\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use FOS\RestBundle\Controller\Annotations as Rest;
  9. use App\Exception\BadRequestException;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use App\Annotation\Log;
  13. class EntreprisesController extends BaseFrontendController
  14. {
  15.     /**
  16.      * @Route("/{_locale}/forum-des-entreprises", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="forum_entreprises")
  17.      */
  18.     public function forumEntreprises(TranslatorInterface $translator)
  19.     {
  20.         $this->addTitle($translator->trans(
  21.             'forum_entreprises.title'
  22.         ));
  23.         $this->setDescription($translator->trans(
  24.             'forum_entreprises.desc'
  25.         ));
  26.         $data = [];
  27.         $timezone $this->requestService->getTimezone('fallback_timezone');
  28.         $data['timezone'] = $timezone;
  29.         $data['forums'] = $this->forumRepo->getActiveDate($timezone);
  30.         $data['campuses'] = $this->campusRepo->findBy(['status' => 1], ['ordering' => 'DESC']);
  31.         return $this->render('entreprises/forum_entreprises.html.twig'$data);
  32.     }
  33.     /**
  34.      * @Rest\Post("/save-entreprises", name="entreprises.save_apply")
  35.      * @Log
  36.      */
  37.     public function saveEntreprises(
  38.         Request $request,
  39.         CaptchaHelper $captchaHelper,
  40.         TranslatorInterface $translator
  41.     ) {
  42.         try {
  43.             // Check captcha is valid
  44.             if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  45.                 return $this->json(ServiceUtil::processFailed([
  46.                     'errorMessage' => $translator->trans('message.captcha_is_not_valid')
  47.                 ]));
  48.             }
  49.             $contact $request->request->get('contact');
  50.             if (isset($contact)) {
  51.                 if (count($contact) > 1) {
  52.                     $request->request->set('contact'2);
  53.                 } else {
  54.                     $request->request->set('contact'$contact[0]);
  55.                 }
  56.             }
  57.             $this->companyService->add($request);
  58.             return $this->json(ServiceUtil::processSuccessful());
  59.         } catch (BadRequestException $badRequestException) {
  60.             $messagesArr $badRequestException->getMessages();
  61.             foreach ($messagesArr['data'] as $field => $message) {
  62.                 $errorMessage $message;
  63.                 break;
  64.             }
  65.         }
  66.         $data['errorMessage'] = $errorMessage;
  67.         return $this->json(ServiceUtil::processFailed($data));
  68.     }
  69.     /**
  70.      * @Rest\Post("/save-candidate", name="candidate.save_apply")
  71.      * @Log
  72.      */
  73.     public function saveCandidate(
  74.         Request $request,
  75.         CaptchaHelper $captchaHelper,
  76.         TranslatorInterface $translator
  77.     ) {
  78.         try {
  79.             // Check captcha is valid
  80.             if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  81.                 return $this->json(ServiceUtil::processFailed([
  82.                     'errorMessage' => $translator->trans('message.captcha_is_not_valid')
  83.                 ]));
  84.             }
  85.             $this->candidateService->add($request);
  86.             return $this->json(ServiceUtil::processSuccessful());
  87.         } catch (BadRequestException $badRequestException) {
  88.             $messagesArr $badRequestException->getMessages();
  89.             foreach ($messagesArr['data'] as $field => $message) {
  90.                 $errorMessage $message;
  91.                 break;
  92.             }
  93.         }
  94.         $data['errorMessage'] = $errorMessage;
  95.         return $this->json(ServiceUtil::processFailed($data));
  96.     }
  97.     /**
  98.      * @Rest\Post("/get-forum", name="get.forum")
  99.      */
  100.     public function getForum(
  101.         Request $request
  102.     ) {
  103.         $timezone $this->requestService->getTimezone('fallback_timezone');
  104.         $data['timezone'] = $timezone;
  105.         $data['forums'] = $this->forumRepo->getActiveDate($timezone);
  106.         $select $this->container->get('twig')->render('entreprises/select_forum.html.twig'$data);
  107.         return $this->json(ServiceUtil::processSuccessful(['html' => $select]));
  108.     }
  109. }