Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter for plain phpcr #243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ $queryBuilder->from('Model\Article');
$adapter = new DoctrineODMPhpcrAdapter($queryBuilder);
```

### DoctrinePlainPhpcrAdapter

To paginate Doctrine Plain Phpcr query builders.

```php
<?php

use Pagerfanta\Adapter\DoctrinePlainPhpcrAdapter;

$queryBuilder = new QueryBuilder($this->factory);
$adapter = new DoctrinePlainPhpcrAdapter($queryBuilder);
```

### DoctrineCollectionAdapter

To paginate a `Doctrine\Common\Collection\Collections` interface
Expand Down
67 changes: 67 additions & 0 deletions src/Pagerfanta/Adapter/DoctrinePlainPhpcrAdapter
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is missing the .php extension


/*
* This file is part of the Pagerfanta package.
*
* (c) Pablo Díez <pablodip@gmail.com>
*
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the Doctrine PHPCR ODM has a concept named Doctrine Plain PHPCR

*
* @author Patrick Tassa <patrick.tassa@gmail.com>
*/
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()
{
$qb = clone $this->queryBuilder;

return $qb->getQuery()->execute(null, Query::HYDRATE_PHPCR)->getRows()->count();
}

/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
return $this->queryBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the query builder must be cloned before altering it.

->setMaxResults($length)
->setFirstResult($offset)
->getQuery()
->execute();
}
}