From 99c511eefdcf2beb727f94ccf35ebab742859dc7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 15 May 2015 15:22:22 +0200 Subject: [PATCH] Limiter: Do not use a hardcoded default limit --- library/Icinga/Web/Controller.php | 9 ++++++--- library/Icinga/Web/Widget/Limiter.php | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index 4c68da0ff..61e80173b 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -84,12 +84,15 @@ class Controller extends ModuleActionController * * In case the current view has been requested as compact this method does nothing. * + * @param int $itemsPerPage Default number of items per page + * * @return $this */ - protected function setupLimitControl() + protected function setupLimitControl($itemsPerPage = 25) { if (! $this->view->compact) { $this->view->limiter = new Limiter(); + $this->view->limiter->setDefaultLimit($itemsPerPage); } return $this; @@ -102,8 +105,8 @@ class Controller extends ModuleActionController * The paginator is set on the `paginator' view property only if the current view has not been requested as compact. * * @param QueryInterface $query The query to create a paginator for - * @param int $itemsPerPage Number of items per page - * @param int $pageNumber Current page number + * @param int $itemsPerPage Default number of items per page + * @param int $pageNumber Default page number * * @return $this */ diff --git a/library/Icinga/Web/Widget/Limiter.php b/library/Icinga/Web/Widget/Limiter.php index 9febf6f63..1c6c82f62 100644 --- a/library/Icinga/Web/Widget/Limiter.php +++ b/library/Icinga/Web/Widget/Limiter.php @@ -21,6 +21,8 @@ class Limiter extends AbstractWidget private $pages; + private $default; + public function setUrl(Url $url) { $this->url = $url; @@ -39,13 +41,19 @@ class Limiter extends AbstractWidget return $this; } + public function setDefaultLimit($limit) + { + $this->default = $limit; + return $this; + } + public function render() { if ($this->url === null) { $this->url = Url::fromRequest(); } - $currentLimit = (int) $this->url->getParam('limit', 25); // Default?? + $currentLimit = (int) $this->url->getParam('limit', $this->default); $availableLimits = array( 10 => '10', 25 => '25',