SimpleQuery: Re-add method paginate but flag it as deprecated

This commit is contained in:
Johannes Meyer 2015-06-02 14:47:29 +02:00
parent cf95994ff5
commit 06fb6ff6fc
1 changed files with 40 additions and 0 deletions

View File

@ -5,8 +5,11 @@ namespace Icinga\Data;
use ArrayIterator;
use IteratorAggregate;
use Zend_Paginator;
use Icinga\Application\Icinga;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
{
@ -327,6 +330,43 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
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
*