src/Controller/Frontend/JobBoardController.php line 114

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Constant\Common;
  4. use App\Misc\CaptchaHelper;
  5. use App\Repository\CampusRepository;
  6. use App\Repository\ContractRepository;
  7. use App\Repository\ExpertiseRepository;
  8. use App\Repository\SkillRepository;
  9. use App\Repository\StudyLevelRepository;
  10. use App\Utilities\ServiceUtil;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use App\Exception\BadRequestException;
  15. use App\Annotation\Log;
  16. class JobBoardController extends BaseFrontendController
  17. {
  18.     /**
  19.      * @Route("/{_locale}/offres-alternances-et-stages", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="job_board.index")
  20.      */
  21.     public function index(
  22.         Request $request,
  23.         TranslatorInterface $translator,
  24.         SkillRepository $skillRepository,
  25.         ExpertiseRepository $expertiseRepository,
  26.         ContractRepository $contractRepository,
  27.         CampusRepository $campusRepository
  28.     ) {
  29.         $siteName $translator->trans('siteName');
  30.         $metaTitle $translator->trans(
  31.             'job.title',
  32.             [
  33.                 '%siteName%' => $siteName
  34.             ]
  35.         );
  36.         $this->addTitle($metaTitle);
  37.         $this->setDescription($translator->trans('job.desc'));
  38.         $data['jobs'] = $this->offerRepo->getListAll(null);
  39.         $data['totalJob'] = $this->offerRepo->getTotalJobActive();
  40.         $data['expertises'] = $expertiseRepository->findAll();
  41.         $data['contracts'] = $contractRepository->findAll();
  42.         $data['campuses'] = $campusRepository->findAll(['filter_status' => 1]);
  43.         $data['skills'] = $skillRepository->findBy([]);
  44.         return $this->render('job_board/index.html.twig'$data);
  45.     }
  46.     /**
  47.      * @Route("/filter-offer", name="job.filter")
  48.      */
  49.     public function filterData(
  50.         Request $request
  51.     ) {
  52.         $jobs $this->offerService->filterJob($request->request->all());
  53.         $view $this->renderView('job_board/_filter.html.twig', [
  54.             'jobs' => $jobs,
  55.         ]);
  56.         return $this->json([
  57.             'data' => $view,
  58.             'total' => count($jobs)
  59.         ]);
  60.     }
  61.     /**
  62.      * @Route("/{_locale}/offres-alternances-et-stages/{slug}", requirements={"_locale": "en|fr", "slug": "[a-zA-Z0-9\-]+"}, defaults={"_locale"="fr"}, name="job_board.detail")
  63.      */
  64.     public function detail(
  65.         $slug,
  66.         Request $request,
  67.         TranslatorInterface $translator
  68.     ) {
  69.         $job $this->offerRepo->getBySlug($slug$request);
  70.         if(!$job){
  71.             return $this->render('pages/404.html.twig');
  72.         }
  73.         $this->addTitle($job->offerTitle);
  74.         $this->setDescription($job->offerTitle);
  75.         $data['job'] = $job;
  76.         $data['jobs'] = $this->offerRepo->getListLasted($job->id);
  77.         return $this->render(
  78.             'job_board/detail.html.twig',
  79.             $data
  80.         );
  81.     }
  82.     /**
  83.      * @Route("/{_locale}/offres-alternances-et-stages/{slug}/{code}", requirements={"_locale": "en|fr", "code": "[a-zA-Z0-9\-]+", "slug": "[a-zA-Z0-9\-]+"}, defaults={"_locale"="fr"}, name="job.apply")
  84.      */
  85.     public function applyJob(
  86.         $slug,
  87.         Request $request,
  88.         StudyLevelRepository $studyLevelRepository,
  89.         TranslatorInterface $translator
  90.     ) {
  91.         $job $this->offerRepo->getBySlug($slug$request);
  92.         if (!$job) throw $this->createNotFoundException('');
  93.         $this->addTitle($job->offerTitle);
  94.         $this->setDescription($job->offerTitle);
  95.         $data['job'] = $job;
  96.         $data['studyLevels'] = $studyLevelRepository->findAll();
  97.         $data['statusCandidate'] = $this->jobCandidateService->listStatusCandidate();
  98.         return $this->render(
  99.             'job_board/apply.html.twig',
  100.             $data
  101.         );
  102.     }
  103.     /**
  104.      * @Route("/job-save-apply", name="job.save_apply")
  105.      * @Log
  106.      */
  107.     public function saveOffer(
  108.         Request $request,
  109.         CaptchaHelper $captchaHelper,
  110.         TranslatorInterface $translator
  111.     ) {
  112.         try {
  113.             if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
  114.                 return $this->json(ServiceUtil::processFailed([
  115.                     'errorMessage' => $translator->trans('message.captcha_is_not_valid')
  116.                 ]));
  117.             }
  118.             $this->jobCandidateService->addEntity($request);
  119.             return $this->json(ServiceUtil::processSuccessful());
  120.         } catch (BadRequestException $badRequestException) {
  121.             $messagesArr $badRequestException->getMessages();
  122.             foreach ($messagesArr['data'] as $message) {
  123.                 $errorMessage $message;
  124.                 break;
  125.             }
  126.         }
  127.         $data['errorMessage'] = $errorMessage;
  128.         return $this->json(ServiceUtil::processFailed($data));
  129.     }
  130. }