src/Controller/VideoController.php line 83

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Video;
  4. use App\Entity\Ville;
  5. use App\Entity\Region;
  6. use App\Service\Slugify;
  7. use App\Entity\Departement;
  8. use App\Entity\Etablissement;
  9. use Knp\Component\Pager\PaginatorInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. class VideoController extends AbstractController
  16. {
  17.     private const LIMIT 1000;
  18.     private const HEADERLIMIT 2// Nbre de video à afficher dans l'onglet du header
  19.     private const PER_PAGE 15;
  20.     /** @var Slugify */
  21.     private $slugify;
  22.     /** @var PaginatorInterface */
  23.     private $paginator;    
  24.     public function __construct(Slugify $slugifyPaginatorInterface $paginator)
  25.     {
  26.         $this->slugify $slugify;
  27.         $this->paginator $paginator;
  28.     }
  29.     /**
  30.      * @Route("/videos/{lieu}/{etablissement}", name="video-liste", defaults={"etablissement": null, "lieu":"default"}, methods={"GET", "POST"})
  31.      */
  32.     public function list(?Etablissement $etablissementRequest $requeststring $lieu=null): Response
  33.     {
  34.         $filter = [];
  35.         if ($etablissement) {
  36.             $filter['etablissement'] = $etablissement->getId();
  37.         }
  38.         $currentURL $request->getPathInfo();
  39.         if ($lieu != 'default') {
  40.             return $this->redirectToRoute('video-liste', [], 301);
  41.             // $currentURL = explode("/", $currentURL );
  42.             // array_pop($currentURL);
  43.             // $currentURL = implode("/", $currentURL );
  44.         }
  45.         $types = [];
  46.         $ecole = [];
  47.         $college = [];
  48.         $lycee = [];
  49.         $professionnel = [];
  50.         $superieur = [];
  51.         $niveaux $request->query->get('niveau');
  52.         if($niveaux){
  53.             if(in_array('ecole'$niveaux))
  54.                 $ecole = ['02-ELEM''03-PRIM''01-MATER'];
  55.             if(in_array('college'$niveaux))
  56.                 $college = ['04-COLL'];
  57.             if(in_array('lycee'$niveaux))
  58.                 $lycee = ['05-LGEN''06-LTECH''07-LEGT'];
  59.             if(in_array('professionnel'$niveaux))
  60.                 $professionnel = ['08-LAGRI''09-LPROF''10-LEAP'];
  61.             if(in_array('superieur'$niveaux))
  62.                 $superieur = ['12-SUP'];
  63.             $types array_merge($ecole$college$lycee$professionnel$superieur);
  64.         }
  65.         $lieu $this->slugify->revealLieu($lieu);
  66.         if ($lieu == null)
  67.             return $this->redirectToRoute('video-liste', [], 301);
  68.         $regions $this->getDoctrine()->getRepository(Region::class)->findAll();
  69.         $repositoryDepartement $this->getDoctrine()->getRepository(Departement::class);
  70.         $repositoryVille $this->getDoctrine()->getRepository(Ville::class);
  71.         $departements $repositoryDepartement->findRelatifsAuLieu($lieu);
  72.         $villes $repositoryVille->findRelatifsAuLieu($lieu);
  73.         $repositoryVideo $this->getDoctrine()->getRepository(Video::class);
  74.         $videos $repositoryVideo->findByLieu($lieuself::LIMIT$filter$types);
  75.         $videos $this->paginator->paginate(
  76.             $videos,
  77.             $request->query->getInt('page'1),
  78.             self::PER_PAGE
  79.         );
  80.         // Pour le SEO
  81.         $lieuLibelle null;
  82.         if ($lieu) {
  83.             if ($lieu instanceof Ville)
  84.                 $lieuLibelle $lieu->getLibelle() . " - " $lieu->getCodePostal();
  85.             elseif ($lieu instanceof Departement)
  86.                 $lieuLibelle $lieu->getLibelle() . " (" $lieu->getId() . ")";
  87.             else
  88.                 $lieuLibelle $lieu->getLibelle();
  89.         }
  90.         return $this->render('video/list.html.twig', [
  91.             'etablissement' => $etablissement,
  92.             'videos' => $videos,
  93.             'regions' => $regions,
  94.             'departements' => $departements,
  95.             'villes' => $villes,
  96.             'niveaux' => $niveaux,
  97.             'currentURL' => $currentURL,
  98.             'lieu' => $lieu,
  99.             'lieuLibelle' => $lieuLibelle,
  100.             'robots_tag' => "noindex,follow",
  101.         ]);
  102.     }
  103.     /**
  104.      * @Route("/videos/fiche/{id}", name="video-etab", methods={"GET", "POST"})
  105.      */
  106.     public function fiche(?Video $video): Response
  107.     {
  108.         if (!$video) {
  109.             return $this->redirectToRoute('video-liste', [], 301);
  110.         }
  111.         // $this->etabNonLuService->markAsRead($actualite);
  112.         return $this->render('video/fiche.html.twig', [
  113.             'video' => $video,
  114.         ]);
  115.     }
  116.     /**
  117.      * @Route(
  118.      *     "/video/header",
  119.      *     name="video-header",
  120.      *     methods={"GET"}
  121.      * )
  122.      * @Cache(expires="+1 minutes")
  123.      */
  124.     public function headerList(): Response
  125.     {
  126.         $videos $this->getDoctrine()->getRepository(Video::class)->findBy(
  127.             [],
  128.             ['dateCrea' => 'DESC'],
  129.             self::HEADERLIMIT
  130.         );
  131.         return $this->render('video/dropdown.html.twig', [
  132.             'videos' => $videos,
  133.         ]);
  134.     }
  135.     public function blocVideosALaUne($type null): Response
  136.     {
  137.         // Bloc "Videos à la une"
  138.         $videos $this->getDoctrine()->getRepository(Video::class)->findAlaUne(5);
  139.         return $this->render('partial/video-une.html.twig', [
  140.             'videos' => $videos,
  141.             'type' => $type
  142.         ]);
  143.     }
  144. }