]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8671 - better checking when creating short answer questions. Fix thanks to Joseph...
authortjhunt <tjhunt>
Tue, 27 Feb 2007 16:20:40 +0000 (16:20 +0000)
committertjhunt <tjhunt>
Tue, 27 Feb 2007 16:20:40 +0000 (16:20 +0000)
question/type/shortanswer/edit_shortanswer_form.php

index 1ba15cc773feeb83f36f2bf7c63c0566ea5a377e..54b9e6f9dffbc41aaca0a1c96a819478eca714a9 100644 (file)
@@ -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() {