Skip to content

Commit

Permalink
fixes #6473, dot notation for sort in next/prev
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8213 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Jul 2, 2009
1 parent 92b8e87 commit 9e143bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
13 changes: 5 additions & 8 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -140,7 +140,9 @@ function sortKey($model = null, $options = array()) {

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'])) {
Expand All @@ -149,6 +151,7 @@ function sortKey($model = null, $options = array()) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
return $result[1];
}
return $options['order'];
}
return null;
}
Expand Down Expand Up @@ -223,13 +226,7 @@ function sort($title, $key = null, $options = array()) {
}
$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';
Expand Down
30 changes: 29 additions & 1 deletion cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -911,5 +911,33 @@ function testWithPlugin() {
$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);
}
}
?>
?>

0 comments on commit 9e143bc

Please sign in to comment.