diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 7dec095d2..769481e13 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -5,9 +5,12 @@ namespace Icinga\Data; use Iterator; use IteratorAggregate; +use Zend_Paginator; +use Icinga\Application\Icinga; use Icinga\Application\Benchmark; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; +use Icinga\Web\Paginator\Adapter\QueryAdapter; class SimpleQuery implements QueryInterface, Queryable, Iterator { @@ -410,6 +413,43 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator return $this->limitOffset; } + /** + * Paginate data + * + * Auto-detects pagination parameters from request when unset + * + * @param int $itemsPerPage Number of items per page + * @param int $pageNumber Current page number + * + * @return Zend_Paginator + * + * @deprecated Use Icinga\Web\Controller::setupPaginationControl() and/or Icinga\Web\Widget\Paginator instead + */ + public function paginate($itemsPerPage = null, $pageNumber = null) + { + trigger_error( + 'SimpleQuery::paginate() is deprecated. Use Icinga\Web\Controller::setupPaginationControl()' + . ' and/or Icinga\Web\Widget\Paginator instead', + E_USER_DEPRECATED + ); + + if ($itemsPerPage === null || $pageNumber === null) { + // Detect parameters from request + $request = Icinga::app()->getFrontController()->getRequest(); + if ($itemsPerPage === null) { + $itemsPerPage = $request->getParam('limit', 25); + } + if ($pageNumber === null) { + $pageNumber = $request->getParam('page', 0); + } + } + $this->limit($itemsPerPage, $pageNumber * $itemsPerPage); + $paginator = new Zend_Paginator(new QueryAdapter($this)); + $paginator->setItemCountPerPage($itemsPerPage); + $paginator->setCurrentPageNumber($pageNumber); + return $paginator; + } + /** * Retrieve an array containing all rows of the result set *