mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Standardizing format string in PaginatorHelper::counter(), %page% becomes {:page}, old keys still work, but will be deprecated
This commit is contained in:
parent
23174203e3
commit
c2f111a45a
2 changed files with 25 additions and 17 deletions
|
@ -390,6 +390,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Returns a counter string for the paged result set
|
||||
*
|
||||
* @param mixed $options Options for the counter string. See #options for list of keys.
|
||||
* @todo See about deprecating the keys in $map for formatting
|
||||
* @return string Counter string.
|
||||
*/
|
||||
function counter($options = array()) {
|
||||
|
@ -429,7 +430,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
|
||||
break;
|
||||
default:
|
||||
$replace = array(
|
||||
$map = array(
|
||||
'%page%' => $paging['page'],
|
||||
'%pages%' => $paging['pageCount'],
|
||||
'%current%' => $paging['current'],
|
||||
|
@ -437,7 +438,12 @@ class PaginatorHelper extends AppHelper {
|
|||
'%start%' => $start,
|
||||
'%end%' => $end
|
||||
);
|
||||
$out = str_replace(array_keys($replace), array_values($replace), $options['format']);
|
||||
$out = str_replace(array_keys($map), array_values($map), $options['format']);
|
||||
|
||||
$newKeys = array(
|
||||
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}'
|
||||
);
|
||||
$out = str_replace($newKeys, array_values($map), $out);
|
||||
break;
|
||||
}
|
||||
return $this->output($out);
|
||||
|
@ -452,22 +458,17 @@ class PaginatorHelper extends AppHelper {
|
|||
function numbers($options = array()) {
|
||||
if ($options === true) {
|
||||
$options = array(
|
||||
'before' => ' | ', 'after' => ' | ',
|
||||
'first' => 'first', 'last' => 'last',
|
||||
);
|
||||
'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
|
||||
);
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'before'=> null, 'after'=> null,
|
||||
'model' => $this->defaultModel(),
|
||||
'modulus' => '8', 'separator' => ' | ',
|
||||
'first' => null, 'last' => null,
|
||||
),
|
||||
(array)$options);
|
||||
$defaults = array(
|
||||
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(),
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null,
|
||||
);
|
||||
$options += $defaults;
|
||||
|
||||
$params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
|
||||
$params = (array)$this->params($options['model']) + array('page'=> 1);
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
|
|
|
@ -739,9 +739,16 @@ class PaginatorTest extends CakeTestCase {
|
|||
),
|
||||
)
|
||||
);
|
||||
$input = 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%';
|
||||
$input = 'Page %page% of %pages%, showing %current% records out of %count% total, ';
|
||||
$input .= 'starting on record %start%, ending on %end%';
|
||||
$result = $this->Paginator->counter($input);
|
||||
$expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
|
||||
$expected .= 'ending on 3';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$input = 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, ';
|
||||
$input .= 'starting on record {:start}, ending on {:end}';
|
||||
$result = $this->Paginator->counter($input);
|
||||
$expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ending on 3';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$input = 'Page %page% of %pages%';
|
||||
|
|
Loading…
Reference in a new issue