-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from KnpLabs/refactor
Use doctrine Paginator if available
- Loading branch information
Showing
24 changed files
with
301 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
tests/phpunit.xml | ||
tests/temp/*.php | ||
vendor/* | ||
/tests/phpunit.xml | ||
/tests/temp/*.php | ||
/vendor | ||
tags | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Configuration | ||
|
||
|
||
Some subscribers will take into account some options. | ||
These options can be passed as the 4th argument of `Paginator::paginate()`. | ||
|
||
For example, Doctrine ORM subscriber will generate different sql queries if the `distinct` options changes. | ||
|
||
|
||
The list of existing options are: | ||
|
||
| name | type | default value | subscribers | | ||
| -------------------------- | ------ | ------------- | ----------------------------------------------- | | ||
| wrap-queries | bool | false | orm QuerySubscriber, orm QueryBuilderSubscriber | | ||
| distinct | bool | true | QuerySubscriber, QueryBuilderSubscriber | | ||
| pageParameterName | string | page | SortableSubscriber | | ||
| defaultSortFieldName | string | | SortableSubscriber | | ||
| defaultSortDirection | string | asc | SortableSubscriber | | ||
| sortFieldWhitelist | array | [] | SortableSubscriber | | ||
| sortFieldParameterName | string | sort | SortableSubscriber | | ||
| sortDirectionParameterName | string | sort | SortableSubscriber | | ||
| filterFieldParameterName | string | filterParam | FiltrationSubscriber | | ||
| filterValueParameterName | string | filterValue | FiltrationSubscriber | | ||
|
||
|
||
## Noticeable behaviors of some options | ||
|
||
### `distinct` | ||
|
||
If set to true, will add a distinct sql keyword on orm queries to ensuire unicity of counted results | ||
|
||
|
||
### `wrap-queries` | ||
|
||
If set to true, will take advantage of doctrine 2.3 output walkers by using subqueries to handle composite keys and HAVING queries. | ||
This can considerably impact performances depending on the query and the platform, you will have to consider it at some point. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
* @author David Abdemoulaie <[email protected]> | ||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) | ||
* @license http://hobodave.com/license.txt New BSD License | ||
* @deprecated | ||
*/ | ||
class CountWalker extends TreeWalkerAdapter | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
* @author David Abdemoulaie <[email protected]> | ||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) | ||
* @license http://hobodave.com/license.txt New BSD License | ||
* @deprecated | ||
*/ | ||
|
||
namespace Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
* @author David Abdemoulaie <[email protected]> | ||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) | ||
* @license http://hobodave.com/license.txt New BSD License | ||
* @deprecated | ||
*/ | ||
class WhereInWalker extends TreeWalkerAdapter | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber/UsesPaginator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Knp\Component\Pager\Event\ItemsEvent; | ||
use Doctrine\ORM\Query; | ||
use Doctrine\ORM\Tools\Pagination\Paginator; | ||
use Doctrine\ORM\Tools\Pagination\CountWalker; | ||
|
||
class UsesPaginator implements EventSubscriberInterface | ||
{ | ||
const HINT_FETCH_JOIN_COLLECTION = 'knp_paginator.fetch_join_collection'; | ||
|
||
public function items(ItemsEvent $event) | ||
{ | ||
if (!class_exists('Doctrine\ORM\Tools\Pagination\Paginator')) { | ||
return; | ||
} | ||
if (!$event->target instanceof Query) { | ||
return; | ||
} | ||
$event->stopPropagation(); | ||
|
||
$useOutputWalkers = false; | ||
if (isset($event->options['wrap-queries'])) { | ||
$useOutputWalkers = $event->options['wrap-queries']; | ||
} | ||
|
||
$event->target | ||
->setFirstResult($event->getOffset()) | ||
->setMaxResults($event->getLimit()) | ||
->setHint(CountWalker::HINT_DISTINCT, $event->options['distinct']) | ||
; | ||
|
||
$fetchJoinCollection = true; | ||
if ($event->target->hasHint(self::HINT_FETCH_JOIN_COLLECTION)) { | ||
$fetchJoinCollection = $event->target->getHint(self::HINT_FETCH_JOIN_COLLECTION); | ||
} | ||
|
||
$paginator = new Paginator($event->target, $fetchJoinCollection); | ||
$paginator->setUseOutputWalkers($useOutputWalkers); | ||
$event->count = count($paginator); | ||
$event->items = iterator_to_array($paginator); | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
'knp_pager.items' => array('items', 0) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
756c445
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.
this merge broke count hinting functionality as mentioned here KnpLabs/KnpPaginatorBundle#276 (comment)