Skip to content
This repository
Browse code

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
Mark Story authored July 17, 2009
34  cake/libs/view/helpers/paginator.php
@@ -449,9 +449,9 @@ function counter($options = array()) {
449 449
 	function numbers($options = array()) {
450 450
 		if ($options === true) {
451 451
 			$options = array(
452  
-						'before' => ' | ', 'after' => ' | ',
453  
-						'first' => 'first', 'last' => 'last',
454  
-						);
  452
+				'before' => ' | ', 'after' => ' | ',
  453
+				'first' => 'first', 'last' => 'last',
  454
+			);
455 455
 		}
456 456
 
457 457
 		$options = array_merge(
@@ -490,11 +490,15 @@ function numbers($options = array()) {
490 490
 				$end = $params['page'] + ($modulus  - $params['page']) + 1;
491 491
 			}
492 492
 
493  
-			if ($first && $start > (int)$first) {
494  
-				if ($start == $first + 1) {
495  
-					$out .= $this->first($first, array('tag' => $tag, 'after' => $separator));
496  
-				} else {
497  
-					$out .= $this->first($first, array('tag' => $tag));
  493
+			if ($first) {
  494
+				if ($start > (int)$first) {
  495
+					if ($start == $first + 1) {
  496
+						$out .= $this->first($first, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
  497
+					} else {
  498
+						$out .= $this->first($first, array('tag' => $tag, 'separator' => $separator));
  499
+					}
  500
+				} elseif ($start == 2) {
  501
+					$out .= $this->Html->tag($tag, $this->link(1, array('page' => 1), $options)) . $separator;
498 502
 				}
499 503
 			}
500 504
 
@@ -520,11 +524,15 @@ function numbers($options = array()) {
520 524
 
521 525
 			$out .= $after;
522 526
 
523  
-			if ($last && $end <= $params['pageCount'] - (int)$last) {
524  
-				if ($end + 1 == $params['pageCount']) {
525  
-					$out .= $this->last($last, array('tag' => $tag, 'before' => $separator));
526  
-				} else {
527  
-					$out .= $this->last($last, array('tag' => $tag));
  527
+			if ($last) {
  528
+				if ($end <= $params['pageCount'] - (int)$last) {
  529
+					if ($end + 1 == $params['pageCount']) {
  530
+						$out .= $this->last($last, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
  531
+					} else {
  532
+						$out .= $this->last($last, array('tag' => $tag, 'separator' => $separator));
  533
+					}
  534
+				} elseif ($end == $params['pageCount'] - 1) {
  535
+					$out .= $separator . $this->Html->tag($tag, $this->link($params['pageCount'], array('page' => $params['pageCount']), $options));
528 536
 				}
529 537
 			}
530 538
 
60  cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -725,6 +725,66 @@ function testNumbers() {
725 725
 		$result = $this->Paginator->numbers();
726 726
 		$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>';
727 727
 		$this->assertEqual($result, $expected);
  728
+		
  729
+		$this->Paginator->params['paging'] = array('Client' => array(
  730
+			'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
  731
+			'defaults' => array('limit' => 10),
  732
+			'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
  733
+		);
  734
+
  735
+		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
  736
+		$expected = array(
  737
+			array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  738
+			' | ',
  739
+			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
  740
+			'...',
  741
+			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
  742
+			' | ',
  743
+			array('span' => array('class' => 'current')), '4895', '/span',
  744
+			' | ',
  745
+			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
  746
+			' | ',
  747
+			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
  748
+		);
  749
+		$this->assertTags($result, $expected);
  750
+		
  751
+		$this->Paginator->params['paging'] = array('Client' => array(
  752
+			'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
  753
+			'defaults' => array('limit' => 10),
  754
+			'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
  755
+		);
  756
+
  757
+		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
  758
+		$expected = array(
  759
+			array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  760
+			' | ',
  761
+			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
  762
+			' | ',
  763
+			array('span' => array('class' => 'current')), '3', '/span',
  764
+			' | ',
  765
+			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  766
+			'...',
  767
+			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
  768
+			' | ',
  769
+			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
  770
+		);
  771
+		$this->assertTags($result, $expected);
  772
+		
  773
+		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
  774
+		$expected = array(
  775
+			array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  776
+			' - ',
  777
+			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
  778
+			' - ',
  779
+			array('span' => array('class' => 'current')), '3', '/span',
  780
+			' - ',
  781
+			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  782
+			'...',
  783
+			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
  784
+			' - ',
  785
+			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
  786
+		);
  787
+		$this->assertTags($result, $expected);
728 788
 	}
729 789
 /**
730 790
  * testFirstAndLast method

0 notes on commit 76d5855

Please sign in to comment.
Something went wrong with that request. Please try again.