From 3bfff803db23865efc71d74465655356695d64f6 Mon Sep 17 00:00:00 2001 From: patrick-tassa Date: Fri, 8 Dec 2017 11:20:18 +0100 Subject: [PATCH 1/3] Create DoctrinePlainPhpcrAdapter --- .../Adapter/DoctrinePlainPhpcrAdapter | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter diff --git a/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter b/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter new file mode 100644 index 00000000..51fc843f --- /dev/null +++ b/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Pagerfanta\Adapter; + +use PHPCR\Util\QOM\QueryBuilder; +use Doctrine\ODM\PHPCR\Query\Query; + +/** + * Pagerfanta adapter for Doctrine Plain PHPCR. + * + * @author Patrick Tassa + */ +class DoctrinePlainPhpcrAdapter implements AdapterInterface +{ + private $queryBuilder; + + /** + * Constructor. + * + * @param QueryBuilder $queryBuilder A Doctrine PHPCR-ODM query builder. + */ + public function __construct(QueryBuilder $queryBuilder) + { + $this->queryBuilder = $queryBuilder; + } + + /** + * Returns the query builder. + * + * @return QueryBuilder The query builder. + */ + public function getQueryBuilder() + { + return $this->queryBuilder; + } + + /** + * {@inheritdoc} + */ + public function getNbResults() + { + return $this->queryBuilder->getQuery()->execute(null, Query::HYDRATE_PHPCR)->getRows()->count(); + } + + /** + * {@inheritdoc} + */ + public function getSlice($offset, $length) + { + return $this->queryBuilder + ->setMaxResults($length) + ->setFirstResult($offset) + ->getQuery() + ->execute(); + } +} From b66e5faf7b18c29e80255e03fca3bf3bba606d33 Mon Sep 17 00:00:00 2001 From: patrick-tassa Date: Fri, 8 Dec 2017 11:39:03 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index fb34bfd7..72016f8a 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,19 @@ $queryBuilder->from('Model\Article'); $adapter = new DoctrineODMPhpcrAdapter($queryBuilder); ``` +### DoctrinePlainPhpcrAdapter + +To paginate Doctrine Plain Phpcr query builders. + +```php +factory); +$adapter = new DoctrinePlainPhpcrAdapter($queryBuilder); +``` + ### DoctrineCollectionAdapter To paginate a `Doctrine\Common\Collection\Collections` interface From e6a725ee0a3617b283f2f933c4b9716a4f88a1ca Mon Sep 17 00:00:00 2001 From: patrick-tassa Date: Fri, 8 Dec 2017 14:53:23 +0100 Subject: [PATCH 3/3] Update DoctrinePlainPhpcrAdapter --- src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter b/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter index 51fc843f..e03e274b 100644 --- a/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter +++ b/src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter @@ -48,7 +48,9 @@ class DoctrinePlainPhpcrAdapter implements AdapterInterface */ public function getNbResults() { - return $this->queryBuilder->getQuery()->execute(null, Query::HYDRATE_PHPCR)->getRows()->count(); + $qb = clone $this->queryBuilder; + + return $qb->getQuery()->execute(null, Query::HYDRATE_PHPCR)->getRows()->count(); } /**