<?php
namespace App\Controller\Frontend;
use App\Constant\Common;
use App\Misc\CaptchaHelper;
use App\Repository\CampusRepository;
use App\Repository\ContractRepository;
use App\Repository\ExpertiseRepository;
use App\Repository\SkillRepository;
use App\Repository\StudyLevelRepository;
use App\Utilities\ServiceUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Annotation\Route;
use App\Exception\BadRequestException;
use App\Annotation\Log;
class JobBoardController extends BaseFrontendController
{
/**
* @Route("/{_locale}/offres-alternances-et-stages", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="job_board.index")
*/
public function index(
Request $request,
TranslatorInterface $translator,
SkillRepository $skillRepository,
ExpertiseRepository $expertiseRepository,
ContractRepository $contractRepository,
CampusRepository $campusRepository
) {
$siteName = $translator->trans('siteName');
$metaTitle = $translator->trans(
'job.title',
[
'%siteName%' => $siteName
]
);
$this->addTitle($metaTitle);
$this->setDescription($translator->trans('job.desc'));
$data['jobs'] = $this->offerRepo->getListAll(null);
$data['totalJob'] = $this->offerRepo->getTotalJobActive();
$data['expertises'] = $expertiseRepository->findAll();
$data['contracts'] = $contractRepository->findAll();
$data['campuses'] = $campusRepository->findAll(['filter_status' => 1]);
$data['skills'] = $skillRepository->findBy([]);
return $this->render('job_board/index.html.twig', $data);
}
/**
* @Route("/filter-offer", name="job.filter")
*/
public function filterData(
Request $request
) {
$jobs = $this->offerService->filterJob($request->request->all());
$view = $this->renderView('job_board/_filter.html.twig', [
'jobs' => $jobs,
]);
return $this->json([
'data' => $view,
'total' => count($jobs)
]);
}
/**
* @Route("/{_locale}/offres-alternances-et-stages/{slug}", requirements={"_locale": "en|fr", "slug": "[a-zA-Z0-9\-]+"}, defaults={"_locale"="fr"}, name="job_board.detail")
*/
public function detail(
$slug,
Request $request,
TranslatorInterface $translator
) {
$job = $this->offerRepo->getBySlug($slug, $request);
if(!$job){
return $this->render('pages/404.html.twig');
}
$this->addTitle($job->offerTitle);
$this->setDescription($job->offerTitle);
$data['job'] = $job;
$data['jobs'] = $this->offerRepo->getListLasted($job->id);
return $this->render(
'job_board/detail.html.twig',
$data
);
}
/**
* @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")
*/
public function applyJob(
$slug,
Request $request,
StudyLevelRepository $studyLevelRepository,
TranslatorInterface $translator
) {
$job = $this->offerRepo->getBySlug($slug, $request);
if (!$job) throw $this->createNotFoundException('');
$this->addTitle($job->offerTitle);
$this->setDescription($job->offerTitle);
$data['job'] = $job;
$data['studyLevels'] = $studyLevelRepository->findAll();
$data['statusCandidate'] = $this->jobCandidateService->listStatusCandidate();
return $this->render(
'job_board/apply.html.twig',
$data
);
}
/**
* @Route("/job-save-apply", name="job.save_apply")
* @Log
*/
public function saveOffer(
Request $request,
CaptchaHelper $captchaHelper,
TranslatorInterface $translator
) {
try {
if ($this->getParameter('captcha_enabled') && !$captchaHelper->isCaptchaValid($request)) {
return $this->json(ServiceUtil::processFailed([
'errorMessage' => $translator->trans('message.captcha_is_not_valid')
]));
}
$this->jobCandidateService->addEntity($request);
return $this->json(ServiceUtil::processSuccessful());
} catch (BadRequestException $badRequestException) {
$messagesArr = $badRequestException->getMessages();
foreach ($messagesArr['data'] as $message) {
$errorMessage = $message;
break;
}
}
$data['errorMessage'] = $errorMessage;
return $this->json(ServiceUtil::processFailed($data));
}
}