MDL-32888 Grader report: refined user search

This commit is contained in:
Melissa Aitkin 2013-06-26 11:27:29 +10:00
parent 8e4bf6cca6
commit cbe8e5b325
4 changed files with 140 additions and 66 deletions

View file

@ -24,6 +24,7 @@
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
require_once $CFG->dirroot.'/user/renderer.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/grader/lib.php';
@ -39,16 +40,22 @@ $target = optional_param('target', 0, PARAM_ALPHANUM);
$toggle = optional_param('toggle', NULL, PARAM_INT);
$toggle_type = optional_param('toggle_type', 0, PARAM_ALPHANUM);
$reset = optional_param('Reset', NULL, PARAM_ALPHA);
$graderreportsifirst = optional_param('sifirst', NULL, PARAM_ALPHA);
$graderreportsilast = optional_param('silast', NULL, PARAM_ALPHA);
// the report object is recreated each time, save search information to session for future use
if (isset($graderreportsifirst)) {
$SESSION->graderreportsifirst = $graderreportsifirst;
}
if (isset($graderreportsilast)) {
$SESSION->graderreportsilast = $graderreportsilast;
}
if (isset($reset)) {
$SESSION->graderreportsifirst = '';
$SESSION->graderreportsilast = '';
} else {
// the report object is recreated each time, save search information to session for future use
if (isset($graderreportsifirst)) {
$SESSION->graderreportsifirst = $graderreportsifirst;
}
if (isset($graderreportsilast)) {
$SESSION->graderreportsilast = $graderreportsilast;
}
}
$PAGE->set_url(new moodle_url('/grade/report/grader/index.php', array('id'=>$courseid)));
@ -150,55 +157,14 @@ $report->load_users();
$report->load_final_grades();
echo $report->group_selector;
// Initials Selection Section
$baseurl = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
$firstinitial = isset($SESSION->graderreportsifirst) ? $SESSION->graderreportsifirst : "";
$lastinitial = isset($SESSION->graderreportsilast) ? $SESSION->graderreportsilast : "";
$strall = get_string('all');
$alpha = explode(',', get_string('alphabet', 'langconfig'));
$strallparticipants = get_string('allparticipants');
$totalusers = $report->get_numusers(false, false);
echo '<form action="index.php">';
echo '<div>';
echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$numusers.'/'.$totalusers, 3);
// Bar of first initials
echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
if (!empty($firstinitial)) {
echo '<a href="'.$baseurl->out().'&amp;sifirst=">'.$strall.'</a>';
} else {
echo '<strong>'.$strall.'</strong>';
}
foreach ($alpha as $letter) {
if ($letter == $firstinitial) {
echo ' <strong>'.$letter.'</strong>';
} else {
echo ' <a href="'.$baseurl->out().'&amp;sifirst='.$letter.'">'.$letter.'</a>';
}
}
echo '</div>';
// Bar of last initials
echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
if (!empty($lastinitial)) {
echo '<a href="'.$baseurl->out().'&amp;silast=">'.$strall.'</a>';
} else {
echo '<strong>'.$strall.'</strong>';
}
foreach ($alpha as $letter) {
if ($letter == $lastinitial) {
echo ' <strong>'.$letter.'</strong>';
} else {
echo ' <a href="'.$baseurl->out().'&amp;silast='.$letter.'">'.$letter.'</a>';
}
}
echo '</div>';
echo '</div>';
echo '<div>&nbsp;</div>';
echo '</form>';
// Initials Selection Section
// User search
$url = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
$hiddenfields = array('group' => 0);
$firstinitial = isset($SESSION->graderreportsifirst) ? $SESSION->graderreportsifirst : '';
$lastinitial = isset($SESSION->graderreportsilast) ? $SESSION->graderreportsilast : '';
$totalusers = $report->get_numusers(true, false);
$renderer = $PAGE->get_renderer('core_user');
echo $renderer->user_search($url, $hiddenfields, $firstinitial, $lastinitial, $numusers, $totalusers, $report->currentgroupname);
//show warnings if any
foreach($warnings as $warning) {
@ -211,7 +177,12 @@ if (!empty($studentsperpage)) {
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}
$reporthtml = $report->get_grade_table();
$displayaverages = true;
if ($numusers == 0) {
$displayaverages = false;
}
$reporthtml = $report->get_grade_table($displayaverages);
// print submit button
if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {

View file

@ -559,9 +559,10 @@ class grade_report_grader extends grade_report {
* This consists of student names and icons, links to user reports and id numbers, as well
* as header cells for these columns. It also includes the fillers required for the
* categories displayed on the right side of the report.
* @param boolean $displayaverages whether to display average rows in the table
* @return array Array of html_table_row objects
*/
public function get_left_rows() {
public function get_left_rows($displayaverages) {
global $CFG, $USER, $OUTPUT;
$rows = array();
@ -678,17 +679,20 @@ class grade_report_grader extends grade_report {
}
$rows = $this->get_left_range_row($rows, $colspan);
$rows = $this->get_left_avg_row($rows, $colspan, true);
$rows = $this->get_left_avg_row($rows, $colspan);
if ($displayaverages) {
$rows = $this->get_left_avg_row($rows, $colspan, true);
$rows = $this->get_left_avg_row($rows, $colspan);
}
return $rows;
}
/**
* Builds and returns the rows that will make up the right part of the grader report
* @param boolean $displayaverages whether to display average rows in the table
* @return array Array of html_table_row objects
*/
public function get_right_rows() {
public function get_right_rows($displayaverages) {
global $CFG, $USER, $OUTPUT, $DB, $PAGE;
$rows = array();
@ -1064,8 +1068,10 @@ class grade_report_grader extends grade_report {
$PAGE->requires->strings_for_js(array('ajaxchoosescale','ajaxclicktoclose','ajaxerror','ajaxfailedupdate', 'ajaxfieldchanged'), 'gradereport_grader');
$rows = $this->get_right_range_row($rows);
$rows = $this->get_right_avg_row($rows, true);
$rows = $this->get_right_avg_row($rows);
if ($displayaverages) {
$rows = $this->get_right_avg_row($rows, true);
$rows = $this->get_right_avg_row($rows);
}
return $rows;
}
@ -1074,14 +1080,15 @@ class grade_report_grader extends grade_report {
* Depending on the style of report (fixedstudents vs traditional one-table),
* arranges the rows of data in one or two tables, and returns the output of
* these tables in HTML
* @param boolean $displayaverages whether to display average rows in the table
* @return string HTML
*/
public function get_grade_table() {
public function get_grade_table($displayaverages = false) {
global $OUTPUT;
$fixedstudents = $this->is_fixed_students();
$leftrows = $this->get_left_rows();
$rightrows = $this->get_right_rows();
$leftrows = $this->get_left_rows($displayaverages);
$rightrows = $this->get_right_rows($displayaverages);
$html = '';

View file

@ -102,6 +102,12 @@ abstract class grade_report {
*/
public $currentgroup;
/**
* The current groupname being displayed.
* @var string $currentgroupname
*/
public $currentgroupname;
/**
* Current course group mode
* @var int $groupmode
@ -341,6 +347,8 @@ abstract class grade_report {
}
if ($this->currentgroup) {
$group = groups_get_group($this->currentgroup);
$this->currentgroupname = $group->name;
$this->groupsql = " JOIN {groups_members} gm ON gm.userid = u.id ";
$this->groupwheresql = " AND gm.groupid = :gr_grpid ";
$this->groupwheresql_params = array('gr_grpid'=>$this->currentgroup);