-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
56 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# NumericPaginator | ||
|
||
`contain` is deprecated/removed in 5.x as per https://book.cakephp.org/5/en/appendices/5-0-migration-guide.html#controller | ||
|
||
For those with hundreds of controllers using this option it can be tedious to upgrade all at once. | ||
In that case one can use this one instead: | ||
|
||
```php | ||
use Shim\Datasource\Paging\NumericPaginator; | ||
|
||
/** | ||
* @var array<string, mixed> | ||
*/ | ||
protected array $paginate = [ | ||
'order' => ['States.modified' => 'DESC'], | ||
'className' => NumericPaginator::class, | ||
]; | ||
``` |
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,36 @@ | ||
<?php | ||
|
||
namespace Shim\Datasource\Paging; | ||
|
||
use Cake\Datasource\Paging\NumericPaginator as CoreNumericPaginator; | ||
use Cake\Datasource\QueryInterface; | ||
use Cake\Datasource\RepositoryInterface; | ||
|
||
class NumericPaginator extends CoreNumericPaginator { | ||
|
||
/** | ||
* Get query for fetching paginated results. | ||
* | ||
* @param \Cake\Datasource\RepositoryInterface $object Repository instance. | ||
* @param \Cake\Datasource\QueryInterface|null $query Query Instance. | ||
* @param array<string, mixed> $data Pagination data. | ||
* @return \Cake\Datasource\QueryInterface | ||
*/ | ||
protected function getQuery(RepositoryInterface $object, ?QueryInterface $query, array $data): QueryInterface { | ||
$contain = null; | ||
if (!empty($data['options']['contain'])) { | ||
$contain = $data['options']['contain']; | ||
} | ||
|
||
unset($data['options']['contain']); | ||
|
||
$query = parent::getQuery($object, $query, $data); | ||
if ($contain) { | ||
/** @var \Cake\ORM\Query\SelectQuery $query */ | ||
$query->contain($contain); | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
} |