Skip to content
Permalink
Browse files

Standardizing format string in PaginatorHelper::counter(), %page% bec…

…omes {:page}, old keys still work, but will be deprecated
  • Loading branch information...
nateabele committed Feb 7, 2009
1 parent 2317420 commit c2f111a45a2855d894d5748b576535adb2372df8
Showing with 25 additions and 17 deletions.
  1. +16 −15 cake/libs/view/helpers/paginator.php
  2. +9 −2 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -390,6 +390,7 @@ function defaultModel() {
* 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,15 +430,20 @@ function counter($options = array()) {
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
break;
default:
$replace = array(
$map = array(
'%page%' => $paging['page'],
'%pages%' => $paging['pageCount'],
'%current%' => $paging['current'],
'%count%' => $paging['count'],
'%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 @@ function counter($options = array()) {
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 @@ function testCounter() {
),
)
);
$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%';

0 comments on commit c2f111a

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