mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-71492-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
52af65ca60
3 changed files with 21 additions and 1 deletions
|
@ -495,7 +495,8 @@ class mod_quiz_external extends external_api {
|
|||
* @since Moodle 3.1
|
||||
*/
|
||||
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();
|
||||
|
||||
|
@ -545,6 +546,17 @@ class mod_quiz_external extends external_api {
|
|||
$result['hasgrade'] = true;
|
||||
$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;
|
||||
return $result;
|
||||
}
|
||||
|
@ -560,6 +572,7 @@ class mod_quiz_external extends external_api {
|
|||
array(
|
||||
'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),
|
||||
'gradetopass' => new external_value(PARAM_FLOAT, 'The grade to pass the quiz (only if set).', VALUE_OPTIONAL),
|
||||
'warnings' => new external_warnings(),
|
||||
)
|
||||
);
|
||||
|
|
|
@ -552,6 +552,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
|
|||
// Now I have grades.
|
||||
$this->assertTrue($result['hasgrade']);
|
||||
$this->assertEquals(100.0, $result['grade']);
|
||||
$this->assertEquals(80, $result['gradetopass']);
|
||||
|
||||
// We should not see other users grades.
|
||||
$anotherstudent = self::getDataGenerator()->create_user();
|
||||
|
@ -572,6 +573,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
|
|||
|
||||
$this->assertTrue($result['hasgrade']);
|
||||
$this->assertEquals(100.0, $result['grade']);
|
||||
$this->assertEquals(80, $result['gradetopass']);
|
||||
|
||||
// Invalid user.
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
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 ===
|
||||
|
||||
* External functions mod_quiz_external::get_attempt_data, mod_quiz_external::get_attempt_summary
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue