Skip to content
Browse files

MDL-37475 core_grade:fixed the handling of show totals

  • Loading branch information...
1 parent b5e41da commit 4b280ca67972479b4b86dd8861bcbeb8c06e41f9 @andyjdavis andyjdavis committed with Sam Hemelryk Mar 5, 2013
View
11 grade/report/lib.php
@@ -358,7 +358,12 @@ protected function blank_hidden_total($courseid, $course_item, $finalgrade) {
// If we're dealing with multiple courses we need to know when we've moved on to a new course.
static $previous_courseid = null;
- if( $this->showtotalsifcontainhidden==GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN ) {
+ if (!is_array($this->showtotalsifcontainhidden)) {
+ debugging('showtotalsifcontainhidden should be an array', DEBUG_DEVELOPER);
+ $this->showtotalsifcontainhidden = array($courseid => $this->showtotalsifcontainhidden);
+ }
+
+ if ($this->showtotalsifcontainhidden[$courseid] == GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN) {
return $finalgrade;
}
@@ -396,7 +401,7 @@ protected function blank_hidden_total($courseid, $course_item, $finalgrade) {
//if the item definitely depends on a hidden item
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
- if( !$this->showtotalsifcontainhidden ) {
+ if( !$this->showtotalsifcontainhidden[$courseid] ) {
//hide the grade
$finalgrade = null;
}
@@ -406,7 +411,7 @@ protected function blank_hidden_total($courseid, $course_item, $finalgrade) {
}
} else if (!empty($hiding_affected['unknown'][$course_item->id])) {
//not sure whether or not this item depends on a hidden item
- if( !$this->showtotalsifcontainhidden ) {
+ if( !$this->showtotalsifcontainhidden[$courseid] ) {
//hide the grade
$finalgrade = null;
}
View
7 grade/report/overview/lib.php
@@ -71,8 +71,6 @@ public function __construct($userid, $gpr, $context) {
global $CFG, $COURSE, $DB;
parent::__construct($COURSE->id, $gpr, $context);
- $this->showtotalsifcontainhidden = grade_get_setting($this->courseid, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
-
// Get the user (for full name).
$this->user = $DB->get_record('user', array('id' => $userid));
@@ -81,12 +79,17 @@ public function __construct($userid, $gpr, $context) {
$this->showrank = array();
$this->showrank['any'] = false;
+
+ $this->showtotalsifcontainhidden = array();
+
if ($this->courses) {
foreach ($this->courses as $course) {
$this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
if ($this->showrank[$course->id]) {
$this->showrank['any'] = true;
}
+
+ $this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
}
}
View
7 grade/report/upgrade.txt
@@ -0,0 +1,7 @@
+This files describes API changes in /grade/report/*,
+information provided here is intended especially for developers.
+
+
+=== 2.3.5, 2.4.2 ===
+* class_grade_report::showtotalsifcontainhidden has been switched from a single integer value to an array.
+The array keys are course IDs while the array values are the value of the course setting "report_overview_showtotalsifcontainhidden".
View
2 grade/report/user/lib.php
@@ -165,7 +165,7 @@ public function __construct($courseid, $gpr, $context, $userid) {
$this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
$this->showpercentage = grade_get_setting($this->courseid, 'report_user_showpercentage', $CFG->grade_report_user_showpercentage);
$this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
- $this->showtotalsifcontainhidden = grade_get_setting($this->courseid, 'report_user_showtotalsifcontainhidden', $CFG->grade_report_user_showtotalsifcontainhidden);
+ $this->showtotalsifcontainhidden = array($this->courseid => grade_get_setting($this->courseid, 'report_user_showtotalsifcontainhidden', $CFG->grade_report_user_showtotalsifcontainhidden));
$this->showgrade = grade_get_setting($this->courseid, 'report_user_showgrade', !empty($CFG->grade_report_user_showgrade));
$this->showrange = grade_get_setting($this->courseid, 'report_user_showrange', !empty($CFG->grade_report_user_showrange));
View
12 grade/tests/reportlib_test.php
@@ -120,15 +120,15 @@ public function test_blank_hidden_total() {
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
// Should return the supplied student total grade regardless of hiding.
- $report->showtotalsifcontainhidden = GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals($datagrade + $forumgrade, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
// Should blank the student total as course grade depends on a hidden item.
- $report->showtotalsifcontainhidden = GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
// Should return the course total minus the hidden database activity grade.
- $report->showtotalsifcontainhidden = GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals($forumgrade, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
// Note: we cannot simply hide modules and call $report->blank_hidden_total() again.
@@ -182,16 +182,16 @@ public function test_blank_hidden_total() {
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
// Should return the supplied student total grade regardless of hiding.
- $report->showtotalsifcontainhidden = GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals($datagrade + $forumgrade, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
// Should blank the student total as course grade depends on a hidden item.
- $report->showtotalsifcontainhidden = GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
// Should return the course total minus the hidden activity grades.
// They are both hidden so should return null.
- $report->showtotalsifcontainhidden = GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN;
+ $report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN);
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
}
}

0 comments on commit 4b280ca

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