Commit fd537e30 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Adding the comment sort order option to institution (Bug #1037531)"

parents 949a0b32 70c4944a
......@@ -209,6 +209,7 @@ if ($institution || $add) {
if (!$add) {
$data = get_record('institution', 'name', $institution);
$data->commentsortorder = get_config_institution($institution, 'commentsortorder');
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
// TODO: Find a better way to work around Smarty's minimal looping logic
......@@ -246,6 +247,7 @@ if ($institution || $add) {
$data->licensedefault = '';
$data->dropdownmenu = get_config('dropdownmenu') ? 1 : 0;
$data->skins = get_config('skins') ? 1 : 0;
$data->commentsortorder = 'earliest';
$lockedprofilefields = array();
$authtypes = auth_get_available_auth_types();
......@@ -443,6 +445,16 @@ if ($institution || $add) {
'defaultvalue' => $data->skins,
);
}
$elements['commentsortorder'] = array(
'type' => 'select',
'title' => get_string('commentsortorder', 'admin'),
'description' => get_string('commentsortorderdescription', 'admin'),
'defaultvalue' => $data->commentsortorder,
'options' => array('earliest' => get_string('earliest'),
'latest' => get_string('latest'),
),
'help' => true,
);
// Some more fields that are hidden from the default institution
if (empty($data->name) || $data->name != 'mahara') {
$elements['showonlineusers'] = array(
......@@ -719,9 +731,12 @@ function institution_submit(Pieform $form, $values) {
}
}
$newinstitution->theme = (empty($values['theme']) || $values['theme'] == 'sitedefault') ? null : $values['theme'];
$newinstitution->dropdownmenu = (!empty($values['dropdownmenu'])) ? 1 : 0;
$newinstitution->theme = (empty($values['theme']) || $values['theme'] == 'sitedefault') ? null : $values['theme'];
$newinstitution->dropdownmenu = (!empty($values['dropdownmenu'])) ? 1 : 0;
$newinstitution->skins = (!empty($values['skins'])) ? 1 : 0;
require_once(get_config('docroot') . 'artefact/comment/lib.php');
$commentoptions = ArtefactTypeComment::get_comment_options();
$newinstitution->commentsortorder = (empty($values['commentsortorder'])) ? $commentoptions->sort : $values['commentsortorder'];
if ($newinstitution->theme == 'custom') {
if (!empty($oldinstitution->style)) {
......
......@@ -321,6 +321,7 @@ class ArtefactTypeComment extends ArtefactType {
* object $artefact Optional artefact object
* bool $export Determines if comments are fetched for html export purposes
* bool $onview Optional - is viewing artefact comments on view page so don't show edit buttons
* string $sort Optional - the sort order of the comments. Valid options are 'earliest' and 'latest'.
* @return object $options Default comments data object
*/
public static function get_comment_options() {
......@@ -332,6 +333,7 @@ class ArtefactTypeComment extends ArtefactType {
$options->artefact = null;
$options->export = false;
$options->onview = false;
$options->sort = 'earliest';
return $options;
}
......@@ -372,6 +374,7 @@ class ArtefactTypeComment extends ArtefactType {
'owner' => $owner,
'isowner' => $isowner,
'export' => $export,
'sort' => $sort,
'data' => array(),
);
......@@ -417,6 +420,7 @@ class ArtefactTypeComment extends ArtefactType {
}
}
$sortorder = (!empty($sort) && $sort == 'latest') ? 'a.ctime DESC' : 'a.ctime ASC';
$comments = get_records_sql_assoc('
SELECT
a.id, a.author, a.authorname, a.ctime, a.mtime, a.description, a.group,
......@@ -427,7 +431,7 @@ class ArtefactTypeComment extends ArtefactType {
INNER JOIN {artefact_comment_comment} c ON a.id = c.artefact
LEFT JOIN {usr} u ON a.author = u.id
WHERE ' . $where . '
ORDER BY a.ctime', array(), $offset, $limit);
ORDER BY ' . $sortorder, array(), $offset, $limit);
$files = ArtefactType::attachments_from_id_list(array_keys($comments));
......
......@@ -318,6 +318,8 @@ $string['antispamdescription'] = 'The type of anti-spam measures used on publicl
$string['dropdownmenu'] = 'Drop-down navigation';
$string['dropdownmenudescription'] = 'If checked, the main Mahara navigation will use a drop-down format for the sub-navigation.';
$string['dropdownmenudescriptioninstitution'] = 'If checked, the main navigation for the chosen institution theme will use a drop-down format.';
$string['commentsortorder'] = 'Comment sort order';
$string['commentsortorderdescription'] = 'Set the sort order for artefact comments when viewed on a page.';
$string['defaultaccountinactiveexpire'] = 'Default account inactivity time';
$string['defaultaccountinactiveexpiredescription'] = 'How long a user account will remain active without the user logging in';
$string['defaultaccountinactivewarn'] = 'Warning time for inactivity / expiry';
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Comment sort order</h3>
<p>The comments that an artefact has received are displayed below the
artefact on the page. The order in which the comments are displayed is based in this
setting, either <strong>earliest</strong> to latest or
<strong>latest</strong> to earliest.</p>
\ No newline at end of file
......@@ -153,6 +153,8 @@ $string['nameztoa'] = 'Name Z to A';
$string['firstjoined'] = 'First joined';
$string['lastjoined'] = 'Last joined';
$string['date'] = 'Date';
$string['earliest'] = 'Earliest';
$string['latest'] = 'Latest';
$string['dateformatguide'] = 'Use the format YYYY/MM/DD';
$string['dateofbirthformatguide'] = 'Use the format YYYY/MM/DD';
$string['datetimeformatguide'] = 'Use the format YYYY/MM/DD HH:MM';
......
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