Skip to content

Instantly share code, notes, and snippets.

@romankonz
Created March 4, 2013 20:18
Show Gist options
  • Save romankonz/5085261 to your computer and use it in GitHub Desktop.
Save romankonz/5085261 to your computer and use it in GitHub Desktop.
DoctrineMongoODMModule Pagination Adapter
<?php
namespace DoctrineMongoODMModule\Paginator\Adapter;
use Zend\Paginator\Adapter\AdapterInterface;
class DoctrinePaginator implements AdapterInterface
{
protected $query;
function __construct(\Doctrine\MongoDB\Query\Builder $query)
{
$this->query = $query;
}
public function count()
{
$query = clone $this->query;
return $query->count()->getQuery()->execute();
}
public function getItems($offset, $itemCountPerPage)
{
$query = clone $this->query;
$query->skip($offset);
$query->limit($itemCountPerPage);
return iterator_to_array($query->getQuery()->execute());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment