From 332bec6e83e93fd80a392605a4ff0e0f12903482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 22 Jun 2017 23:05:19 +0200 Subject: [PATCH] fix gitlab tests --- .gitlab-ci.yml | 5 +++-- Controller/ReportController.php | 30 ++++++++++++++++++++++----- Resources/views/Report/list.html.twig | 4 ++++ composer.json | 14 ++++++++----- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe90372ed..ce6e7ca72 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,11 +16,12 @@ stages: - build-doc - deploy-doc -test:php-5.6: +test:php-7.1: stage: test - image: chill/ci-image:php-5.6 + image: chill/ci-image:php-7.1 <<: *test_definition script: phpunit + test:php-7: stage: test image: chill/ci-image:php-7 diff --git a/Controller/ReportController.php b/Controller/ReportController.php index 0f49e406d..87c3eaae9 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -52,12 +52,32 @@ class ReportController extends Controller $reachableScopes = $this->get('chill.main.security.authorization.helper') ->getReachableScopes($this->getUser(), new Role('CHILL_REPORT_SEE'), $person->getCenter()); - $reports = $em->getRepository('ChillReportBundle:Report') - ->findBy(array('person' => $person, 'scope' => $reachableScopes)); - + + $total = $em + ->createQuery("SELECT COUNT(r.id) FROM ChillReportBundle:Report r " + . "WHERE r.person = :person AND r.scope IN (:scopes) ") + ->setParameter('person', $person) + ->setParameter('scopes', $reachableScopes) + ->getSingleScalarResult(); + + // get the PaginatorFactory + $paginator = $this->get('chill_main.paginator_factory')->create($total); + + $reports = $em->createQuery('SELECT r + FROM ChillReportBundle:Report r + WHERE r.person = :person AND r.scope IN (:scopes) + ORDER BY r.date DESC') + ->setParameter('person', $person) + ->setParameter('scopes', $reachableScopes) + ->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber()) + ->setMaxResults($paginator->getItemsPerPage()) + ->getResult() + ; + return $this->render('ChillReportBundle:Report:list.html.twig', array( - 'reports' => $reports, - 'person' => $person + 'reports' => $reports, + 'person' => $person, + 'paginator' => $paginator )); } diff --git a/Resources/views/Report/list.html.twig b/Resources/views/Report/list.html.twig index 9cd095647..8849f1832 100644 --- a/Resources/views/Report/list.html.twig +++ b/Resources/views/Report/list.html.twig @@ -64,6 +64,10 @@ + {% if reports|length < paginator.getTotalItems %} + {{ chill_pagination(paginator) }} + {% endif %} + {% endif %}