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

First fix #92

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityRepository;
use DoctrineModule\Paginator\Adapter\Selectable as SelectableAdapter;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator as DoctrineAdapter;
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
use Metadata\MetadataFactoryInterface;
use Zend\Mvc\Router\Http\RouteInterface;
use Zend\Mvc\Router\Http\RouteMatch;
Expand Down Expand Up @@ -239,6 +242,7 @@ protected function buildRouteMatch(ResourceInterface $resource, $path)
$collectionMetadata = $resourceMetadata->getCollectionMetadata();
$classMetadata = $resourceMetadata->getClassMetadata();
$data = $resource->getData();
$chunks = explode('/', $path);

if ($data instanceof Selectable) {
$criteria = Criteria::create();
Expand All @@ -250,7 +254,11 @@ protected function buildRouteMatch(ResourceInterface $resource, $path)
}

// @TODO: for now, collection is always wrapped around a ResourcePaginator, should instead be configurable
$data = new ResourcePaginator($resourceMetadata, new SelectableAdapter($data, $criteria));
if ($data instanceof EntityRepository && class_exists('DoctrineORMModule/Paginator/Adapter/DoctrinePaginator')) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure you should use the namespace separator for class exists.

$data = new ResourcePaginator($resourceMetadata, new DoctrineAdapter(new DoctrinePaginator($data->find(array_shift($chunks)))));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. In fact it's not that easy. https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L62

The consrtuctor of Doctrine paginator accepts either a Query or a Query builder. Hhmm... Let me think about it tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

This does not handle pagination. The DoctrinePagination of the ORM module works with DQL queries

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I realized this. I'm going to close as the logic is broken.

Today I'm going to give a new try to fix that directly in Doctrine ORM.

} else {
$data = new ResourcePaginator($resourceMetadata, new SelectableAdapter($data, $criteria));
}

$resource = new Resource($data, $resourceMetadata);
}
Expand Down