From: tjhunt Date: Tue, 27 Feb 2007 16:20:40 +0000 (+0000) Subject: MDL-8671 - better checking when creating short answer questions. Fix thanks to Joseph... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=846e7545253ac4f6e4e305993c28f70529e14b96;p=moodle.git MDL-8671 - better checking when creating short answer questions. Fix thanks to Joseph Rézeau. Merged from MOODLE_18_STABLE. --- diff --git a/question/type/shortanswer/edit_shortanswer_form.php b/question/type/shortanswer/edit_shortanswer_form.php index 1ba15cc773..54b9e6f9df 100644 --- a/question/type/shortanswer/edit_shortanswer_form.php +++ b/question/type/shortanswer/edit_shortanswer_form.php @@ -67,15 +67,25 @@ class question_edit_shortanswer_form extends question_edit_form { $errors = array(); $answers = $data['answer']; $answercount = 0; - foreach ($answers as $answer){ + $maxgrade = false; + foreach ($answers as $key => $answer){ $trimmedanswer = trim($answer); if (!empty($trimmedanswer)){ $answercount++; } + // Check grades + if ($answer != '') { + if ($data['fraction'][$key] == 1) { + $maxgrade = true; + } + } } if ($answercount==0){ $errors['answer[0]'] = get_string('notenoughanswers', 'quiz', 1); } + if ($maxgrade == false) { + $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); + } return $errors; } function qtype() {