Commit dc58ab00 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge "Add sorting by last update or comment in view_search"

parents b130fa9b aa2febcc
......@@ -3010,7 +3010,6 @@ class View {
$ph = array_merge($ph, array($ownerquery,$ownerquery,$ownerquery,$ownerquery,$ownerquery));
}
$count = count_records_sql('SELECT COUNT(*) ' . $from . $where, $ph);
$orderby = 'title ASC';
if (!empty($sort)) {
$orderby = '';
......@@ -3022,7 +3021,21 @@ class View {
if (!empty($orderby)) {
$orderby .= ', ';
}
$orderby .= $item['column'];
if ($item['column'] == 'lastchanged') {
// We need the date of the last comment on each view
$from .= 'LEFT OUTER JOIN (
SELECT c.onview, MAX(a.mtime) AS lastcomment
FROM {artefact_comment_comment} c JOIN {artefact} a ON c.artefact = a.id AND c.deletedby IS NULL AND c.private = 0
GROUP BY c.onview
) l ON v.id = l.onview
';
$orderby .= 'GREATEST(lastcomment, v.mtime)';
}
else {
$orderby .= 'v.' . $item['column'];
}
if ($item['desc']) {
$orderby .= ' DESC';
}
......@@ -3032,13 +3045,15 @@ class View {
}
}
$count = count_records_sql('SELECT COUNT(*) ' . $from . $where, $ph);
$viewdata = get_records_sql_assoc('
SELECT
v.id, v.title, v.description, v.owner, v.ownerformat, v.group, v.institution,
v.template, v.mtime, v.ctime,
c.id AS collid, c.name, v.type
' . $from . $where . '
ORDER BY v.' . $orderby . ', v.id ASC',
ORDER BY ' . $orderby . ', v.id ASC',
$ph, $offset, $limit
);
......
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