src/Controller/Front/OffreEmploiController.php line 22

  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Contrats;
  4. use App\Entity\Domaines;
  5. use App\Entity\Region;
  6. use App\Repository\OffreEmploiRepository;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class OffreEmploiController extends AbstractController
  13. {
  14.     public function __construct(private EntityManagerInterface $entityManager, private OffreEmploiRepository $offreEmploiRepository)
  15.     {
  16.     }
  17.     #[Route('/offres-emploi'name'app_offre_emploi_list')]
  18.     public function recherche(Request $request): Response
  19.     {
  20.         $domaines $this->entityManager->getRepository(Domaines::class)->findAll();
  21.         $regions $this->entityManager->getRepository(Region::class)->findAll();
  22.         $contrats $this->entityManager->getRepository(Contrats::class)->findAll();
  23.         $domaine $request->get('domaine');
  24.         $region $request->get('region');
  25.         $contrat $request->get('contrat');
  26.         if (null === $domaine && null === $region && null === $contrat) {
  27.             $offreEmplois $this->offreEmploiRepository->findBy(['visible' => true]);
  28.         } else {
  29.             $offreEmplois $this->offreEmploiRepository->findBySearch($domaine$region$contrat);
  30.         }
  31.         return $this->render('front/offre_emploi/index.html.twig', [
  32.             'domaines' => $domaines,
  33.             'regions' => $regions,
  34.             'contrats' => $contrats,
  35.             'domaineSearch' => $domaine,
  36.             'regionSearch' => $region,
  37.             'contratSearch' => $contrat,
  38.             'offreEmplois' => $offreEmplois,
  39.         ]);
  40.     }
  41.     #[
  42.         Route('/offre-emploi/{offreEmploi<[0-9]\d*>}'name'app_offre_emploi_detail'),
  43.         Route('/offre-emploi/{slug}'name'app_offre_emploi_detail_slug')
  44.     ]
  45.     public function detail(
  46.         ?int $offreEmploi,
  47.         ?string $slug
  48.     ): Response {
  49.         if (!$slug) {
  50.             $offreEmploi $this->offreEmploiRepository->find($offreEmploi);
  51.         } else {
  52.             $offreEmploi $this->offreEmploiRepository->findOneBy(['slug' => $slug]);
  53.         }
  54.         if (null === $offreEmploi || (!$this->isGranted('ROLE_ADMIN') && false === $offreEmploi->isVisible())) {
  55.             throw $this->createNotFoundException('Page not found');
  56.         }
  57.         if ($this->isGranted('ROLE_ADMIN') && false === $offreEmploi->isVisible()) {
  58.             $this->addFlash('success''Cette page est visible car vous ĂȘte administrateur');
  59.         }
  60.         $offreEmplois $this->offreEmploiRepository->findOther($offreEmploi);
  61.         return $this->render('front/offre_emploi/detail.html.twig', [
  62.             'offreEmploi' => $offreEmploi,
  63.             'offreEmplois' => $offreEmplois,
  64.         ]);
  65.     }
  66. }