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:
@@ -55,7 +55,7 @@ echo $OUTPUT->heading(format_string($attemptobj->get_question_name($slot)));
|
||||
|
||||
// Process any data that was submitted.
|
||||
if (data_submitted() && confirm_sesskey()) {
|
||||
if (optional_param('submit', false, PARAM_BOOL)) {
|
||||
if (optional_param('submit', false, PARAM_BOOL) && question_behaviour::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$attemptobj->process_submitted_actions(time());
|
||||
$transaction->allow_commit();
|
||||
|
||||
@@ -461,11 +461,7 @@ class quiz_grading_report extends quiz_default_report {
|
||||
|
||||
foreach ($qubaids as $qubaid) {
|
||||
foreach ($slots as $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);
|
||||
if (!is_null($mark) && ($mark < $minfraction * $maxmark || $mark > $maxmark)) {
|
||||
if (!question_behaviour::is_manual_grade_in_range($qubaid, $slot)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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