MDL-53034 mod_quiz: New WS mod_quiz_get_quiz_feedback_for_grade

This commit is contained in:
Juan Leyva 2016-02-08 18:28:42 +01:00
parent 3e5c19a0ed
commit 48abca7996
4 changed files with 141 additions and 7 deletions

View file

@ -544,6 +544,27 @@ function quiz_rescale_grade($rawgrade, $quiz, $format = true) {
return $grade;
}
/**
* Get the feedback object for this grade on this quiz.
*
* @param float $grade a grade on this quiz.
* @param object $quiz the quiz settings.
* @return false|stdClass the record object or false if there is not feedback for the given grade
* @since Moodle 3.1
*/
function quiz_feedback_record_for_grade($grade, $quiz) {
global $DB;
// With CBM etc, it is possible to get -ve grades, which would then not match
// any feedback. Therefore, we replace -ve grades with 0.
$grade = max($grade, 0);
$feedback = $DB->get_record_select('quiz_feedback',
'quizid = ? AND mingrade <= ? AND ? < maxgrade', array($quiz->id, $grade, $grade));
return $feedback;
}
/**
* Get the feedback text that should be show to a student who
* got this grade on this quiz. The feedback is processed ready for diplay.
@ -554,18 +575,12 @@ function quiz_rescale_grade($rawgrade, $quiz, $format = true) {
* @return string the comment that corresponds to this grade (empty string if there is not one.
*/
function quiz_feedback_for_grade($grade, $quiz, $context) {
global $DB;
if (is_null($grade)) {
return '';
}
// With CBM etc, it is possible to get -ve grades, which would then not match
// any feedback. Therefore, we replace -ve grades with 0.
$grade = max($grade, 0);
$feedback = $DB->get_record_select('quiz_feedback',
'quizid = ? AND mingrade <= ? AND ? < maxgrade', array($quiz->id, $grade, $grade));
$feedback = quiz_feedback_record_for_grade($grade, $quiz);
if (empty($feedback->feedbacktext)) {
return '';