mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-37475 core_grade:fixed the handling of show totals
This commit is contained in:
parent
4ce97aed0d
commit
5df9bc3998
5 changed files with 27 additions and 12 deletions
|
@ -358,7 +358,12 @@ abstract class grade_report {
|
||||||
// If we're dealing with multiple courses we need to know when we've moved on to a new course.
|
// If we're dealing with multiple courses we need to know when we've moved on to a new course.
|
||||||
static $previous_courseid = null;
|
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;
|
return $finalgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +401,7 @@ abstract class grade_report {
|
||||||
|
|
||||||
//if the item definitely depends on a hidden item
|
//if the item definitely depends on a hidden item
|
||||||
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
|
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
|
||||||
if( !$this->showtotalsifcontainhidden ) {
|
if( !$this->showtotalsifcontainhidden[$courseid] ) {
|
||||||
//hide the grade
|
//hide the grade
|
||||||
$finalgrade = null;
|
$finalgrade = null;
|
||||||
}
|
}
|
||||||
|
@ -406,7 +411,7 @@ abstract class grade_report {
|
||||||
}
|
}
|
||||||
} else if (!empty($hiding_affected['unknown'][$course_item->id])) {
|
} else if (!empty($hiding_affected['unknown'][$course_item->id])) {
|
||||||
//not sure whether or not this item depends on a hidden item
|
//not sure whether or not this item depends on a hidden item
|
||||||
if( !$this->showtotalsifcontainhidden ) {
|
if( !$this->showtotalsifcontainhidden[$courseid] ) {
|
||||||
//hide the grade
|
//hide the grade
|
||||||
$finalgrade = null;
|
$finalgrade = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,6 @@ class grade_report_overview extends grade_report {
|
||||||
global $CFG, $COURSE, $DB;
|
global $CFG, $COURSE, $DB;
|
||||||
parent::__construct($COURSE->id, $gpr, $context);
|
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).
|
// Get the user (for full name).
|
||||||
$this->user = $DB->get_record('user', array('id' => $userid));
|
$this->user = $DB->get_record('user', array('id' => $userid));
|
||||||
|
|
||||||
|
@ -81,12 +79,17 @@ class grade_report_overview extends grade_report {
|
||||||
|
|
||||||
$this->showrank = array();
|
$this->showrank = array();
|
||||||
$this->showrank['any'] = false;
|
$this->showrank['any'] = false;
|
||||||
|
|
||||||
|
$this->showtotalsifcontainhidden = array();
|
||||||
|
|
||||||
if ($this->courses) {
|
if ($this->courses) {
|
||||||
foreach ($this->courses as $course) {
|
foreach ($this->courses as $course) {
|
||||||
$this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
|
$this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
|
||||||
if ($this->showrank[$course->id]) {
|
if ($this->showrank[$course->id]) {
|
||||||
$this->showrank['any'] = true;
|
$this->showrank['any'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
grade/report/upgrade.txt
Normal file
7
grade/report/upgrade.txt
Normal file
|
@ -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".
|
|
@ -165,7 +165,7 @@ class grade_report_user extends grade_report {
|
||||||
$this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
|
$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->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->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->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));
|
$this->showrange = grade_get_setting($this->courseid, 'report_user_showrange', !empty($CFG->grade_report_user_showrange));
|
||||||
|
|
|
@ -120,15 +120,15 @@ class gradereportlib_testcase extends advanced_testcase {
|
||||||
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
|
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
|
||||||
|
|
||||||
// Should return the supplied student total grade regardless of hiding.
|
// 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));
|
$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.
|
// 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));
|
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
|
||||||
|
|
||||||
// Should return the course total minus the hidden database activity grade.
|
// 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));
|
$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.
|
// Note: we cannot simply hide modules and call $report->blank_hidden_total() again.
|
||||||
|
@ -182,16 +182,16 @@ class gradereportlib_testcase extends advanced_testcase {
|
||||||
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
|
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
|
||||||
|
|
||||||
// Should return the supplied student total grade regardless of hiding.
|
// 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));
|
$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.
|
// 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));
|
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
|
||||||
|
|
||||||
// Should return the course total minus the hidden activity grades.
|
// Should return the course total minus the hidden activity grades.
|
||||||
// They are both hidden so should return null.
|
// 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));
|
$this->assertEquals(null, $report->blank_hidden_total($course->id, $coursegradeitem, $datagrade + $forumgrade));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue