Skip to content
Permalink
Browse files

Also cleaned up a bit pagination code

This removes the option of passing the finder name as an array value
in the pagination options. I think that looked like an error instead
  • Loading branch information...
lorenzo committed Sep 6, 2014
1 parent 36ba3bb commit 0c605c83e97ad5a1445a1e3f539003a98a54b104
@@ -155,16 +155,10 @@ public function paginate($object, array $settings = []) {
$options += ['page' => 1];
$options['page'] = intval($options['page']) < 1 ? 1 : (int)$options['page'];
if (!isset($options['finder']) && isset($options['findType'])) {
trigger_error('You should use finder instead of findType', E_USER_DEPRECATED);
$options['finder'] = $options['findType'];
}
$type = !empty($options['finder']) ? $options['finder'] : 'all';
unset($options['finder'], $options['maxLimit']);
list($finder, $options) = $this->_extractFinder($options);
if (empty($query)) {
$query = $object->find($type, $options);
$query = $object->find($finder, $options);
}
$query->applyOptions($options);
@@ -190,7 +184,7 @@ public function paginate($object, array $settings = []) {
}
$paging = array(
'finder' => $type,
'finder' => $finder,
'page' => $page,
'current' => $numResults,
'count' => $count,
@@ -220,6 +214,30 @@ public function paginate($object, array $settings = []) {
return $results;
}
/**
* Extracts the finder name and options out of the provided pagination options
*
* @param array $options the pagination options
* @return array An array containing in the first position the finder name and
* in the second the options to be passed to it
*/
protected function _extractFinder($options) {
if (!isset($options['finder']) && isset($options['findType'])) {
trigger_error('You should use finder instead of findType', E_USER_DEPRECATED);
$options['finder'] = $options['findType'];
}
$type = !empty($options['finder']) ? $options['finder'] : 'all';
unset($options['finder'], $options['maxLimit']);
if (is_array($type)) {
$options = $options + (array)current($type);
$type = key($type);
}
return [$type, $options];
}
/**
* Merges the various options that Pagination uses.
* Pulls settings together from the following places:
@@ -155,7 +155,12 @@ public function testPaginateCustomFinderOptions() {
];
$table = TableRegistry::get('PaginatorPosts');
$expected = $table->find('author', ['conditions' => ['PaginatorPosts.author_id' => $settings['PaginatorPosts']['finder']['author']['author_id']]])
$expected = $table
->find('author', [
'conditions' => [
'PaginatorPosts.author_id' => 1
]
])
->count();
$result = $this->Paginator->paginate($table, $settings)->count();

0 comments on commit 0c605c8

Please sign in to comment.
You can’t perform that action at this time.