mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
fixes #3788, paginator numbers first and last issues
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6538 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
db1e079e5f
commit
dd10cb191f
2 changed files with 39 additions and 9 deletions
|
@ -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 .= '<span class="current">' . $params['page'] . '</span>';
|
||||
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 .= '<span>' .$this->link($i, array('page' => $i), $options) . '</span>';
|
||||
}
|
||||
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 .= '<span>' . $this->link($i, array('page' => $i), $options) . '</span>';
|
||||
if($i != $first) {
|
||||
if ($i != $first) {
|
||||
$out .= $separator;
|
||||
}
|
||||
}
|
||||
|
@ -600,7 +608,7 @@ class PaginatorHelper extends AppHelper {
|
|||
}
|
||||
for ($i = $lower; $i <= $params['pageCount']; $i++) {
|
||||
$out .= '<span>' . $this->link($i, array('page' => $i), $options) . '</span>';
|
||||
if($i != $params['pageCount']) {
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,8 +248,30 @@ class PaginatorTest extends UnitTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
|
||||
$expected = '<span><a href="/index/page:1">1</a></span>...<span><a href="/index/page:6">6</a></span> | <span><a href="/index/page:7">7</a></span> | <span><a href="/index/page:8">8</a></span> | <span><a href="/index/page:9">9</a></span> | <span class="current">10</span> | <span><a href="/index/page:11">11</a></span> | <span><a href="/index/page:12">12</a></span> | <span><a href="/index/page:13">13</a></span> | <span><a href="/index/page:14">14</a></span>...<span><a href="/index/page:15">15</a></span>';
|
||||
$expected = '<span><a href="/index/page:1">1</a></span>...<span><a href="/index/page:6">6</a></span> | <span><a href="/index/page:7">7</a></span> | <span><a href="/index/page:8">8</a></span> | <span><a href="/index/page:9">9</a></span> | <span class="current">10</span> | <span><a href="/index/page:11">11</a></span> | <span><a href="/index/page:12">12</a></span> | <span><a href="/index/page:13">13</a></span> | <span><a href="/index/page:14">14</a></span> | <span><a href="/index/page:15">15</a></span>';
|
||||
$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 = '<span><a href="/index/page:1">1</a></span> | <span><a href="/index/page:2">2</a></span> | <span><a href="/index/page:3">3</a></span> | <span><a href="/index/page:4">4</a></span> | <span><a href="/index/page:5">5</a></span> | <span class="current">6</span> | <span><a href="/index/page:7">7</a></span> | <span><a href="/index/page:8">8</a></span> | <span><a href="/index/page:9">9</a></span> | <span><a href="/index/page:10">10</a></span>...<span><a href="/index/page:42">42</a></span>';
|
||||
$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 = '<span><a href="/index/page:1">1</a></span>...<span><a href="/index/page:33">33</a></span> | <span><a href="/index/page:34">34</a></span> | <span><a href="/index/page:35">35</a></span> | <span><a href="/index/page:36">36</a></span> | <span class="current">37</span> | <span><a href="/index/page:38">38</a></span> | <span><a href="/index/page:39">39</a></span> | <span><a href="/index/page:40">40</a></span> | <span><a href="/index/page:41">41</a></span> | <span><a href="/index/page:42">42</a></span>';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
}
|
||||
|
||||
function testFirstAndLast() {
|
||||
|
|
Loading…
Add table
Reference in a new issue