mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 19:12:42 +00:00
Merge pull request #1624 from ADmad/fix-paginator-order
Fix setting of order in Paginator options when using model's order. Refs #3902
This commit is contained in:
commit
fd50c5277e
2 changed files with 25 additions and 4 deletions
|
@ -361,6 +361,10 @@ class PaginatorComponent extends Component {
|
|||
* @return array An array of options with sort + direction removed and replaced with order if possible.
|
||||
*/
|
||||
public function validateSort(Model $object, array $options, array $whitelist = array()) {
|
||||
if (empty($options['order']) && is_array($object->order)) {
|
||||
$options['order'] = $object->order;
|
||||
}
|
||||
|
||||
if (isset($options['sort'])) {
|
||||
$direction = null;
|
||||
if (isset($options['direction'])) {
|
||||
|
@ -401,9 +405,7 @@ class PaginatorComponent extends Component {
|
|||
}
|
||||
$options['order'] = $order;
|
||||
}
|
||||
if (empty($options['order']) && !empty($object->order)) {
|
||||
$options['order'] = $object->order;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
|
|
@ -601,7 +601,26 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
|
||||
$this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
|
||||
$this->assertEquals($Controller->PaginatorControllerPost->order, $this->Controller->request['paging']['PaginatorControllerPost']['order']);
|
||||
$this->assertEquals(
|
||||
$Controller->PaginatorControllerPost->order,
|
||||
$Controller->request->paging['PaginatorControllerPost']['options']['order']
|
||||
);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
|
||||
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$this->assertEmpty($result['order']);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
|
||||
$results = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$this->assertEmpty($result['order']);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = array(
|
||||
'PaginatorControllerPost.id',
|
||||
'PaginatorControllerPost.created' => 'asc'
|
||||
);
|
||||
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$expected = array('PaginatorControllerPost.created' => 'asc');
|
||||
$this->assertEquals($expected, $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue