-
Notifications
You must be signed in to change notification settings - Fork 31
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
First fix #92
Changes from 1 commit
b0c79f0
1492213
de48ee9
727651b
fb14da8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(); | ||
|
@@ -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')) { | ||
$data = new ResourcePaginator($resourceMetadata, new DoctrineAdapter(new DoctrinePaginator($data->find(array_shift($chunks))))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
There was a problem hiding this comment.
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.