MDL-31266 Lesson module: Improve feedback so that the responses are concatenated...
authorRossiani Wijaya <rwijaya@moodle.com>
Tue, 13 Mar 2012 06:54:39 +0000 (14:54 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 20 Mar 2012 13:56:18 +0000 (21:56 +0800)
mod/lesson/pagetypes/multichoice.php

index 7ab9d2c..f930756 100644 (file)
@@ -145,8 +145,7 @@ class lesson_page_type_multichoice extends lesson_page {
             $answers = $this->get_used_answers();
             $ncorrect = 0;
             $nhits = 0;
-            $correctresponse = '';
-            $wrongresponse = '';
+            $responses = array();
             $correctanswerid = 0;
             $wronganswerid = 0;
             // store student's answers for displaying on feedback page
@@ -155,6 +154,9 @@ class lesson_page_type_multichoice extends lesson_page {
                 foreach ($studentanswers as $answerid) {
                     if ($answerid == $answer->id) {
                         $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
+                        if (trim(strip_tags($answer->response))) {
+                            $responses[$answerid] = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
+                        }
                     }
                 }
             }
@@ -182,10 +184,6 @@ class lesson_page_type_multichoice extends lesson_page {
                         if ($correctanswerid == 0) {
                             $correctanswerid = $answer->id;
                         }
-                        // ...also save any response from the correct answers...
-                        if (trim(strip_tags($answer->response))) {
-                            $correctresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
-                        }
                     } else {
                         // save the first jumpto page id, may be needed!...
                         if (!isset($wrongpageid)) {
@@ -196,10 +194,6 @@ class lesson_page_type_multichoice extends lesson_page {
                         if ($wronganswerid == 0) {
                             $wronganswerid = $answer->id;
                         }
-                        // ...and from the incorrect ones, don't know which to use at this stage
-                        if (trim(strip_tags($answer->response))) {
-                            $wrongresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
-                        }
                     }
                 }
             } else {
@@ -220,10 +214,6 @@ class lesson_page_type_multichoice extends lesson_page {
                         if ($correctanswerid == 0) {
                             $correctanswerid = $answer->id;
                         }
-                        // ...also save any response from the correct answers...
-                        if (trim(strip_tags($answer->response))) {
-                            $correctresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
-                        }
                     } else {
                         // save the first jumpto page id, may be needed!...
                         if (!isset($wrongpageid)) {
@@ -234,20 +224,16 @@ class lesson_page_type_multichoice extends lesson_page {
                         if ($wronganswerid == 0) {
                             $wronganswerid = $answer->id;
                         }
-                        // ...and from the incorrect ones, don't know which to use at this stage
-                        if (trim(strip_tags($answer->response))) {
-                            $wrongresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
-                        }
                     }
                 }
             }
             if ((count($studentanswers) == $ncorrect) and ($nhits == $ncorrect)) {
                 $result->correctanswer = true;
-                $result->response  = $correctresponse;
+                $result->response  = implode('<br />', $responses);
                 $result->newpageid = $correctpageid;
                 $result->answerid  = $correctanswerid;
             } else {
-                $result->response  = $wrongresponse;
+                $result->response  = implode('<br />', $responses);
                 $result->newpageid = $wrongpageid;
                 $result->answerid  = $wronganswerid;
             }