Skip to content
Browse files

gradebook MDL-25769 fixed up the grader report

  • Loading branch information...
1 parent b61e4f4 commit 387815db61b71087a449961518fcde1ef6b33710 @andyjdavis andyjdavis committed with Sam Hemelryk Jan 6, 2011
Showing with 21 additions and 7 deletions.
  1. +11 −5 grade/report/grader/lib.php
  2. +10 −2 grade/report/lib.php
View
16 grade/report/grader/lib.php
@@ -1279,20 +1279,25 @@ public function get_right_avg_row($rows=array(), $grouponly=false) {
$totalcount = $this->get_numusers($grouponly);
- list($usql, $rolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
+ //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
+ list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
if ($showaverages) {
- $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams);
+ $params = array_merge(array('courseid'=>$this->courseid), $gradebookrolesparams, $enrolledparams, $groupwheresqlparams);
// find sums of all grade items in course
$SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum
FROM {grade_items} gi
JOIN {grade_grades} g ON g.itemid = gi.id
JOIN {user} u ON u.id = g.userid
+ JOIN ($enrolledsql) je ON je.id = u.id
JOIN {role_assignments} ra ON ra.userid = u.id
$groupsql
WHERE gi.courseid = :courseid
- AND ra.roleid $usql
+ AND ra.roleid $gradebookrolessql
AND ra.contextid ".get_related_contexts_string($this->context)."
AND g.finalgrade IS NOT NULL
$groupwheresql
@@ -1306,15 +1311,16 @@ public function get_right_avg_row($rows=array(), $grouponly=false) {
// MDL-10875 Empty grades must be evaluated as grademin, NOT always 0
// This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
- $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams);
+ $params = array_merge(array('courseid'=>$this->courseid), $params);
$SQL = "SELECT gi.id, COUNT(u.id) AS count
FROM {grade_items} gi
CROSS JOIN {user} u
+ JOIN ($enrolledsql) je ON je.id = u.id
JOIN {role_assignments} ra ON ra.userid = u.id
LEFT OUTER JOIN {grade_grades} g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
$groupsql
WHERE gi.courseid = :courseid
- AND ra.roleid $usql
+ AND ra.roleid $gradebookrolessql
AND ra.contextid ".get_related_contexts_string($this->context)."
AND g.id IS NULL
$groupwheresql
View
12 grade/report/lib.php 100755 → 100644
@@ -274,7 +274,14 @@ public function get_numusers($groups=true) {
$groupsql = "";
$groupwheresql = "";
- list($usql, $params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
+
+ //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
+ list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
+
+ $params = array_merge($gradebookrolesparams, $enrolledparams);
if ($groups) {
$groupsql = $this->groupsql;
@@ -284,9 +291,10 @@ public function get_numusers($groups=true) {
$countsql = "SELECT COUNT(DISTINCT u.id)
FROM {user} u
+ JOIN ($enrolledsql) je ON je.id = u.id
JOIN {role_assignments} ra ON u.id = ra.userid
$groupsql
- WHERE ra.roleid $usql AND u.deleted = 0
+ WHERE ra.roleid $gradebookrolessql AND u.deleted = 0
$groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context);
return $DB->count_records_sql($countsql, $params);

0 comments on commit 387815d

Please sign in to comment.
Something went wrong with that request. Please try again.