diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index e0a8006d7..57caf9d23 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -473,8 +473,12 @@ class PaginatorHelper extends AppHelper { $end = $params['page'] + ($modulus - $params['page']) + 1; } - if($first && $start > (int)$first) { - $out .= $this->first($first); + if ($first && $start > (int)$first) { + if ($start == $first + 1) { + $out .= $this->first($first, array('after' => $separator)); + } else { + $out .= $this->first($first); + } } $out .= $before; @@ -484,7 +488,7 @@ class PaginatorHelper extends AppHelper { } $out .= '' . $params['page'] . ''; - if($i != $params['pageCount']) { + if ($i != $params['pageCount']) { $out .= $separator; } @@ -499,8 +503,12 @@ class PaginatorHelper extends AppHelper { $out .= $after; - if($last && $end <= $params['pageCount'] - (int)$last) { - $out .= $this->last($last); + if ($last && $end <= $params['pageCount'] - (int)$last) { + if ($end + 1 == $params['pageCount']) { + $out .= $this->last($last, array('before' => $separator)); + } else { + $out .= $this->last($last); + } } } else { @@ -512,7 +520,7 @@ class PaginatorHelper extends AppHelper { } else { $out .= '' .$this->link($i, array('page' => $i), $options) . ''; } - if($i != $params['pageCount']) { + if ($i != $params['pageCount']) { $out .= $separator; } } @@ -555,7 +563,7 @@ class PaginatorHelper extends AppHelper { } for ($i = 1; $i <= $first; $i++) { $out .= '' . $this->link($i, array('page' => $i), $options) . ''; - if($i != $first) { + if ($i != $first) { $out .= $separator; } } @@ -600,7 +608,7 @@ class PaginatorHelper extends AppHelper { } for ($i = $lower; $i <= $params['pageCount']; $i++) { $out .= '' . $this->link($i, array('page' => $i), $options) . ''; - if($i != $params['pageCount']) { + if ($i != $params['pageCount']) { $out .= $separator; } } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 12d43db56..7f4cbe744 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -248,8 +248,30 @@ class PaginatorTest extends UnitTestCase { ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); - $expected = '1...6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14...15'; + $expected = '1...6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15'; $this->assertEqual($result, $expected); + + $this->Paginator->params['paging'] = array('Client' => array( + 'page' => 6, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, + 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), + 'options' => array('page' => 6, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + ); + + $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); + $expected = '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10...42'; + $this->assertEqual($result, $expected); + + $this->Paginator->params['paging'] = array('Client' => array( + 'page' => 37, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, + 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), + 'options' => array('page' => 37, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + ); + + $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); + $expected = '1...33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42'; + + $this->assertEqual($result, $expected); + } function testFirstAndLast() {