MDL-33548 quiz manual grading: check the grade is in range.
To do this nicely, I refactored some code out of the quiz manual grading report.
This commit is contained in:
@@ -458,7 +458,8 @@ abstract class question_behaviour {
|
||||
$fraction = null;
|
||||
} else if ($fraction > 1 || $fraction < $this->qa->get_min_fraction()) {
|
||||
throw new coding_exception('Score out of range when processing ' .
|
||||
'a manual grading action.', $pendingstep);
|
||||
'a manual grading action.', 'Question ' . $this->qa->get_question()->id .
|
||||
', slot ' . $this->qa->get_slot() . ', fraction ' . $fraction);
|
||||
}
|
||||
$pendingstep->set_fraction($fraction);
|
||||
}
|
||||
@@ -468,6 +469,20 @@ abstract class question_behaviour {
|
||||
return question_attempt::KEEP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the manual grade submitted for a particular question is in range.
|
||||
* @param int $qubaid the question_usage id.
|
||||
* @param int $slot the slot number within the usage.
|
||||
* @return bool whether the submitted data is in range.
|
||||
*/
|
||||
public static function is_manual_grade_in_range($qubaid, $slot) {
|
||||
$prefix = 'q' . $qubaid . ':' . $slot . '_';
|
||||
$mark = optional_param($prefix . '-mark', null, PARAM_NUMBER);
|
||||
$maxmark = optional_param($prefix . '-maxmark', null, PARAM_NUMBER);
|
||||
$minfraction = optional_param($prefix . ':minfraction', null, PARAM_NUMBER);
|
||||
return is_null($mark) || ($mark >= $minfraction * $maxmark && $mark <= $maxmark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $comment the comment text to format. If omitted,
|
||||
* $this->qa->get_manual_comment() is used.
|
||||
|
||||
Reference in New Issue
Block a user