Skip to content
This repository
Browse code

fixes #6473, dot notation for sort in next/prev

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8213 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 9e143bc3351d4cf03328e7446bdd9bfa8d517ef4 1 parent 92b8e87
authored July 02, 2009
13  cake/libs/view/helpers/paginator.php
@@ -140,7 +140,9 @@ function sortKey($model = null, $options = array()) {
140 140
 
141 141
 		if (isset($options['sort']) && !empty($options['sort'])) {
142 142
 			if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) {
143  
-				return $result[1];
  143
+				if ($result[0] == $this->defaultModel()) {
  144
+					return $result[1];
  145
+				}
144 146
 			}
145 147
 			return $options['sort'];
146 148
 		} elseif (isset($options['order']) && is_array($options['order'])) {
@@ -149,6 +151,7 @@ function sortKey($model = null, $options = array()) {
149 151
 			if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
150 152
 				return $result[1];
151 153
 			}
  154
+			return $options['order'];
152 155
 		}
153 156
 		return null;
154 157
 	}
@@ -223,13 +226,7 @@ function sort($title, $key = null, $options = array()) {
223 226
 		}
224 227
 		$dir = 'asc';
225 228
 		$sortKey = $this->sortKey($options['model']);
226  
-		$defaultModel = $this->defaultModel();
227  
-
228  
-		if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) {
229  
-			$isSorted = ($sortKey === $defaultModel . '.' . $key);
230  
-		} else {
231  
-			$isSorted = ($sortKey === $key);
232  
-		}
  229
+		$isSorted = ($sortKey === $key);
233 230
 
234 231
 		if ($isSorted && $this->sortDir($options['model']) === 'asc') {
235 232
 			$dir = 'desc';
30  cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -911,5 +911,33 @@ function testWithPlugin() {
911 911
 		$result = $this->Paginator->link('Page 3', array('page' => 3));
912 912
 		$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
913 913
 	}
  914
+
  915
+/**
  916
+ * testNextLinkUsingDotNotation method
  917
+ *
  918
+ * @access public
  919
+ * @return void
  920
+ */
  921
+	function testNextLinkUsingDotNotation() {
  922
+		Router::reload();
  923
+		Router::parse('/');
  924
+		Router::setRequestInfo(array(
  925
+			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),	 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
  926
+			array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
  927
+		));
  928
+
  929
+		$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  930
+		$this->Paginator->params['paging']['Article']['page'] = 1;
  931
+
  932
+		$test = array('url'=> array(
  933
+			'page'=> '1',
  934
+			'sort'=>'Article.title',
  935
+			'direction'=>'asc',
  936
+		));
  937
+		$this->Paginator->options($test);
  938
+
  939
+		$result = $this->Paginator->next('Next');
  940
+		$this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
  941
+	}
914 942
 }
915  
-?>
  943
+?>

0 notes on commit 9e143bc

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