Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 76d5855d720c9fe65d4d3ec02dc176d405d91aed 1 parent 7fd6cc5
@markstory markstory authored
View
34 cake/libs/view/helpers/paginator.php
@@ -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(
@@ -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;
}
}
@@ -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));
}
}
View
60 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.