Permalink
Browse files

added DoctrinePaginator.php

  • Loading branch information...
1 parent 3a652cf commit 3adba20e175a615c2f8b4f8be1517e6724b80c7d @romankonz romankonz committed Mar 4, 2013
Showing with 67 additions and 0 deletions.
  1. +67 −0 src/DoctrineMongoODMModule/Paginator/Adapter/DoctrinePaginator.php
@@ -0,0 +1,67 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineMongoODMModule\Paginator\Adapter;
+
+use Zend\Paginator\Adapter\AdapterInterface;
+use \Doctrine\MongoDB\Query\Builder;
+
+/**
+ * @license MIT
+ * @link http://www.doctrine-project.org/
+ * @author Roman Konz <roman@konz.me>
+ */
+class DoctrinePaginator implements AdapterInterface
+{
+ /**
+ * @var QueryBuilder
+ */
+ protected $queryBuilder;
+
+ /**
+ * Constructor
+ *
+ * @param \Doctrine\MongoDB\Query\Builder $queryBuilder
+ */
+ function __construct(Builder $queryBuilder)
+ {
+ $this->queryBuilder = $queryBuilder;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function count()
+ {
+ $query = clone $this->queryBuilder;
+ return $query->count()->getQuery()->execute();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getItems($offset, $itemCountPerPage)
+ {
+ $query = clone $this->queryBuilder;
+ $query->skip($offset);
+ $query->limit($itemCountPerPage);
+ return iterator_to_array($query->getQuery()->execute());
+
+ }
+}

0 comments on commit 3adba20

Please sign in to comment.