Merge branch 'MDL-75381-401' of https://github.com/paulholden/moodle into MOODLE_401_STABLE

This commit is contained in:
Jun Pataleta 2022-12-06 19:24:34 +08:00
commit dd3b92545e
3 changed files with 45 additions and 3 deletions

View File

@ -1994,7 +1994,7 @@ class grade_report_grader extends grade_report {
*
* @return int The maximum number of students to display per page
*/
public function get_students_per_page() {
return $this->get_pref('studentsperpage');
public function get_students_per_page(): int {
return (int) $this->get_pref('studentsperpage');
}
}

View File

@ -33,7 +33,7 @@ if ($ADMIN->fulltree) {
/// Add settings for this module to the $settings object (it's already defined)
$settings->add(new admin_setting_configtext('grade_report_studentsperpage', get_string('studentsperpage', 'grades'),
get_string('studentsperpage_help', 'grades'), 100));
get_string('studentsperpage_help', 'grades'), 100, PARAM_INT));
$settings->add(new admin_setting_configcheckbox('grade_report_showonlyactiveenrol', get_string('showonlyactiveenrol', 'grades'),
get_string('showonlyactiveenrol_help', 'grades'), 1));

View File

@ -29,6 +29,7 @@ require_once($CFG->dirroot.'/grade/report/grader/lib.php');
* Tests grade_report_grader (the grader report)
*
* @package core_grades
* @covers \grade_report_grader
* @category test
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
@ -518,6 +519,47 @@ class report_graderlib_test extends \advanced_testcase {
$this->assertCount(3, $result);
}
/**
* Test loading report users when per page preferences are set
*/
public function test_load_users_paging_preference(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
// The report users will default to sorting by their lastname.
$user1 = $this->getDataGenerator()->create_and_enrol($course, 'student', ['lastname' => 'Apple']);
$user2 = $this->getDataGenerator()->create_and_enrol($course, 'student', ['lastname' => 'Banana']);
$user3 = $this->getDataGenerator()->create_and_enrol($course, 'student', ['lastname' => 'Carrot']);
// Set to empty string.
$report = $this->create_report($course);
$report->set_pref('studentsperpage', '');
$users = $report->load_users();
$this->assertEquals([$user1->id, $user2->id, $user3->id], array_column($users, 'id'));
// Set to valid value.
$report = $this->create_report($course);
$report->set_pref('studentsperpage', 2);
$users = $report->load_users();
$this->assertEquals([$user1->id, $user2->id], array_column($users, 'id'));
}
/**
* Test getting students per page report preference
*/
public function test_get_students_per_page(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$report = $this->create_report($course);
$report->set_pref('studentsperpage', 10);
$perpage = $report->get_students_per_page();
$this->assertSame(10, $perpage);
}
private function create_grade_category($course) {
static $cnt = 0;
$cnt++;