]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed form error checking for cloze questions, see bug http://moodle.org/bugs/bug...
authorgustav_delius <gustav_delius>
Tue, 28 Dec 2004 09:12:40 +0000 (09:12 +0000)
committergustav_delius <gustav_delius>
Tue, 28 Dec 2004 09:12:40 +0000 (09:12 +0000)
lang/en/quiz.php
mod/quiz/questiontypes/multianswer/questiontype.php

index 335468bae7faaff858712fab54b1cefa436ddb06..5156c5a0b02206a1dcbd998c4c350d1d5e35e295 100644 (file)
@@ -167,6 +167,7 @@ $string['nodataset'] = 'nothing - it is not a wild card';
 $string['nominal'] = 'Nominal';
 $string['nomoreattempts'] = 'No more attempts are allowed';
 $string['nopossibledatasets'] = 'No possible datasets';
+$string['noquestionintext'] = 'The question text does not contain any embedded questions';
 $string['noquestions'] = 'No questions have been added yet';
 $string['noresponse'] = 'No Response';
 $string['noreview'] = 'You are not allowed to review this quiz';
index fb5a2650a2352806be6bc3db72f64f7c796e153f..4ca23f37eab553682585f0f5ac82639cf9e87a82 100644 (file)
@@ -63,7 +63,16 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
         if (!$oldmultianswers = get_records("quiz_multianswers", "question", $question->id, "id ASC")) {
             $oldmultianswers = array();
         }
-
+        
+        if (empty($question->name)) {
+            $result->notice = get_string("missingname", "quiz");
+            return $result;
+        }
+        if (!$question->answers) {
+            $result->notice = get_string('noquestionintext', 'quiz');
+            return $result;
+        }
+        
         // Insert all the new multi answers
         foreach ($question->answers as $dataanswer) {
             if ($oldmultianswer = array_shift($oldmultianswers)) {  // Existing answer, so reuse it
@@ -111,7 +120,9 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
 
         $question = quiz_qtype_multianswer_extract_question
                                      ($form->questiontext);
-        $question->id = $authorizedquestion->id;
+        if (isset($authorizedquestion->id)) {
+            $question->id = $authorizedquestion->id;
+        }
         $question->qtype = $authorizedquestion->qtype;
         $question->category = $authorizedquestion->category;
 
@@ -122,45 +133,40 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
             $question->image = $form->image;
         }
 
-        // Formcheck
-        $err = array();
-        if (empty($question->name)) {
-            $err["name"] = get_string("missingname", "quiz");
-        }
-        if (empty($question->questiontext)) {
-            $err["questiontext"] = get_string("missingquestiontext", "quiz");
+        if (!empty($question->id)) { // Question already exists
+            if (!update_record("quiz_questions", $question)) {
+                error("Could not update question!");
+            }
+        } else {         // Question is a new one
+            $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
+            if (!$question->id = insert_record("quiz_questions", $question)) {
+                error("Could not insert new question!");
+            }
         }
-        if ($err) { // Formcheck failed
-            notify(get_string("someerrorswerefound"));
 
-        } else {
+        // Now to save all the answers and type-specific options
+        
+        $form->id       = $question->id;
+        $form->qtype    = $question->qtype;
+        $form->category = $question->category;
+        
+        $result = $this->save_question_options($question);
 
-            if (!empty($question->id)) { // Question already exists
-                if (!update_record("quiz_questions", $question)) {
-                    error("Could not update question!");
-                }
-            } else {         // Question is a new one
-                $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
-                if (!$question->id = insert_record("quiz_questions", $question)) {
-                    error("Could not insert new question!");
-                }
-            }
-    
-            // Now to save all the answers and type-specific options
-            $result = $this->save_question_options($question);
+        if (!empty($result->error)) {
+            error($result->error);
+        }
 
-            if (!empty($result->error)) {
-                error($result->error);
-            }
+        if (!empty($result->notice)) {
+            notice($result->notice, "question.php?id=$question->id");
+        }
 
-            if (!empty($result->notice)) {
-                notice_yesno($result->notice, "question.php?id=$question->id", "edit.php");
-                print_footer($course);
-                exit;
-            }
-    
-            redirect("edit.php");
+        if (!empty($result->noticeyesno)) {
+            notice_yesno($result->noticeyesno, "question.php?id=$question->id", "edit.php");
+            print_footer($course);
+            exit;
         }
+        
+        redirect("edit.php");
     }
     
     function convert_to_response_answer_field($questionresponse) {