Skip to content

Commit

Permalink
MDL-32888 Grader report: refined user search
Browse files Browse the repository at this point in the history
  • Loading branch information
Melissa Aitkin committed Oct 17, 2013
1 parent 8e4bf6c commit cbe8e5b
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 66 deletions.
85 changes: 28 additions & 57 deletions grade/report/grader/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -39,16 +40,22 @@
$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)));

Expand Down Expand Up @@ -150,55 +157,14 @@
$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) {
Expand All @@ -211,7 +177,12 @@
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'))) {
Expand Down
25 changes: 16 additions & 9 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,10 @@ public function print_toggle($type) {
* 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();
Expand Down Expand Up @@ -678,17 +679,20 @@ public function get_left_rows() {
}

$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();
Expand Down Expand Up @@ -1064,8 +1068,10 @@ public function get_right_rows() {
$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;
}
Expand All @@ -1074,14 +1080,15 @@ public function get_right_rows() {
* 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 = '';

Expand Down
8 changes: 8 additions & 0 deletions grade/report/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -341,6 +347,8 @@ protected function setup_groups() {
}

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);
Expand Down
88 changes: 88 additions & 0 deletions user/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,94 @@ protected function htmllize_tree($tree, $dir) {

return $result;
}

/**
* Prints user search utility that can search user by first initial of firstname and/or first initial of lastname
* Prints a header with a title and the number of users found within that subset
* @param string $url the url to return to, complete with any parameters needed for the return
* @param string $hiddenfields any extra hidden fields needed by the selection process or to comlete the reset process
* @param string $firstinitial the first initial of the firstname
* @param string $lastinitial the first initial of the lastname
* @param int $usercount the amount of users meeting the search criteria
* @param int $totalcount the amount of users of the set/subset being searched
* @param string $heading heading of the subset being searched, default is All Participants
* @return string html output
*/
public function user_search($url, $hiddenfields, $firstinitial, $lastinitial, $usercount, $totalcount, $heading = null) {
global $OUTPUT;

$strall = get_string('all');
$alpha = explode(',', get_string('alphabet', 'langconfig'));

if (!isset($heading)) {
$heading = get_string('allparticipants');
}

$content = html_writer::start_tag('form', array('action' => new moodle_url($url)));
$content .= html_writer::start_tag('div');

// Search utility heading
$content .= $OUTPUT->heading($heading.get_string('labelsep', 'langconfig').$usercount.'/'.$totalcount, 3);

// Hidden fields
$content .= html_writer::input_hidden_params($url);
$content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => get_string('reset')));
if (isset($hiddenfields)) {
foreach ($hiddenfields as $key => $value) {
$content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
}
}
// Bar of first initials
$content .= html_writer::start_tag('div', array('class' => 'initialbar firstinitial'));
$content .= html_writer::label(get_string('firstname').' : ', null);

if (!empty($firstinitial)) {
$content .= html_writer::link($url.'&sifirst=', $strall);
} else {
$content .= html_writer::tag('strong', $strall);
}

foreach ($alpha as $letter) {
if ($letter == $firstinitial) {
$content .= html_writer::tag('strong', $letter);
} else {
$content .= html_writer::link($url.'&sifirst='.$letter, $letter);
}
}
$content .= html_writer::end_tag('div');

// Bar of last initials
$content .= html_writer::start_tag('div', array('class' => 'initialbar lastinitial'));
$content .= html_writer::label(get_string('lastname').' : ', null);

if (!empty($lastinitial)) {
$content .= html_writer::link($url.'&silast=', $strall);
} else {
$content .= html_writer::tag('strong', $strall);
}

foreach ($alpha as $letter) {
if ($letter == $lastinitial) {
$content .= html_writer::tag('strong', $letter);
} else {
$content .= html_writer::link($url.'&silast='.$letter, $letter);
}
}
$content .= html_writer::end_tag('div');

// Reset button
$content .= html_writer::tag('div', '&nbsp');
$content .= html_writer::start_tag('div', array('class' => 'mdl-align'));
$content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('reset')));
$content .= html_writer::end_tag('div');

$content .= html_writer::end_tag('div');
$content .= html_writer::tag('div', '&nbsp');
$content .= html_writer::end_tag('form');

return $content;
}

}

class user_files_tree implements renderable {
Expand Down

0 comments on commit cbe8e5b

Please sign in to comment.