mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing bug when trying to Paginate ordering by multiple keys.
This commit is contained in:
parent
b261024111
commit
49f4035412
2 changed files with 38 additions and 14 deletions
|
@ -340,22 +340,23 @@ class PaginatorComponent extends Component {
|
|||
}
|
||||
|
||||
if (!empty($options['order']) && is_array($options['order'])) {
|
||||
$alias = $object->alias;
|
||||
$key = $field = key($options['order']);
|
||||
$order = array();
|
||||
foreach ($options['order'] as $key => $value) {
|
||||
$field = $key;
|
||||
$alias = $object->alias;
|
||||
if (strpos($key, '.') !== false) {
|
||||
list($alias, $field) = explode('.', $key);
|
||||
}
|
||||
|
||||
if (strpos($key, '.') !== false) {
|
||||
list($alias, $field) = explode('.', $key);
|
||||
}
|
||||
$value = $options['order'][$key];
|
||||
unset($options['order'][$key]);
|
||||
|
||||
if ($object->hasField($field)) {
|
||||
$options['order'][$alias . '.' . $field] = $value;
|
||||
} elseif ($object->hasField($key, true)) {
|
||||
$options['order'][$field] = $value;
|
||||
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
|
||||
$options['order'][$alias . '.' . $field] = $value;
|
||||
if ($object->hasField($field)) {
|
||||
$order[$alias . '.' . $field] = $value;
|
||||
} elseif ($object->hasField($key, true)) {
|
||||
$order[$field] = $value;
|
||||
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
|
||||
$order[$alias . '.' . $field] = $value;
|
||||
}
|
||||
}
|
||||
$options['order'] = $order;
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
|
|
@ -683,6 +683,29 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals('desc', $result['order']['something']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that multiple sort works.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSortMultiple() {
|
||||
$model = $this->getMock('Model');
|
||||
$model->alias = 'model';
|
||||
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
|
||||
|
||||
$options = array('order' => array(
|
||||
'author_id' => 'asc',
|
||||
'title' => 'asc'
|
||||
));
|
||||
$result = $this->Paginator->validateSort($model, $options);
|
||||
$expected = array(
|
||||
'model.author_id' => 'asc',
|
||||
'model.title' => 'asc'
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that maxLimit is respected
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue