Permalink
Browse files

MDL-32888 Grader report: added user search

  • Loading branch information...
Melissa Aitkin
Melissa Aitkin committed Jun 21, 2013
1 parent f8eff10 commit 8e4bf6cca631a308043eb87b71655dbb887b12b7
Showing with 111 additions and 14 deletions.
  1. +62 −3 grade/report/grader/index.php
  2. +12 −8 grade/report/grader/lib.php
  3. +37 −3 grade/report/lib.php
@@ -39,6 +39,17 @@
$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 @@
//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 @@
// 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) {
@@ -145,7 +145,7 @@ public function __construct($courseid, $gpr, $context, $page=null, $sortitemid=n
$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 @@ public function __construct($courseid, $gpr, $context, $page=null, $sortitemid=n
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 @@ public function process_data($data) {
// always initialize all arrays
$queue = array();
+
$this->load_users();
$this->load_final_grades();
@@ -397,8 +398,9 @@ public function load_users() {
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 @@ public function load_users() {
// 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 @@ public function load_users() {
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 @@ public function load_users() {
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 @@ public function load_users() {
}
}
}
-
return $this->users;
}
@@ -504,6 +505,10 @@ public function load_final_grades() {
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 @@ public function load_final_grades() {
$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
@@ -132,6 +132,19 @@
*/
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 @@ public function get_lang_string($strcode, $section=null) {
/**
* 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 @@ public function get_numusers($groups=true) {
$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 @@ public function get_numusers($groups=true) {
$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 @@ protected function setup_groups() {
}
}
+ 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

0 comments on commit 8e4bf6c

Please sign in to comment.