mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
fixes #6507 paginator sort directions
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8239 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
4cfdd311a9
commit
56bee6e1fc
2 changed files with 13 additions and 1 deletions
|
@ -226,11 +226,12 @@ class PaginatorHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
$dir = 'asc';
|
$dir = 'asc';
|
||||||
$sortKey = $this->sortKey($options['model']);
|
$sortKey = $this->sortKey($options['model']);
|
||||||
$isSorted = ($sortKey === $key);
|
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
|
||||||
|
|
||||||
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
|
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
|
||||||
$dir = 'desc';
|
$dir = 'desc';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($title) && array_key_exists($dir, $title)) {
|
if (is_array($title) && array_key_exists($dir, $title)) {
|
||||||
$title = $title[$dir];
|
$title = $title[$dir];
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,17 @@ class PaginatorHelperTest extends CakeTestCase {
|
||||||
$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
|
$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
|
||||||
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
|
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
|
||||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result);
|
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result);
|
||||||
|
|
||||||
|
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
|
||||||
|
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
|
||||||
|
$result = $this->Paginator->sort('title');
|
||||||
|
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
|
||||||
|
|
||||||
|
|
||||||
|
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
|
||||||
|
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
|
||||||
|
$result = $this->Paginator->sort('title');
|
||||||
|
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testSortLinksUsingDotNotation method
|
* testSortLinksUsingDotNotation method
|
||||||
|
|
Loading…
Reference in a new issue