Merge branch 'MDL-71492-master' of git://github.com/jleyva/moodle

This commit is contained in:
Jake Dallimore 2021-05-06 09:15:47 +08:00
commit 52af65ca60
3 changed files with 21 additions and 1 deletions

View file

@ -495,7 +495,8 @@ class mod_quiz_external extends external_api {
* @since Moodle 3.1 * @since Moodle 3.1
*/ */
public static function get_user_best_grade($quizid, $userid = 0) { public static function get_user_best_grade($quizid, $userid = 0) {
global $DB, $USER; global $DB, $USER, $CFG;
require_once($CFG->libdir . '/gradelib.php');
$warnings = array(); $warnings = array();
@ -545,6 +546,17 @@ class mod_quiz_external extends external_api {
$result['hasgrade'] = true; $result['hasgrade'] = true;
$result['grade'] = $grade; $result['grade'] = $grade;
} }
// Inform user of the grade to pass if non-zero.
$gradinginfo = grade_get_grades($course->id, 'mod', 'quiz', $quiz->id, $user->id);
if (!empty($gradinginfo->items)) {
$item = $gradinginfo->items[0];
if ($item && grade_floats_different($item->gradepass, 0)) {
$result['gradetopass'] = $item->gradepass;
}
}
$result['warnings'] = $warnings; $result['warnings'] = $warnings;
return $result; return $result;
} }
@ -560,6 +572,7 @@ class mod_quiz_external extends external_api {
array( array(
'hasgrade' => new external_value(PARAM_BOOL, 'Whether the user has a grade on the given quiz.'), 'hasgrade' => new external_value(PARAM_BOOL, 'Whether the user has a grade on the given quiz.'),
'grade' => new external_value(PARAM_FLOAT, 'The grade (only if the user has a grade).', VALUE_OPTIONAL), 'grade' => new external_value(PARAM_FLOAT, 'The grade (only if the user has a grade).', VALUE_OPTIONAL),
'gradetopass' => new external_value(PARAM_FLOAT, 'The grade to pass the quiz (only if set).', VALUE_OPTIONAL),
'warnings' => new external_warnings(), 'warnings' => new external_warnings(),
) )
); );

View file

@ -552,6 +552,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
// Now I have grades. // Now I have grades.
$this->assertTrue($result['hasgrade']); $this->assertTrue($result['hasgrade']);
$this->assertEquals(100.0, $result['grade']); $this->assertEquals(100.0, $result['grade']);
$this->assertEquals(80, $result['gradetopass']);
// We should not see other users grades. // We should not see other users grades.
$anotherstudent = self::getDataGenerator()->create_user(); $anotherstudent = self::getDataGenerator()->create_user();
@ -572,6 +573,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
$this->assertTrue($result['hasgrade']); $this->assertTrue($result['hasgrade']);
$this->assertEquals(100.0, $result['grade']); $this->assertEquals(100.0, $result['grade']);
$this->assertEquals(80, $result['gradetopass']);
// Invalid user. // Invalid user.
try { try {

View file

@ -1,5 +1,10 @@
This files describes API changes in the quiz code. This files describes API changes in the quiz code.
=== 3.11 ===
* External function mod_quiz_external::get_user_best_grade now returns and additional optional field:
- gradetopass: The grade to pass the quiz (if set)
=== 3.10.1 === === 3.10.1 ===
* External functions mod_quiz_external::get_attempt_data, mod_quiz_external::get_attempt_summary * External functions mod_quiz_external::get_attempt_data, mod_quiz_external::get_attempt_summary