<?php
namespace App\Controller;
use App\Entity\VideoOnpc as Video;
use App\Service\Slugify;
use App\Entity\Etablissement;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class VideoOnpcController extends AbstractController
{
private const LIMIT = 1000;
private const HEADERLIMIT = 2; // Nbre de video à afficher dans l'onglet du header
private const PER_PAGE = 15;
/** @var Slugify */
private $slugify;
/** @var PaginatorInterface */
private $paginator;
public function __construct(Slugify $slugify, PaginatorInterface $paginator)
{
$this->slugify = $slugify;
$this->paginator = $paginator;
}
/**
* @Route("/webtv/", name="video-onpc-liste", methods={"GET", "POST"})
*/
public function list(Request $request): Response
{
$currentURL = $request->getPathInfo();
$repositoryVideo = $this->getDoctrine()->getRepository(Video::class);
$videos = $repositoryVideo->findBy([], ['createdAt' => 'DESC']);
$videos = $this->paginator->paginate(
$videos,
$request->query->getInt('page', 1),
self::PER_PAGE
);
return $this->render('video-onpc/list.html.twig', [
'videos' => $videos,
'currentURL' => $currentURL,
// 'robots_tag' => "noindex,follow",
]);
}
/**
* @Route("/webtv/{slug}", name="video-promo-fiche", methods={"GET", "POST"})
*/
public function fiche(?Video $video): Response
{
if (!$video) {
return $this->redirectToRoute('video-onpc-liste', [], 301);
}
return $this->render('video-onpc/fiche.html.twig', [
'video' => $video,
]);
}
}