<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Etablissement;
use App\Entity\CategorieOrganisme;
use App\Entity\Departement;
use App\Entity\Region;
use App\Entity\QuoiMotCle;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
class OrganismeController extends AbstractController
{
private const PER_PAGE = 10;
/** @var PaginatorInterface */
private $paginator;
public function __construct(PaginatorInterface $paginator)
{
$this->paginator = $paginator;
}
// Redirection des anciennes URLs
// Exp : /fiche_organismes?id=OR075-9
/**
* @Route("/fiche_organismes", name="old_fiche_organismes")
*/
public function oldFicheOrganismes(Request $request)
{
$id = $request->query->get('id');
return $this->redirectToRoute('fiche-organisme', ['id' => $id], 301);
}
/**
* @Route("/organisme", name="organisme")
*/
public function index()
{
// Catégories d'organismes
$categories = $this->getDoctrine()->getRepository(CategorieOrganisme::class)->findAll();
$departements = $this->getDoctrine()->getRepository(Departement::class)->findAll();
$regions = $this->getDoctrine()->getRepository(Region::class)->findAll();
return $this->render('organisme/index.html.twig', [
'categories' => $categories,
'departements' => $departements,
'regions' => $regions,
'quoi' => new QuoiMotCle('organisme'),
]);
}
/**
* @Route("/organismes/centres-d-orientation-publics/", name="organismes_cop")
*/
public function listeDesCentresDOrientationPublics(Request $request)
{
$organismes = $this->paginator->paginate(
$this->getDoctrine()->getRepository(Etablissement::class)
->findOrganismesCentresOrientationPublics(),
$request->query->getInt('page', 1),
self::PER_PAGE
);
return $this->render('organisme/liste.html.twig', [
'organismes' => $organismes,
'index' => false
]);
}
/**
* @Route("/organismes/{categorie}/1", name="organismes_tous")
*/
public function listeDeTousLesOrganismesParCategorie(CategorieOrganisme $categorie, Request $request)
{
$organismes = $this->paginator->paginate(
$this->getDoctrine()->getRepository(Etablissement::class)->findByCategorieOrganisme($categorie),
$request->query->getInt('page', 1),
self::PER_PAGE
);
return $this->render('organisme/liste.html.twig', [
'categorie' => $categorie,
'organismes' => $organismes,
'quoi' => new QuoiMotCle('organisme'),
'departement' => null,
'region' => null,
'noindex' => false
]);
}
/**
* @Route("/fiche_organismes/{etablissement}", name="organisme_fiche")
*/
public function ficheOrganisme(Etablissement $etablissement)
{
return $this->render('organisme/fiche.html.twig', [
'etablissement' => $etablissement,
'noindex' => true
]);
}
/**
* @Route("/organismes/departement/{departementSlug}/{departementId}/{categorie}/1", name="organismes_departement")
* @Route("/organismes/region/{regionSlug}/{regionId}/{categorie}/1", name="organismes_region")
*/
public function listeParDepartementEtCategorie(CategorieOrganisme $categorie, $departementId = null, $regionId=null, Request $request)
{
$catholique ="catholique";
$organismes = $this->getDoctrine()->getRepository(Etablissement::class)
->findOrganismes($catholique, $categorie->getId(), $departementId, $regionId);
$departement = $departementId ? $this->getDoctrine()->getRepository(Departement::class)->find($departementId): null;
$region = $regionId ? $this->getDoctrine()->getRepository(Region::class)->find($regionId): null;
$pagination = $this->paginator->paginate(
$organismes, /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('organisme/liste.html.twig', [
'categorie' => $categorie,
'organismes' => $pagination,
'departement'=>$departement,
'region'=>$region,
'noindex' => true
]);
}
/**
* @Route("/orientation-scolaire", name="organismes_cos")
*/
public function listeDesCentresDOrientationScolaire(Request $request)
{
$organismes = $this->paginator->paginate(
$this->getDoctrine()->getRepository(Etablissement::class)->findCentresOrientationScolaire(),
$request->query->getInt('page', 1),
self::PER_PAGE
);
return $this->render('organisme/liste.html.twig', [
'organismes' => $organismes,
]);
}
}