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
This commit is contained in:
gwoo 2009-07-02 23:48:10 +00:00
parent 92b8e87ed7
commit 9e143bc335
2 changed files with 34 additions and 9 deletions

View file

@ -140,7 +140,9 @@ class PaginatorHelper extends AppHelper {
if (isset($options['sort']) && !empty($options['sort'])) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) {
return $result[1];
if ($result[0] == $this->defaultModel()) {
return $result[1];
}
}
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
@ -149,6 +151,7 @@ class PaginatorHelper extends AppHelper {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
return $result[1];
}
return $options['order'];
}
return null;
}
@ -223,13 +226,7 @@ class PaginatorHelper extends AppHelper {
}
$dir = 'asc';
$sortKey = $this->sortKey($options['model']);
$defaultModel = $this->defaultModel();
if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) {
$isSorted = ($sortKey === $defaultModel . '.' . $key);
} else {
$isSorted = ($sortKey === $key);
}
$isSorted = ($sortKey === $key);
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';

View file

@ -911,5 +911,33 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->link('Page 3', array('page' => 3));
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
}
/**
* testNextLinkUsingDotNotation method
*
* @access public
* @return void
*/
function testNextLinkUsingDotNotation() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
));
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->params['paging']['Article']['page'] = 1;
$test = array('url'=> array(
'page'=> '1',
'sort'=>'Article.title',
'direction'=>'asc',
));
$this->Paginator->options($test);
$result = $this->Paginator->next('Next');
$this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
}
}
?>
?>