<?php
namespace App\Controller\ThemesWebsite\Cvs\Website;
use App\Entity\Cvs\Candidates;
use App\Entity\Cvs\Categories;
use App\Entity\Pages\Pages;
use App\Form\Cvs\SearchCandidatesForm;
use App\Services\Core\RequestData;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
class CandidatesController extends AbstractController
{
private $rd;
private $em;
private $paginator;
public function __construct(RequestData $rd,
EntityManagerInterface $em,
PaginatorInterface $paginator
) {
$this->rd = $rd;
$this->em = $em;
$this->paginator = $paginator;
}
/**
* Candidats
* @param Request $request
* @return Response
*/
public function list(Request $request): Response
{
$session = $request->getSession();
$queryKeyword = $session->get('queryKeyword');
$queryLocalisation = $session->get('queryLocalisation');
$queryPointsX = $session->get('queryPointsX');
$queryPointsY = $session->get('queryPointsY');
$queryCategories = $session->get('queryCategories');
$page = $this->em->getRepository(Pages::class)->findOneBy(['name' => 'candidates']);
$categories = $this->em->getRepository(Categories::class)->findAll();
$form = $this->createForm(SearchCandidatesForm::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $request->request->all();
$search = $data['search_candidates_form'];
$localisation = $search['localisation'];
$queryCategories = "";
if(isset($data['categories'])) {
$queryCategories = $data['categories'];
}
$points = $this->rd->getPoints($localisation);
$session->set('queryLocalisation',$localisation);
$session->set('queryPointsX',$points[0]);
$session->set('queryPointsY',$points[1]);
$session->set('queryCategories',$queryCategories);
$session->set('queryKeyword',$search['title']);
return $this->redirect($this->generateUrl('cvs_website_candidates'));
}
$candidates = $this->em->getRepository(Candidates::class)->searchBy($queryKeyword,$queryPointsX,$queryPointsY,$queryCategories);
$pagination = $this->paginator->paginate(
$candidates,
$request->query->getInt('page', 1),
15
);
return $this->render('themesWebsite/cvs/website/candidates/list.html.twig',[
'candidates' => $pagination,
'page' => $page,
'categories' => $categories,
'form' => $form->createView(),
'queryTitle' => $queryKeyword,
'queryLocalisation' => $queryLocalisation,
'queryCategories' => $queryCategories,
'countCandidates' => count($candidates)
]);
}
public function dataSkill(Request $request, $skill)
{
$queryTitle = $_POST['queryTitle'];
$queryLocalisation = $_POST['queryLocalisation'];
$queryCategories = $_POST['queryCategories'];
$count = $this->em->getRepository(Candidates::class)->countSkillBy($queryTitle,$queryLocalisation,$queryCategories,$skill);
return new JsonResponse($count);
}
}