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:
Tim Hunt
2012-06-06 20:21:33 +01:00
parent 4db061680e
commit ee326d5e7d
3 changed files with 18 additions and 7 deletions
+1 -1
View File
@@ -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();
+1 -5
View File
@@ -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;
}
}
+16 -1
View File
@@ -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.