<?php
namespace App\Controller\Frontend;
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\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Exception\BadRequestException;
use App\Annotation\Log;
class OfferController extends BaseFrontendController
{
/**
* @Route("/{_locale}/entreprises-offre-demploi", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="offer.index")
*/
public function index(
TranslatorInterface $translator,
ExpertiseRepository $expertiseRepository,
StudyLevelRepository $studyLevelRepository,
ContractRepository $contractRepository,
CampusRepository $campusRepository,
SkillRepository $skillRepository
) {
$this->addTitle($translator->trans(
'offer.title'
));
$this->setDescription($translator->trans(
'offer.desc'
));
$data['expertises'] = $expertiseRepository->findAll();
$data['studyLevels'] = $studyLevelRepository->findAll();
$data['contracts'] = $contractRepository->findAll();
$data['campuses'] = $campusRepository->findBy(['status' => 1], ['ordering' => 'DESC','name' => 'ASC']);
$data['skills'] = $skillRepository->findBy([]);
return $this->render(
'offer/index.html.twig',
$data
);
}
/**
* @Route("/save-offer", name="offer.save")
* @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->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));
}
}