From c288300c3c642e43c4b997eeb29ba1efa5b711a5 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Tue, 24 Feb 2015 12:50:30 -0800 Subject: [PATCH] MDL-48572 gradereport_grader: Average wrong with suspended users --- grade/report/grader/lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index daaeddcd47d53..f6f1821426f9b 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -1345,7 +1345,7 @@ public function get_right_range_row($rows=array()) { * @return array Array of rows for the right part of the report */ public function get_right_avg_row($rows=array(), $grouponly=false) { - global $USER, $DB, $OUTPUT; + global $USER, $DB, $OUTPUT, $CFG; if (!$this->canviewhidden) { // Totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered @@ -1377,7 +1377,11 @@ public function get_right_avg_row($rows=array(), $grouponly=false) { 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); + $coursecontext = $this->context->get_course_context(true); + $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); + $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); + $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext); + list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context, '', 0, $showonlyactiveenrol); // We want to query both the current context and parent contexts. list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx');