src/Controller/OrganismeController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use App\Entity\Etablissement;
  6. use App\Entity\CategorieOrganisme;
  7. use App\Entity\Departement;
  8. use App\Entity\Region;
  9. use App\Entity\QuoiMotCle;
  10. use Knp\Component\Pager\PaginatorInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. class OrganismeController extends AbstractController
  13. {
  14.     private const PER_PAGE 10;
  15.     /** @var PaginatorInterface */
  16.     private $paginator;
  17.     public function __construct(PaginatorInterface $paginator)
  18.     {
  19.         $this->paginator $paginator;
  20.     }
  21.     // Redirection des anciennes URLs
  22.     // Exp : /fiche_organismes?id=OR075-9
  23.     /**
  24.      * @Route("/fiche_organismes", name="old_fiche_organismes")
  25.      */
  26.     public function oldFicheOrganismes(Request $request)
  27.     {
  28.         $id $request->query->get('id');
  29.         return $this->redirectToRoute('fiche-organisme', ['id' => $id], 301);
  30.     }
  31.     /**
  32.      * @Route("/organisme", name="organisme")
  33.      */
  34.     public function index()
  35.     {
  36.         // Catégories d'organismes
  37.         $categories $this->getDoctrine()->getRepository(CategorieOrganisme::class)->findAll();
  38.         $departements =  $this->getDoctrine()->getRepository(Departement::class)->findAll();
  39.         $regions =  $this->getDoctrine()->getRepository(Region::class)->findAll();
  40.         return $this->render('organisme/index.html.twig', [
  41.             'categories' => $categories,
  42.             'departements' => $departements,
  43.             'regions' => $regions,
  44.             'quoi' => new QuoiMotCle('organisme'),
  45.         ]);
  46.     }
  47.     /**
  48.      * @Route("/organismes/centres-d-orientation-publics/", name="organismes_cop")
  49.      */
  50.     public function listeDesCentresDOrientationPublics(Request $request)
  51.     {
  52.         $organismes $this->paginator->paginate(
  53.             $this->getDoctrine()->getRepository(Etablissement::class)
  54.                         ->findOrganismesCentresOrientationPublics(),
  55.             $request->query->getInt('page'1),
  56.             self::PER_PAGE
  57.         );
  58.         return $this->render('organisme/liste.html.twig', [
  59.             'organismes' => $organismes,
  60.             'index' => false
  61.         ]);
  62.     }
  63.     /**
  64.      * @Route("/organismes/{categorie}/1", name="organismes_tous")
  65.      */
  66.     public function listeDeTousLesOrganismesParCategorie(CategorieOrganisme $categorieRequest $request)
  67.     {
  68.         $organismes $this->paginator->paginate(
  69.             $this->getDoctrine()->getRepository(Etablissement::class)->findByCategorieOrganisme($categorie),
  70.             $request->query->getInt('page'1),
  71.             self::PER_PAGE
  72.         );
  73.         return $this->render('organisme/liste.html.twig', [
  74.             'categorie'  => $categorie,
  75.             'organismes' => $organismes,
  76.             'quoi' => new QuoiMotCle('organisme'),
  77.             'departement' => null,
  78.             'region' => null,
  79.             'noindex' => false
  80.         ]);
  81.     }
  82.     /**
  83.      * @Route("/fiche_organismes/{etablissement}", name="organisme_fiche")
  84.      */
  85.     public function ficheOrganisme(Etablissement $etablissement)
  86.     {
  87.         return $this->render('organisme/fiche.html.twig', [
  88.             'etablissement'  => $etablissement,
  89.             'noindex' => true
  90.         ]);
  91.     }
  92.     /**
  93.      * @Route("/organismes/departement/{departementSlug}/{departementId}/{categorie}/1", name="organismes_departement")
  94.      * @Route("/organismes/region/{regionSlug}/{regionId}/{categorie}/1", name="organismes_region")
  95.      */
  96.     public function listeParDepartementEtCategorie(CategorieOrganisme $categorie$departementId null$regionId=nullRequest $request)
  97.     {
  98.         $catholique  ="catholique";
  99.         $organismes $this->getDoctrine()->getRepository(Etablissement::class)
  100.                         ->findOrganismes($catholique$categorie->getId(), $departementId$regionId);
  101.         $departement $departementId $this->getDoctrine()->getRepository(Departement::class)->find($departementId): null;
  102.         $region =  $regionId $this->getDoctrine()->getRepository(Region::class)->find($regionId): null;
  103.         $pagination $this->paginator->paginate(
  104.             $organismes/* query NOT result */
  105.             $request->query->getInt('page'1), /*page number*/
  106.             10 /*limit per page*/
  107.         );
  108.         return $this->render('organisme/liste.html.twig', [
  109.             'categorie'  => $categorie,
  110.             'organismes' => $pagination,
  111.             'departement'=>$departement,
  112.             'region'=>$region,
  113.             'noindex' => true
  114.         ]);
  115.     }
  116.     /**
  117.      * @Route("/orientation-scolaire", name="organismes_cos")
  118.      */
  119.     public function listeDesCentresDOrientationScolaire(Request $request)
  120.     {
  121.         $organismes $this->paginator->paginate(
  122.             $this->getDoctrine()->getRepository(Etablissement::class)->findCentresOrientationScolaire(),
  123.             $request->query->getInt('page'1),
  124.             self::PER_PAGE
  125.         );
  126.         return $this->render('organisme/liste.html.twig', [
  127.             'organismes' => $organismes,
  128.         ]);
  129.     }
  130. }