]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed some problems with matching
authormichaelpenne <michaelpenne>
Tue, 21 Sep 2004 22:11:00 +0000 (22:11 +0000)
committermichaelpenne <michaelpenne>
Tue, 21 Sep 2004 22:11:00 +0000 (22:11 +0000)
mod/lesson/lesson.php

index fcdac3f648ceafc958d99c61ac099f25f0f49b76..0cb3c30b31752969c10f8b46ada8cf2119c44f6b 100644 (file)
                 $ncorrect = 0;
                 $i = 0;
                 foreach ($answers as $answer) {
+                                       if ($i == 0 || $i == 1) {
+                                               // ignore first two answers, they are correct response
+                                               // and wrong response
+                                               $i++;
+                                               continue;
+                                       }
                     if ($answer->response == $response[$answer->id]) {
                         $ncorrect++;
                     }
                     }
                     $i++;
                 }
-                if ($ncorrect == count($answers)) {
+                if ($ncorrect == count($answers)-2) {  // dont count correct/wrong responses in the total.
                        $response = get_string("thatsthecorrectanswer", "lesson");
                                        foreach ($answers as $answer) {
                                                if ($answer->response == NULL && $answer->answer != NULL) {
                                error("Insert Page: answer record $i not inserted");
                        }
                } else {
+                       if ($form->qtype == LESSON_MATCHING) {
+                               // need to add two to offset correct response and wrong response
+                               $lesson->maxanswers = $lesson->maxanswers + 2;
+                       }
                        for ($i = 0; $i < $lesson->maxanswers; $i++) {
                                if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds <p><br />...
                                        $newanswer->lessonid = $lesson->id;
             }
         } else {
             // it's an "ordinary" page
+                       if ($form->qtype == LESSON_MATCHING) {
+                               // need to add two to offset correct response and wrong response
+                               $lesson->maxanswers = $lesson->maxanswers + 2;
+                       }
             for ($i = 0; $i < $lesson->maxanswers; $i++) {
                 // strip tags because the editor gives <p><br />...
                 // also save any answers where the editor is (going to be) used