diff --git a/app/Resources/views/admin/event/list.html.twig b/app/Resources/views/admin/event/list.html.twig
index 77ad935aa..76b999fd9 100644
--- a/app/Resources/views/admin/event/list.html.twig
+++ b/app/Resources/views/admin/event/list.html.twig
@@ -10,7 +10,7 @@
{% endblock %}
{% block content %}
-
Liste des événements ({{ events | length }})
+Liste des événements ({{ result_count }})
{# Filter form --------- #}
@@ -36,6 +36,24 @@
{% include "admin/event/_partial/table.html.twig" with { events: events } %}
+
+
{% if is_granted("ROLE_ADMIN") %}
listToutes les procurations
@@ -43,3 +61,15 @@
addAjouter un événement
{% endif %}
{% endblock %}
+
+{% block javascripts %}
+
+{% endblock %}
diff --git a/src/AppBundle/Controller/EventController.php b/src/AppBundle/Controller/EventController.php
index f0c537128..416d48f41 100644
--- a/src/AppBundle/Controller/EventController.php
+++ b/src/AppBundle/Controller/EventController.php
@@ -11,11 +11,13 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
+use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
+use Doctrine\ORM\Tools\Pagination\Paginator;
/**
@@ -33,6 +35,7 @@ private function filterFormFactory(Request $request): array
// default values
$res = [
"kind" => null,
+ 'page' => 1,
];
// filter creation ----------------------
@@ -49,6 +52,9 @@ private function filterFormFactory(Request $request): array
->orderBy('ek.name', 'ASC');
},
))
+ ->add('page', HiddenType::class, [
+ 'data' => '1'
+ ])
->add('submit', SubmitType::class, array(
'label' => 'Filtrer',
'attr' => array('class' => 'btn', 'value' => 'filtrer')
@@ -59,6 +65,7 @@ private function filterFormFactory(Request $request): array
if ($res["form"]->isSubmitted() && $res["form"]->isValid()) {
$res["kind"] = $res["form"]->get("kind")->getData();
+ $res["page"] = $res["form"]->get("page")->getData();
}
return $res;
@@ -94,20 +101,35 @@ public function listAction(Request $request)
$em = $this->getDoctrine()->getManager();
$filter = $this->filterFormFactory($request);
- $findByFilter = array();
$sort = 'date';
$order = 'DESC';
+ $qb = $em->getRepository('AppBundle:Event')->createQueryBuilder('e')
+ ->orderBy('e.' . $sort, $order);
+
if ($filter['kind']) {
- $findByFilter['kind'] = $filter['kind'];
+ $qb = $qb->andWhere('e.kind = :kind')
+ ->setParameter('kind', $filter['kind']);
}
- $events = $em->getRepository('AppBundle:Event')
- ->findBy($findByFilter, array($sort => $order));
+ $limitPerPage = 25;
+ $paginator = new Paginator($qb);
+ $resultCount = count($paginator);
+ $pageCount = ($resultCount == 0) ? 1 : ceil($resultCount / $limitPerPage);
+ $currentPage = $filter['page'];
+ $currentPage = ($currentPage > $pageCount) ? $pageCount : $currentPage;
+
+ $paginator
+ ->getQuery()
+ ->setFirstResult($limitPerPage * ($currentPage-1)) // set the offset
+ ->setMaxResults($limitPerPage); // set the limit
return $this->render('admin/event/list.html.twig', array(
- 'events' => $events,
+ 'events' => $paginator,
'filter_form' => $filter['form']->createView(),
+ 'result_count' => $resultCount,
+ 'current_page' => $currentPage,
+ 'page_count' => $pageCount,
));
}