diff --git a/_test/helper.test.php b/_test/helper.test.php index c85c59e..ad218fc 100644 --- a/_test/helper.test.php +++ b/_test/helper.test.php @@ -202,14 +202,15 @@ function testReplacePlaceholdersInSQL() { $this->assertEquals('en', $data['sql']); } - protected function createColumnEntry($name, $multi, $key, $origkey, $title, $type) { + protected function createColumnEntry($name, $multi, $key, $origkey, $title, $type, $datatype = '') { return array( 'colname' => $name, 'multi' => $multi, 'key' => $key, 'origkey' => $origkey, 'title' => $title, - 'type' => $type + 'type' => $type, + 'datatype' => $datatype ); } diff --git a/_test/syntax_plugin_data_entry.test.php b/_test/syntax_plugin_data_entry.test.php index c657cdb..bae1230 100644 --- a/_test/syntax_plugin_data_entry.test.php +++ b/_test/syntax_plugin_data_entry.test.php @@ -309,14 +309,15 @@ function testHandleEmpty() { $this->assertEquals($cols, $result['cols'], 'Cols array corrupted'); } - protected function createColumnEntry($name, $multi, $key, $origkey, $title, $type) { + protected function createColumnEntry($name, $multi, $key, $origkey, $title, $type, $datatype = '') { return array( 'colname' => $name, 'multi' => $multi, 'key' => $key, 'origkey' => $origkey, 'title' => $title, - 'type' => $type + 'type' => $type, + 'datatype' => $datatype ); } diff --git a/_test/syntax_plugin_data_table.test.php b/_test/syntax_plugin_data_table.test.php index ddef008..61be636 100644 --- a/_test/syntax_plugin_data_table.test.php +++ b/_test/syntax_plugin_data_table.test.php @@ -13,7 +13,7 @@ class syntax_plugin_data_table_test extends DokuWikiTest { . 'headers : Details, "Assigned Employees \#no", stuff outside quotes """Deadline, ", Personal website, $$$'."\n" . "max : 10\n" . "filter : type=web development\n" - . "sort : ^volume\n" + . "sort : ^(num)volume,%pageid%\n" . "dynfilters: 1\n" . "summarize : 1\n" . "align : c\n" @@ -30,10 +30,10 @@ function testHandle() { $data = array( 'classes' => 'employees', 'limit' => 10, - 'dynfilters' => 1, - 'summarize' => 1, - 'rownumbers' => 1, - 'sepbyheaders' => '', + 'dynfilters' => true, + 'summarize' => true, + 'rownumbers' => true, + 'sepbyheaders' => false, 'headers' => array( '0' => 'Details', '1' => 'Assigned Employees #no', @@ -65,6 +65,7 @@ function testHandle() { 'origkey' => '%pageid%', 'title' => 'Title', 'type' => 'page', + 'datatype' => '' ), 'employee' => array( 'colname' => 'employees', @@ -72,7 +73,8 @@ function testHandle() { 'key' => 'employee', 'origkey' => 'employee', 'title' => 'employee', - 'type' => '' + 'type' => '', + 'datatype' => '' ), 'deadline' => array( 'colname' => 'deadline_dt', @@ -80,7 +82,8 @@ function testHandle() { 'key' => 'deadline', 'origkey' => 'deadline', 'title' => 'deadline', - 'type' => 'dt' + 'type' => 'dt', + 'datatype' => '' ), 'website' => array( 'colname' => 'website_url', @@ -88,7 +91,8 @@ function testHandle() { 'key' => 'website', 'origkey' => 'website', 'title' => 'website', - 'type' => 'url' + 'type' => 'url', + 'datatype' => '' ), 'volume' => array( 'colname' => 'volume', @@ -96,13 +100,14 @@ function testHandle() { 'key' => 'volume', 'origkey' => 'volume', 'title' => 'volume', - 'type' => '' + 'type' => '', + 'datatype' => '' ), ), 'sort' => array( - '0' => 'volume', - '1' => 'DESC' + 'volume' => array('volume', 'DESC', 'numeric'), + '%pageid%' => array('%pageid%', 'ASC', '') ), 'align' => array( '0' => 'center' @@ -120,7 +125,7 @@ function testHandle() { LEFT JOIN data AS T1 ON T1.pid = W1.pid AND T1.key = 'employee' LEFT JOIN data AS T2 ON T2.pid = W1.pid AND T2.key = 'deadline' LEFT JOIN data AS T3 ON T3.pid = W1.pid AND T3.key = 'website' LEFT JOIN data AS T4 ON T4.pid = W1.pid AND T4.key = 'volume' LEFT JOIN pages ON W1.pid=pages.pid GROUP BY W1.pid - ORDER BY T4.value DESC LIMIT 11", + ORDER BY CAST(T4.value AS NUMERIC) DESC, pages.page ASC LIMIT 11", 'cur_param' => array() ); diff --git a/helper.php b/helper.php index 56e8693..d105cad 100644 --- a/helper.php +++ b/helper.php @@ -364,15 +364,16 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) { * @param string $col column name * @return array with key, type, ismulti, title, opt */ - function _column($col) { - preg_match('/^([^_]*)(?:_(.*))?((? $col, - 'multi' => ($matches[3] === 's'), + 'multi' => ($matches[4] === 's'), 'key' => utf8_strtolower($matches[1]), 'origkey' => $matches[1], //similar to key, but stores upper case 'title' => $matches[1], - 'type' => utf8_strtolower($matches[2]) + 'type' => utf8_strtolower($matches[3]), + 'datatype'=> $matches[2] == '(num)' ? 'numeric' : '' ); // fix title for special columns diff --git a/syntax/table.php b/syntax/table.php index c0a2b39..c1eeadc 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -152,12 +152,10 @@ function handle($match, $state, $pos, Doku_Handler $handler) { break; case 'order': case 'sort': - $column = $this->dthlp->_column($line[1]); - $sort = $column['key']; - if(substr($sort, 0, 1) == '^') { - $data['sort'] = array(substr($sort, 1), 'DESC'); - } else { - $data['sort'] = array($sort, 'ASC'); + $cols = explode(',', $line[1]); + foreach($cols as $col) { + $param = $this->parseSortParam($col); + $data['sort'][$param[0]] = $param; } break; case 'where': @@ -408,13 +406,17 @@ function preList($clist, $data) { $text .= '