<?php
namespace App\Controller\Frontend;
use App\Misc\CaptchaHelper;
use App\Repository\CampusRepository;
use App\Utilities\ServiceUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Exception\BadRequestException;
use App\Repository\CountryRepository;
use App\Repository\RecruitmentThemeRepository;
use App\Annotation\Log;
class RecruitmentController extends BaseFrontendController
{
/**
* @Route("/{_locale}/collaborer-avec-estiam", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="recruitmemt.index")
*/
public function index(
TranslatorInterface $translator,
RecruitmentThemeRepository $recruitmentThemeRepository,
CampusRepository $campusRepository,
CountryRepository $countryRepository
) {
$siteName = $translator->trans('siteName');
$this->addTitle($translator->trans(
'recruitment.title',
[
'%siteName%' => $siteName
]
));
$this->setDescription($translator->trans(
'recruitment.desc',
[
'%siteName%' => $siteName
]
));
$data['themes'] = $recruitmentThemeRepository->findBy([], ['name' => 'asc']);
$data['campuses'] = $campusRepository->findBy(['status' => 1], ['name' => 'asc']);
$data['countries'] = $countryRepository->findBy([], ['ordering' => 'asc']);
return $this->render(
'recrutement/index.html.twig',
$data
);
}
/**
* @Route("/save-recruitmemt", name="recruitmemt.save")
* @Log
*/
public function saveRecruitmemt(
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->currentService->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));
}
}