src/Controller/ThemesWebsite/Cvs/Website/CandidatesController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ThemesWebsite\Cvs\Website;
  3. use App\Entity\Cvs\Candidates;
  4. use App\Entity\Cvs\Categories;
  5. use App\Entity\Pages\Pages;
  6. use App\Form\Cvs\SearchCandidatesForm;
  7. use App\Services\Core\RequestData;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\HttpFoundation\Cookie;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  20. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  21. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use Knp\Component\Pager\PaginatorInterface;
  24. class CandidatesController extends AbstractController
  25. {
  26.     private $rd;
  27.     private $em;
  28.     private $paginator;
  29.     public function __construct(RequestData $rd,
  30.                                 EntityManagerInterface $em,
  31.                                 PaginatorInterface $paginator
  32.     ) {
  33.         $this->rd $rd;
  34.         $this->em $em;
  35.         $this->paginator $paginator;
  36.     }
  37.     /**
  38.      * Candidats
  39.      * @param Request $request
  40.      * @return Response
  41.      */
  42.     public function list(Request $request): Response
  43.     {
  44.         $session $request->getSession();
  45.         $queryKeyword =  $session->get('queryKeyword');
  46.         $queryLocalisation =  $session->get('queryLocalisation');
  47.         $queryPointsX =  $session->get('queryPointsX');
  48.         $queryPointsY =  $session->get('queryPointsY');
  49.         $queryCategories =  $session->get('queryCategories');
  50.         $page $this->em->getRepository(Pages::class)->findOneBy(['name' => 'candidates']);
  51.         $categories $this->em->getRepository(Categories::class)->findAll();
  52.         $form $this->createForm(SearchCandidatesForm::class);
  53.         $form->handleRequest($request);
  54.         if ($form->isSubmitted() && $form->isValid()) {
  55.             $data $request->request->all();
  56.             $search $data['search_candidates_form'];
  57.             $localisation $search['localisation'];
  58.             $queryCategories "";
  59.             if(isset($data['categories'])) {
  60.                 $queryCategories $data['categories'];
  61.             }
  62.             $points $this->rd->getPoints($localisation);
  63.             $session->set('queryLocalisation',$localisation);
  64.             $session->set('queryPointsX',$points[0]);
  65.             $session->set('queryPointsY',$points[1]);
  66.             $session->set('queryCategories',$queryCategories);
  67.             $session->set('queryKeyword',$search['title']);
  68.             return $this->redirect($this->generateUrl('cvs_website_candidates'));
  69.         }
  70.         $candidates $this->em->getRepository(Candidates::class)->searchBy($queryKeyword,$queryPointsX,$queryPointsY,$queryCategories);
  71.         $pagination $this->paginator->paginate(
  72.             $candidates,
  73.             $request->query->getInt('page'1),
  74.             15
  75.         );
  76.         return $this->render('themesWebsite/cvs/website/candidates/list.html.twig',[
  77.             'candidates' => $pagination,
  78.             'page' => $page,
  79.             'categories' => $categories,
  80.             'form' => $form->createView(),
  81.             'queryTitle' => $queryKeyword,
  82.             'queryLocalisation' => $queryLocalisation,
  83.             'queryCategories' => $queryCategories,
  84.             'countCandidates' => count($candidates)
  85.         ]);
  86.     }
  87.     public function dataSkill(Request $request$skill)
  88.     {
  89.         $queryTitle $_POST['queryTitle'];
  90.         $queryLocalisation $_POST['queryLocalisation'];
  91.         $queryCategories $_POST['queryCategories'];
  92.         $count $this->em->getRepository(Candidates::class)->countSkillBy($queryTitle,$queryLocalisation,$queryCategories,$skill);
  93.         return new JsonResponse($count);
  94.     }
  95. }