From 4893b62fc67b7763fb91b415d1d6cc658525890a Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 18 Feb 2014 20:50:05 +0100 Subject: [PATCH 1/2] Fix #1697 : Add pagination to quarantine --- lib/Alchemy/Phrasea/Application.php | 2 ++ .../Phrasea/Controller/Prod/Lazaret.php | 16 ++++++------ .../Repositories/LazaretFileRepository.php | 10 +++----- templates/web/prod/upload/lazaret.html.twig | 25 ++++++++++++++++--- templates/web/prod/upload/upload.html.twig | 16 ++++++++++-- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 1198d35c61..04f2c9e4d1 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -592,6 +592,8 @@ class Application extends SilexApplication $twig->addFilter('stripdoublequotes', new \Twig_Filter_Function('stripdoublequotes')); $twig->addFilter('get_collection_logo', new \Twig_Filter_Function('collection::getLogo')); $twig->addFilter('floor', new \Twig_Filter_Function('floor')); + $twig->addFilter('ceil', new \Twig_Filter_Function('ceil')); + $twig->addFilter('max', new \Twig_Filter_Function('max')); $twig->addFilter('min', new \Twig_Filter_Function('min')); $twig->addFilter('bas_labels', new \Twig_Filter_Function('phrasea::bas_labels')); $twig->addFilter('sbas_names', new \Twig_Filter_Function('phrasea::sbas_names')); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php b/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php index 78c45d47ee..4aff805758 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php @@ -179,18 +179,20 @@ class Lazaret implements ControllerProviderInterface $baseIds = array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('canaddrecord'))); $lazaretFiles = null; + $perPage = 10; + $page = max(1, $request->query->get('page', 1)); + $offset = ($page - 1) * $perPage; if (count($baseIds) > 0) { $lazaretRepository = $app['EM']->getRepository('Entities\LazaretFile'); - - $lazaretFiles = $lazaretRepository->findPerPage( - $baseIds, $request->query->get('offset', 0), $request->query->get('limit', 10) - ); + $lazaretFiles = $lazaretRepository->findPerPage($baseIds, $offset, $perPage); } - return $app['twig']->render( - 'prod/upload/lazaret.html.twig', array('lazaretFiles' => $lazaretFiles) - ); + return $app['twig']->render('prod/upload/lazaret.html.twig', array( + 'lazaretFiles' => $lazaretFiles, + 'currentPage' => $page, + 'perPage' => $perPage, + )); } /** diff --git a/lib/Doctrine/Repositories/LazaretFileRepository.php b/lib/Doctrine/Repositories/LazaretFileRepository.php index 7651642dfa..1bad0e5e3e 100644 --- a/lib/Doctrine/Repositories/LazaretFileRepository.php +++ b/lib/Doctrine/Repositories/LazaretFileRepository.php @@ -3,6 +3,7 @@ namespace Repositories; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Tools\Pagination\Paginator; /** * LazaretFileRepository @@ -12,12 +13,11 @@ use Doctrine\ORM\EntityRepository; */ class LazaretFileRepository extends EntityRepository { - public function findPerPage(array $base_ids, $offset = 0, $perPage = 10) { $base_ids = implode(', ', array_map(function ($int) { - return (int) $int; - }, $base_ids)); + return (int) $int; + }, $base_ids)); $dql = ' SELECT f @@ -29,8 +29,6 @@ class LazaretFileRepository extends EntityRepository $query->setFirstResult($offset) ->setMaxResults($perPage); - $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query, true); - - return $paginator; + return new Paginator($query, true); } } diff --git a/templates/web/prod/upload/lazaret.html.twig b/templates/web/prod/upload/lazaret.html.twig index 203b6366b1..d97b833e1f 100644 --- a/templates/web/prod/upload/lazaret.html.twig +++ b/templates/web/prod/upload/lazaret.html.twig @@ -2,10 +2,27 @@ {% if lazaretFiles is not none %} {% if lazaretFiles|length > 0 %} -
- +
+
+ +
+
+ + {% set items = lazaretFiles | length %} + {% set pages = (items / perPage) | ceil | min(10) %} + + {% for i in 1..pages %} + + {% endfor %} +