This seemed to fix things for me, so it shows some of the areas needing fixing. I know that edit_multichoice_form.php is simpler in validation - I would expect them to be roughly similar, but I haven't looked seriously to compare ... nholtz@holtz3:/files/www/data/moodle21/question/type/calculatedmulti$ git diff edit_calculatedmulti_form.php | cat diff --git a/question/type/calculatedmulti/edit_calculatedmulti_form.php b/question/type/calculatedmulti/edit_calculatedmulti_form.php index eec57e3..9b32b78 100644 --- a/question/type/calculatedmulti/edit_calculatedmulti_form.php +++ b/question/type/calculatedmulti/edit_calculatedmulti_form.php @@ -261,6 +261,8 @@ class qtype_calculatedmulti_edit_form extends question_edit_form { } } if ($data['multichoice'] == 1) { + $totalfraction = 0; + $maxfraction = 0; foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if ($trimmedanswer != '' || $answercount == 0) { @@ -303,8 +305,6 @@ class qtype_calculatedmulti_edit_form extends question_edit_form { $answercount++; } //check grades - $totalfraction = 0; - $maxfraction = 0; if ($answer != '') { if ($data['fraction'][$key] > 0) { $totalfraction += $data['fraction'][$key]; @@ -324,27 +324,25 @@ class qtype_calculatedmulti_edit_form extends question_edit_form { /// Perform sanity checks on fractional grades if ($data['single']) { - if ($maxfraction > 0.999) { + if ($maxfraction != 1) { /// Won't this get caught by totalfraction test, below? No - this effectively will require one right answer for single choice $maxfraction = $maxfraction * 100; $errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction); } - } else { - $totalfraction = round($totalfraction, 2); - if ($totalfraction != 1) { - $totalfraction = $totalfraction * 100; - $errors['fraction[0]'] = - get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction); - } + } + $totalfraction = round($totalfraction, 2); + if ($totalfraction != 1) { + $totalfraction = $totalfraction * 100; + $errors['fraction[0]'] = + get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction); } if ($answercount == 0) { $errors['answer[0]'] = get_string('atleastoneanswer', 'qtype_calculated'); } - if ($maxgrade == false) { - $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); - } - +/// if ($maxgrade == false) { +/// $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); +/// } } return $errors; }