Limiter: Do not use a hardcoded default limit

This commit is contained in:
Johannes Meyer 2015-05-15 15:22:22 +02:00
parent 9a043386de
commit 99c511eefd
2 changed files with 15 additions and 4 deletions

View File

@ -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
*/

View File

@ -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',