From d07cbb15da434c6afef9a54172da30acbfaf72b0 Mon Sep 17 00:00:00 2001 From: Tchama Date: Thu, 17 Jan 2019 13:59:20 +0100 Subject: [PATCH] list events by person, add pagination --- Controller/EventController.php | 34 +++++++++++++++++--- Resources/views/Event/listByPerson.html.twig | 17 ++++++---- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 49f438713..e98486ef7 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -259,11 +259,36 @@ class EventController extends Controller $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); - $participations = $em->getRepository('ChillEventBundle:Participation') - ->findBy( - array('person' => $person) ); + $total = $em + ->createQuery(" + SELECT COUNT (participation.id) + FROM ChillEventBundle:Participation participation + WHERE participation.person = :person_id + ") + ->setParameter(':person_id', $person_id) + ->getSingleScalarResult(); + + /* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */ + $paginatorFactory = $this->get('chill_main.paginator_factory'); + $paginator = $paginatorFactory->create($total); + + $participations = $em + ->createQuery(" + SELECT participation + FROM ChillEventBundle:Participation participation + WHERE participation.person = :person_id + ") + ->setParameters(array( + ':person_id' => $person_id, + )) + ->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber()) + ->setMaxResults($paginator->getItemsPerPage()) + ->getResult() + ; + + $privacyEvent = new PrivacyEvent($person, array( 'element_class' => Participation::class, 'action' => 'list' @@ -272,7 +297,8 @@ class EventController extends Controller return $this->render('ChillEventBundle:Event:listByPerson.html.twig', array( 'participations' => $participations, - 'person' => $person + 'person' => $person, + 'paginator' => $paginator )); } } diff --git a/Resources/views/Event/listByPerson.html.twig b/Resources/views/Event/listByPerson.html.twig index f36278197..2f553c284 100644 --- a/Resources/views/Event/listByPerson.html.twig +++ b/Resources/views/Event/listByPerson.html.twig @@ -58,11 +58,11 @@