<?php
namespace App\Controller;
use App\Entity\Admin\Article;
use App\Repository\Admin\ArticleRepository;
use App\Repository\Admin\ThemeRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/evenements")
*/
class EvenementController extends AbstractController
{
/**
* @Route("/", name="evenement_all")
*/
public function all(Request $request, ArticleRepository $articleRepository, ThemeRepository $themeRepository, PaginatorInterface $paginator){
if ($request->get('theme_id')){
$theme_id = $request->get('theme_id');
//$articles = $articleRepository->findByThemeOrderedByDateDesc($themeRepository->find($theme_id));
$articles = $paginator->paginate($articleRepository->findByThemeOrderedByDateDesc($theme_id),
$request->query->getInt('page', 1),
5
);
}else{
$theme_id = null;
//$articles = $articleRepository->findAllByDateDesc();
$articles = $paginator->paginate($articleRepository->findAllByDateDesc(),
$request->query->getInt('page', 1),
5
);
}
$themes = $themeRepository->showAll();
return $this->render('evenement/all.html.twig', [
'articles' => $articles,
'themes' => $themes,
'theme_id' => $theme_id,
]);
}
/**
* @Route("/{slug}/{id}", name="evenement_single")
*/
public function show(Request $request, Article $article, ThemeRepository $themeRepository)
{
$themes = $themeRepository->showAll();
$theme_id = null;
return $this->render('evenement/single.html.twig', [
'article' => $article,
'theme_id' => $theme_id,
'themes' => $themes,
]);
}
}