Commit a7df7ba2 authored by lphuberdeau's avatar lphuberdeau

[MRG] Automatic merge, branches/10.x 44617 to 44620

parent f175ced0
......@@ -1369,7 +1369,18 @@ class ArtLib extends TikiLib
from `tiki_articles`
$fromSql
$join
$mid $mid2 order by " . $this->convertSortMode($sort_mode);
$mid $mid2 order by " . $this->convertSortMode($sort_mode, array(
'title',
'state',
'authorName',
'topicId',
'topicName',
'publishDate',
'expireDate',
'created',
'author',
'rating',
));
$result = $this->query($query, $bindvars, $maxRecords, $offset);
$query_cant = "select distinct count(*) from `tiki_articles` $fromSql $join $mid $mid2";
......
......@@ -170,7 +170,7 @@ abstract class TikiDb
}
} // }}}
function convertSortMode( $sort_mode ) // {{{
function convertSortMode( $sort_mode, $fields = null ) // {{{
{
if ( !$sort_mode ) {
return '';
......@@ -183,8 +183,8 @@ abstract class TikiDb
return "RAND()";
}
$sorts=explode(',', $sort_mode);
foreach ($sorts as $k => $sort) {
$sorts = array();
foreach (explode(',', $sort_mode) as $sort) {
// force ending to either _asc or _desc unless it's "random"
$sep = strrpos($sort, '_');
......@@ -196,11 +196,22 @@ abstract class TikiDb
$sort .= 'asc';
}
// When valid fields are specified, skip those not available
if (is_array($fields) && preg_match('/^(.*)_(asc|desc)$/', $sort, $parts)) {
if (! in_array($parts[1], $fields)) {
continue;
}
}
$sort = preg_replace('/_asc$/', '` asc', $sort);
$sort = preg_replace('/_desc$/', '` desc', $sort);
$sort = '`' . $sort;
$sort = str_replace('.', '`.`', $sort);
$sorts[$k]=$sort;
$sorts[] = $sort;
}
if (empty($sorts)) {
return '1';
}
$sort_mode=implode(',', $sorts);
......
......@@ -87,9 +87,9 @@ class TikiDb_Bridge extends TikiDb
self::get()->convertQueryTablePrefixes($query);
} // }}}
function convertSortMode( $sort_mode ) // {{{
function convertSortMode( $sort_mode, $fields = null ) // {{{
{
return self::get()->convertSortMode($sort_mode);
return self::get()->convertSortMode($sort_mode, $fields);
} // }}}
function getQuery() // {{{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment