Skip to content

Commit

Permalink
Applying patch from 'Phally' Fixes multiple issues in PaginatorHelper…
Browse files Browse the repository at this point in the history
… related to first and last option in numbers(). Fixes #6516

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8234 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jul 17, 2009
1 parent 7fd6cc5 commit 76d5855
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 13 deletions.
34 changes: 21 additions & 13 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -449,9 +449,9 @@ 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(
Expand Down Expand Up @@ -490,11 +490,15 @@ function numbers($options = array()) {
$end = $params['page'] + ($modulus - $params['page']) + 1;
}

if ($first && $start > (int)$first) {
if ($start == $first + 1) {
$out .= $this->first($first, array('tag' => $tag, 'after' => $separator));
} else {
$out .= $this->first($first, array('tag' => $tag));
if ($first) {
if ($start > (int)$first) {
if ($start == $first + 1) {
$out .= $this->first($first, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
} else {
$out .= $this->first($first, array('tag' => $tag, 'separator' => $separator));
}
} elseif ($start == 2) {
$out .= $this->Html->tag($tag, $this->link(1, array('page' => 1), $options)) . $separator;
}
}

Expand All @@ -520,11 +524,15 @@ function numbers($options = array()) {

$out .= $after;

if ($last && $end <= $params['pageCount'] - (int)$last) {
if ($end + 1 == $params['pageCount']) {
$out .= $this->last($last, array('tag' => $tag, 'before' => $separator));
} else {
$out .= $this->last($last, array('tag' => $tag));
if ($last) {
if ($end <= $params['pageCount'] - (int)$last) {
if ($end + 1 == $params['pageCount']) {
$out .= $this->last($last, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
} else {
$out .= $this->last($last, array('tag' => $tag, 'separator' => $separator));
}
} elseif ($end == $params['pageCount'] - 1) {
$out .= $separator . $this->Html->tag($tag, $this->link($params['pageCount'], array('page' => $params['pageCount']), $options));
}
}

Expand Down
60 changes: 60 additions & 0 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -725,6 +725,66 @@ function testNumbers() {
$result = $this->Paginator->numbers();
$expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC">1</a></span> | <span class="current">2</span> | <span><a href="/index/page:3/sort:Client.name/direction:DESC">3</a></span> | <span><a href="/index/page:4/sort:Client.name/direction:DESC">4</a></span>';
$this->assertEqual($result, $expected);

$this->Paginator->params['paging'] = array('Client' => array(
'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
'defaults' => array('limit' => 10),
'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
);

$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '4895', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging'] = array('Client' => array(
'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
'defaults' => array('limit' => 10),
'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
);

$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '3', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '3', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
}
/**
* testFirstAndLast method
Expand Down

0 comments on commit 76d5855

Please sign in to comment.