From b9c1595720ef7e2844ce88d23d9589f99047ee74 Mon Sep 17 00:00:00 2001
From: drachels
Date: Fri, 16 Oct 2020 10:02:34 -0500
Subject: [PATCH] Added new $sortoption.
---
report.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 46 insertions(+), 5 deletions(-)
diff --git a/report.php b/report.php
index 629d92f..bf3935b 100644
--- a/report.php
+++ b/report.php
@@ -48,6 +48,14 @@
print_error('invalidid', 'diary');
}
+// 20201014 Set a default sorting order for entry retrieval.
+if ($sortoption = get_user_preferences('sortoption')) {
+ $sortoption = get_user_preferences('sortoption');
+} else {
+ set_user_preference('sortoption', 'u.lastname ASC, u.firstname ASC');
+ $sortoption = get_user_preferences('sortoption');
+}
+
// Handle toolbar capabilities.
if (!empty($action)) {
switch ($action) {
@@ -57,6 +65,24 @@
results::download_entries($context, $course, $diary);
}
break;
+ case 'lastnameasc':
+ if (has_capability('mod/diary:manageentries', $context)) {
+ $stringlable = 'lastnameasc';
+ // 20201014 Set order and get ALL diary entries in lastname ascending order.
+ set_user_preference('sortoption', 'u.lastname ASC, u.firstname ASC');
+ $sortoption = get_user_preferences('sortoption');
+ $eee = $DB->get_records("diary_entries", array("diary" => $diary->id));
+ }
+ break;
+ case 'lastnamedesc':
+ if (has_capability('mod/diary:manageentries', $context)) {
+ $stringlable = 'lastnamedesc';
+ // 20201014 Set order and get ALL diary entries in lastname descending order.
+ set_user_preference('sortoption', 'u.lastname DESC, u.firstname DESC');
+ $sortoption = get_user_preferences('sortoption');
+ $eee = $DB->get_records("diary_entries", array("diary" => $diary->id));
+ }
+ break;
case 'currententry':
if (has_capability('mod/diary:manageentries', $context)) {
$stringlable = 'currententry';
@@ -145,8 +171,7 @@
confirm_sesskey();
$feedback = array();
$data = (array)$data;
- // My single data entry contains id, sesskey, and three other items,entry, feedback, and ???
-
+ // My single data entry contains id, sesskey, and three other items, entry, feedback, and ???
// Peel out all the data from variable names.
foreach ($data as $key => $val) {
if (strpos($key, 'r') === 0 || strpos($key, 'c') === 0) {
@@ -265,6 +290,7 @@
$options['id'] = $id;
$options['diary'] = $diary->id;
$output = ' ';
+
// Add download button.
$options['action'] = 'download';
$url = new moodle_url('/mod/diary/report.php', $options);
@@ -272,6 +298,20 @@
, get_string('csvexport', 'diary'))
, array('class' => 'toolbutton'));
+ // Add sort by lastname ascending button.
+ $options['action'] = 'lastnameasc';
+ $url = new moodle_url('/mod/diary/report.php', $options);
+ $output .= html_writer::link($url, $OUTPUT->pix_icon('t/sort_asc'
+ , get_string('lastnameasc', 'diary'))
+ , array('class' => 'toolbutton'));
+
+ // Add sort by lastname descending button.
+ $options['action'] = 'lastnamedesc';
+ $url = new moodle_url('/mod/diary/report.php', $options);
+ $output .= html_writer::link($url, $OUTPUT->pix_icon('t/sort_desc'
+ , get_string('lastnamedesc', 'diary'))
+ , array('class' => 'toolbutton'));
+
// Add reload toolbutton.
$options['action'] = $stringlable;
$url = new moodle_url('/mod/diary/report.php', $options);
@@ -313,6 +353,7 @@
// Add the toolbar to the top of the report page.
echo $output;
}
+
// Next line is different from Journal line 171.
$grades = make_grades_menu($diary->scale);
@@ -328,14 +369,12 @@
$saveallbutton .= "";
$saveallbutton .= "";
-
// 20200421 Added a return button.
$url = $CFG->wwwroot . '/mod/diary/view.php?id='.$id;
$saveallbutton .= ' '
.get_string('returnto', 'diary', $diary->name).'';
-
$saveallbutton .= "
";
// Add save button at the top of the list of users with entries.
@@ -343,8 +382,9 @@
$dcolor3 = get_config('mod_diary', 'entrybgc');
$dcolor4 = get_config('mod_diary', 'entrytextbgc');
+
// Print a list of users who have completed at least one entry.
- if ($usersdone = diary_get_users_done($diary, $currentgroup)) {
+ if ($usersdone = diary_get_users_done($diary, $currentgroup, $sortoption)) {
foreach ($usersdone as $user) {
echo '
';
// Based on toolbutton and on list of users with at least one entry, print the entries onscreen.
+
echo results::diary_print_user_entry($course, $diary, $user, $entrybyuser[$user->id], $teachers, $grades);
echo '