Applying patch from 'Phally' Fixes multiple issues in PaginatorHelper 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
This commit is contained in:
mark_story 2009-07-17 19:46:33 +00:00
parent 7fd6cc52c2
commit 76d5855d72
2 changed files with 81 additions and 13 deletions

View file

@ -449,9 +449,9 @@ 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(
@ -490,11 +490,15 @@ class PaginatorHelper extends AppHelper {
$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;
}
}
@ -520,11 +524,15 @@ class PaginatorHelper extends AppHelper {
$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));
}
}

View file

@ -725,6 +725,66 @@ class PaginatorHelperTest extends CakeTestCase {
$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