MDL-76588 gradereport_summary: Summary report hack

This is a hack since average is not correct for summary report
when we have suspended users. But since we don't want to change
display to user - it is set to match 4.1 behavior.
This commit is contained in:
Ilya Tregubov 2023-11-03 13:36:59 +08:00
parent 4cae211e4a
commit e37eb30a09
No known key found for this signature in database
GPG Key ID: 0F58186F748E55C1
4 changed files with 47 additions and 27 deletions

View File

@ -93,7 +93,8 @@ class grade_items extends base {
);
$this->report = new grade_report_summary($this->course->id, $gpr, $context);
$this->ungradedcounts = $this->report->ungraded_counts();
$showonlyactiveenrol = $this->report->show_only_active();
$this->ungradedcounts = $this->report->ungraded_counts(false, false, $showonlyactiveenrol);
$columns = $this->get_all_columns();
foreach ($columns as $column) {

View File

@ -74,4 +74,17 @@ class grade_report_summary extends grade_report {
public function process_data($data) {
}
/**
* To check if we only need to include active enrolments.
*
* @return bool
*/
public function show_only_active(): bool {
// Limit to users with an active enrolment.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
return $showonlyactiveenrol ||
!has_capability('moodle/course:viewsuspendedusers', $this->context);
}
}

View File

@ -61,7 +61,12 @@ Feature: Average grades are displayed in the gradebook
| -1- | -2- | -3- |
| Overall average | 26.67 | 26.67 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "26.67" in the "Manual item 1" "table_row"
# Average is (10 + 20 + 30)/3 = 30.00 for manual since
# 1. Hidden items are NOT included on grader report.
# 2. There is a bug when we have suspended users in the course so here Student 2 is included.
# So the average is not write when preference is either not set or set to 0.
# Possibly this should be changed later to match grader report.
And I should see "30.00" in the "Manual item 1" "table_row"
And I am on the "Course 1" "grades > Grader report > View" page logged in as "teacher2"
And the following "user preferences" exist:
@ -72,7 +77,8 @@ Feature: Average grades are displayed in the gradebook
| -1- | -2- | -3- |
| Overall average | 26.67 | 26.67 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "26.67" in the "Manual item 1" "table_row"
# Average is (10 + 30)/2 = 20.00 for manual (when preference is set to 1 set average is correct).
And I should see "20.00" in the "Manual item 1" "table_row"
And the following "user preferences" exist:
| user | preference | value |
| teacher2 | grade_report_showonlyactiveenrol | 0 |
@ -81,7 +87,8 @@ Feature: Average grades are displayed in the gradebook
| -1- | -2- | -3- |
| Overall average | 25.00 | 25.00 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "25.00" in the "Manual item 1" "table_row"
# Average is (10 + 30)/2 = 20.00 for manual (when preference is set to 0 set average is NOT correct).
And I should see "20.00" in the "Manual item 1" "table_row"
# Check the user grade table
When I am on the "Course 1" "grades > user > View" page logged in as "student1"
@ -100,7 +107,7 @@ Feature: Average grades are displayed in the gradebook
| -1- | -2- | -3- |
| Overall average | 25.00 | 25.00 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "25.00" in the "Manual item 1" "table_row"
And I should see "20.00" in the "Manual item 1" "table_row"
And the following "user preferences" exist:
| user | preference | value |
| teacher2 | grade_report_showonlyactiveenrol | 1 |
@ -109,14 +116,14 @@ Feature: Average grades are displayed in the gradebook
| -1- | -2- | -3- |
| Overall average | 26.67 | 26.67 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "26.67" in the "Manual item 1" "table_row"
And I should see "20.00" in the "Manual item 1" "table_row"
And I am on the "Course 1" "grades > Grader report > View" page logged in as "teacher1"
And the following should exist in the "user-grades" table:
| -1- | -2- | -3- |
| Overall average | 25.00 | 25.00 |
And I am on the "Course 1" "grades > Grade summary > View" page
And I should see "25.00" in the "Manual item 1" "table_row"
And I should see "20.00" in the "Manual item 1" "table_row"
And I am on the "Course 1" "grades > user > View" page logged in as "student1"
And the following should exist in the "user-grade" table:

View File

@ -25,11 +25,10 @@
namespace core_grades;
use assign;
use block_globalsearch\globalsearch_test;
use cm_info;
use grade_item;
use grade_plugin_return;
use grade_report_summary;
use grade_report_grader;
defined('MOODLE_INTERNAL') || die();
@ -291,7 +290,7 @@ class lib_test extends \advanced_testcase {
$gpr1 = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course1,
]
);
@ -299,13 +298,13 @@ class lib_test extends \advanced_testcase {
$gpr2 = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course2,
]
);
$report1 = new grade_report_summary($course1->id, $gpr1, $context1);
$report2 = new grade_report_summary($course2->id, $gpr2, $context2);
$report1 = new grade_report_grader($course1->id, $gpr1, $context1);
$report2 = new grade_report_grader($course2->id, $gpr2, $context2);
$ungradedcounts = [];
$ungradedcounts[$course1->id] = $report1->ungraded_counts(false);
@ -420,12 +419,12 @@ class lib_test extends \advanced_testcase {
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course,
]
);
$report = new grade_report_summary($course->id, $gpr, $context);
$report = new grade_report_grader($course->id, $gpr, $context);
$ungradedcounts = $report->ungraded_counts(false, $hidden);
@ -541,7 +540,7 @@ class lib_test extends \advanced_testcase {
$gpr1 = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course,
'groupid' => $group1->id,
]
@ -550,14 +549,14 @@ class lib_test extends \advanced_testcase {
$gpr2 = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course,
'groupid' => $group2->id,
]
);
$report1 = new grade_report_summary($course->id, $gpr1, $context);
$report2 = new grade_report_summary($course->id, $gpr2, $context);
$report1 = new grade_report_grader($course->id, $gpr1, $context);
$report2 = new grade_report_grader($course->id, $gpr2, $context);
$ungradedcounts = [];
$ungradedcounts[$group1->id] = $report1->ungraded_counts(true);
@ -692,12 +691,12 @@ class lib_test extends \advanced_testcase {
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course,
]
);
$report = new grade_report_summary($course->id, $gpr, $context);
$report = new grade_report_grader($course->id, $gpr, $context);
$showonlyactiveenrol = $report->show_only_active();
$ungradedcounts = $report->ungraded_counts(false, false, $showonlyactiveenrol);
@ -853,12 +852,12 @@ class lib_test extends \advanced_testcase {
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course,
]
);
$report = new grade_report_summary($course->id, $gpr, $context);
$report = new grade_report_grader($course->id, $gpr, $context);
$ungradedcounts = $report->ungraded_counts(false);
$ungradedcounts['report']['meanselection'] = $meanselection;
@ -939,24 +938,24 @@ class lib_test extends \advanced_testcase {
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course1,
]
);
$report1 = new grade_report_summary($course1->id, $gpr, $context);
$report1 = new grade_report_grader($course1->id, $gpr, $context);
$context = \context_course::instance($course2->id);
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'plugin' => 'grader',
'course' => $course2,
]
);
$report2 = new grade_report_summary($course2->id, $gpr, $context);
$report2 = new grade_report_grader($course2->id, $gpr, $context);
$gradeitems1 = $report1->item_types();
$gradeitems2 = $report2->item_types();