Merge pull request #1031 from krolow/ticket-2495

Paginator Sort, displaying related model field more friendly
This commit is contained in:
José Lorenzo Rodríguez 2012-12-18 00:50:12 -08:00
commit 6af78c15df
2 changed files with 16 additions and 2 deletions

View file

@ -243,7 +243,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->sort('Article.full_name'); $result = $this->Paginator->sort('Article.full_name');
$expected = array( $expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:desc', 'class' => 'asc'), 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:desc', 'class' => 'asc'),
'Article.full Name', 'Article Full Name',
'/a' '/a'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -260,7 +260,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->sort('Article.full_name'); $result = $this->Paginator->sort('Article.full_name');
$expected = array( $expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:asc', 'class' => 'desc'), 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:asc', 'class' => 'desc'),
'Article.full Name', 'Article Full Name',
'/a' '/a'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -319,6 +319,15 @@ class PaginatorHelperTest extends CakeTestCase {
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
)); ));
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Article.title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
'Article Title',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Article.title', 'Title'); $result = $this->Paginator->sort('Article.title', 'Title');
$expected = array( $expected = array(

View file

@ -315,6 +315,11 @@ class PaginatorHelper extends AppHelper {
if (empty($title)) { if (empty($title)) {
$title = $key; $title = $key;
if (strpos($title, '.') !== false) {
$title = str_replace('.', ' ', $title);
}
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title))); $title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
} }
$dir = isset($options['direction']) ? $options['direction'] : 'asc'; $dir = isset($options['direction']) ? $options['direction'] : 'asc';