Skip to content

Commit

Permalink
Added new $sortoption.
Browse files Browse the repository at this point in the history
  • Loading branch information
drachels committed Oct 16, 2020
1 parent 5d3cabb commit b9c1595
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -265,13 +290,28 @@
$options['id'] = $id;
$options['diary'] = $diary->id;
$output = ' ';

// Add download button.
$options['action'] = 'download';
$url = new moodle_url('/mod/diary/report.php', $options);
$output .= html_writer::link($url, $OUTPUT->pix_icon('i/export'
, 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);
Expand Down Expand Up @@ -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);

Expand All @@ -328,30 +369,30 @@
$saveallbutton .= "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
$saveallbutton .= "<input type=\"submit\" class='btn btn-primary' value=\"".get_string("saveallfeedback", "diary")."\" />";


// 20200421 Added a return button.
$url = $CFG->wwwroot . '/mod/diary/view.php?id='.$id;
$saveallbutton .= ' <a href="'.$url
.'" class="btn btn-secondary" role="button">'
.get_string('returnto', 'diary', $diary->name).'</a>';


$saveallbutton .= "</p>";

// Add save button at the top of the list of users with entries.
echo $saveallbutton;

$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 '<div align="center" style="font-size:1em;
font-weight:bold;background: '.$dcolor3.';
border:2px solid black;
-webkit-border-radius:16px;
-moz-border-radius:16px;border-radius:16px;">';
// 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 '</div>';

Expand Down

0 comments on commit b9c1595

Please sign in to comment.