Browse files

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.
  • Loading branch information...
1 parent fbbb4cc commit e78e39cdbb8b88f541625121a61e60cf21b4f069 @timhunt timhunt committed Jun 6, 2012
Showing with 18 additions and 7 deletions.
  1. +1 −1 mod/quiz/comment.php
  2. +1 −5 mod/quiz/report/grading/report.php
  3. +16 −1 question/behaviour/behaviourbase.php
View
2 mod/quiz/comment.php
@@ -55,7 +55,7 @@
// 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_all_actions(time());
$transaction->allow_commit();
View
6 mod/quiz/report/grading/report.php
@@ -455,11 +455,7 @@ protected function validate_submitted_marks() {
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;
}
}
View
17 question/behaviour/behaviourbase.php
@@ -458,7 +458,8 @@ public function process_comment(question_attempt_pending_step $pendingstep) {
$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);
}
@@ -469,6 +470,20 @@ public function process_comment(question_attempt_pending_step $pendingstep) {
}
/**
+ * 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.
* @param $commentformat the format of the comment, one of the FORMAT_... constants.

0 comments on commit e78e39c

Please sign in to comment.