Commit c3e794c2 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Fetching / passing the institution comment sort order (Bug #1037531)

Getting the user's institution comment sort order to sort the comments
for the artefacts on the view page. So that the expand out comment
areas are sorted either earliest -> latest or visa versa.

Change-Id: I13b37b0a42c818ccc21147e4a0469015a020dd80
Signed-off-by: Robert Lyon's avatarRobert Lyon <>
parent 70c4944a
......@@ -333,7 +333,8 @@ class ArtefactTypeComment extends ArtefactType {
$options->artefact = null;
$options->export = false;
$options->onview = false;
$options->sort = 'earliest';
$sortorder = get_user_institution_comment_sort_order();
$options->sort = (!empty($sortorder)) ? $sortorder : 'earliest';
return $options;
......@@ -3986,3 +3986,29 @@ function server_busy($threshold = false) {
return false;
* Find out a user's institution sort order for comments on artefacts within view page.
* If they belong to one institution that has specified a sort order, then this will
* be that institution's comment sort.
* If they belong to multiple institutions then the arbitrarily "first" institution's
* sort order will be used.
* @param int $userid Which user to check (defaults to $USER)
* @return string Sort order - either 'earliest', 'latest'.
function get_user_institution_comment_sort_order($userid = null) {
$instsorts = get_configs_user_institutions('commentsortorder', $userid);
$sortorder = null;
// Every user belongs to at least one institution
foreach ($instsorts as $sort) {
// If the user belongs to multiple institutions, arbitrarily use the sort
// from the first one that has specified a sort.
if (!empty($sort)) {
$sortorder = $sort;
return $sortorder;
......@@ -30,7 +30,7 @@
{if $item->author}
<div class="author"><a href="{$item->author->profileurl}" class="username">{$item->author|display_name}</a><span class="postedon"> - {$item->date} {if $item->updated}[{str tag=Updated}: {$item->updated}]{/if}</span></div>
<div class="author">{$item->authorname}<span class="postedon"> - {$item->date}</span></div>
{if $item->deletedmessage}
<div class="deleteddetails">{$item->deletedmessage}</div>
Supports Markdown
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