MDL-32888 Grader report: added user search

This commit is contained in:
Melissa Aitkin 2013-06-21 11:57:18 +10:00
parent f8eff10319
commit 8e4bf6cca6
3 changed files with 111 additions and 14 deletions

View File

@ -39,6 +39,17 @@ $target = optional_param('target', 0, PARAM_ALPHANUM);
$toggle = optional_param('toggle', NULL, PARAM_INT);
$toggle_type = optional_param('toggle_type', 0, PARAM_ALPHANUM);
$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;
}
$PAGE->set_url(new moodle_url('/grade/report/grader/index.php', array('id'=>$courseid)));
/// basic access checks
@ -118,6 +129,7 @@ print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $butt
//Initialise the grader report object that produces the table
//the class grade_report_grader_ajax was removed as part of MDL-21562
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
$numusers = $report->get_numusers(true, true);
// make sure separate group does not prevent view
if ($report->currentgroup == -2) {
@ -135,11 +147,58 @@ if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/gr
// final grades MUST be loaded after the processing
$report->load_users();
$numusers = $report->get_numusers();
$report->load_final_grades();
echo $report->group_selector;
echo '<div class="clearer"></div>';
// 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
//show warnings if any
foreach($warnings as $warning) {

View File

@ -145,7 +145,7 @@ class grade_report_grader extends grade_report {
$this->pbarurl = new moodle_url('/grade/report/grader/index.php', array('id' => $this->courseid));
$this->setup_groups();
$this->setup_users();
$this->setup_sortitemid();
}
@ -158,7 +158,7 @@ class grade_report_grader extends grade_report {
public function process_data($data) {
global $DB;
$warnings = array();
$separategroups = false;
$mygroups = array();
if ($this->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $this->context)) {
@ -175,6 +175,7 @@ class grade_report_grader extends grade_report {
// always initialize all arrays
$queue = array();
$this->load_users();
$this->load_final_grades();
@ -397,8 +398,9 @@ class grade_report_grader extends grade_report {
if (!empty($this->users)) {
return;
}
$this->setup_users();
// Limit to users with a gradeable role.
//limit to users with a gradeable role
list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
// Limit to users with an active enrollment.
@ -412,8 +414,7 @@ class grade_report_grader extends grade_report {
// If the user has clicked one of the sort asc/desc arrows.
if (is_numeric($this->sortitemid)) {
$params = array_merge(array('gitemid' => $this->sortitemid), $gradebookrolesparams, $this->groupwheresql_params, $enrolledparams,
$relatedctxparams);
$params = array_merge(array('gitemid'=>$this->sortitemid), $gradebookrolesparams, $this->userwheresql_params, $this->groupwheresql_params, $enrolledparams);
$sortjoin = "LEFT JOIN {grade_grades} g ON g.userid = u.id AND g.itemid = $this->sortitemid";
$sort = "g.finalgrade $this->sortorder";
@ -435,7 +436,7 @@ class grade_report_grader extends grade_report {
break;
}
$params = array_merge($gradebookrolesparams, $this->groupwheresql_params, $enrolledparams, $relatedctxparams);
$params = array_merge($gradebookrolesparams, $this->userwheresql_params, $this->groupwheresql_params, $enrolledparams, $relatedctxparams);
}
$sql = "SELECT $userfields
@ -450,6 +451,7 @@ class grade_report_grader extends grade_report {
AND ra.contextid $relatedctxsql
) rainner ON rainner.userid = u.id
AND u.deleted = 0
$this->userwheresql
$this->groupwheresql
ORDER BY $sort";
$studentsperpage = $this->get_students_per_page();
@ -489,7 +491,6 @@ class grade_report_grader extends grade_report {
}
}
}
return $this->users;
}
@ -504,6 +505,10 @@ class grade_report_grader extends grade_report {
return;
}
if (empty($this->users)) {
return;
}
// please note that we must fetch all grade_grades fields if we want to construct grade_grade object from it!
$params = array_merge(array('courseid'=>$this->courseid), $this->userselect_params);
$sql = "SELECT g.*
@ -513,7 +518,6 @@ class grade_report_grader extends grade_report {
$userids = array_keys($this->users);
if ($grades = $DB->get_records_sql($sql, $params)) {
foreach ($grades as $graderec) {
if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->get_items())) { // some items may not be present!!

View File

@ -132,6 +132,19 @@ abstract class grade_report {
*/
protected $groupwheresql_params = array();
//// USER VARIABLES (including SQL)
/**
* An SQL constraint to append to the queries used by this object to build the report.
* @var string $userwheresql
*/
protected $userwheresql;
/**
* The ordered params for $userwheresql
* @var array $userwheresql_params
*/
protected $userwheresql_params = array();
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
@ -268,11 +281,12 @@ abstract class grade_report {
/**
* Fetches and returns a count of all the users that will be shown on this page.
* @param boolean $groups include groups limit
* @param boolean $users include users limit - default false, used for searching purposes
* @return int Count of users
*/
public function get_numusers($groups=true) {
global $DB;
public function get_numusers($groups = true, $users = false) {
global $CFG, $DB;
$userwheresql = "";
$groupsql = "";
$groupwheresql = "";
@ -287,6 +301,11 @@ abstract class grade_report {
$params = array_merge($gradebookrolesparams, $enrolledparams, $relatedctxparams);
if ($users) {
$userwheresql = $this->userwheresql;
$params = array_merge($params, $this->userwheresql_params);
}
if ($groups) {
$groupsql = $this->groupsql;
$groupwheresql = $this->groupwheresql;
@ -302,6 +321,7 @@ abstract class grade_report {
$groupsql
WHERE ra.roleid $gradebookrolessql
AND u.deleted = 0
$userwheresql
$groupwheresql
AND ra.contextid $relatedctxsql";
return $DB->count_records_sql($countsql, $params);
@ -328,6 +348,20 @@ abstract class grade_report {
}
}
public function setup_users() {
global $SESSION;
$this->userwheresql = "";
$this->userwheresql_params = array();
if (isset($SESSION->graderreportsifirst) && !empty($SESSION->graderreportsifirst)) {
$this->userwheresql .= ' AND u.firstname ILIKE :firstname ';
$this->userwheresql_params['firstname'] = $SESSION->graderreportsifirst.'%';
}
if (isset($SESSION->graderreportsilast) && !empty($SESSION->graderreportsilast)) {
$this->userwheresql .= ' AND u.lastname ILIKE :lastname ';
$this->userwheresql_params['lastname'] = $SESSION->graderreportsilast.'%';
}
}
/**
* Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.
* @param string $direction