Skip to content

Commit

Permalink
changed DoctrinePaginator to use cursors instead of query builders
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Konz committed Mar 5, 2013
1 parent 3adba20 commit e0dc67f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/DoctrineMongoODMModule/Paginator/Adapter/DoctrinePaginator.php
Expand Up @@ -20,7 +20,7 @@
namespace DoctrineMongoODMModule\Paginator\Adapter;

use Zend\Paginator\Adapter\AdapterInterface;
use \Doctrine\MongoDB\Query\Builder;
use Doctrine\ODM\MongoDB\Cursor;

/**
* @license MIT
Expand All @@ -30,38 +30,38 @@
class DoctrinePaginator implements AdapterInterface
{
/**
* @var QueryBuilder
* @var Doctrine\ODM\MongoDB\Cursor
*/
protected $queryBuilder;
protected $cursor;

/**
* Constructor
*
* @param \Doctrine\MongoDB\Query\Builder $queryBuilder
* @param Doctrine\ODM\MongoDB\Cursor $cursor
*/
function __construct(Builder $queryBuilder)
function __construct(Cursor $cursor)
{
$this->queryBuilder = $queryBuilder;
$this->cursor = $cursor;
}

/**
* {@inheritDoc}
*/
public function count()
{
$query = clone $this->queryBuilder;
return $query->count()->getQuery()->execute();
$cursor = clone $this->cursor;
return $cursor->count();
}

/**
* {@inheritDoc}
*/
public function getItems($offset, $itemCountPerPage)
{
$query = clone $this->queryBuilder;
$query->skip($offset);
$query->limit($itemCountPerPage);
return iterator_to_array($query->getQuery()->execute());
$cursor = clone $this->cursor;
$cursor->skip($offset);
$cursor->limit($itemCountPerPage);
return $cursor;

}
}

0 comments on commit e0dc67f

Please sign in to comment.