MDL-43042 lesson: Confusing feedback order in multiple answer questions
authorMihail Geshoski <mihail@moodle.com>
Fri, 5 Jan 2018 07:03:14 +0000 (15:03 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 5 Jan 2018 07:03:14 +0000 (15:03 +0800)
mod/lesson/locallib.php
mod/lesson/pagetypes/multichoice.php

index 69e313a..c666bef 100644 (file)
@@ -4119,23 +4119,38 @@ abstract class lesson_page extends lesson_base {
                 $options->context = $context;
 
                 $result->feedback .= $OUTPUT->box(format_text($this->get_contents(), $this->properties->contentsformat, $options),
-                        'generalbox boxaligncenter');
-                $studentanswer = format_text($result->studentanswer, $result->studentanswerformat,
-                        array('context' => $context, 'para' => true));
+                        'generalbox boxaligncenter p-y-1');
                 $result->feedback .= '<div class="correctanswer generalbox"><em>'
-                        . get_string("youranswer", "lesson").'</em> : ' . $studentanswer;
-                if (isset($result->responseformat)) {
-                    $result->response = file_rewrite_pluginfile_urls($result->response, 'pluginfile.php', $context->id,
-                            'mod_lesson', 'page_responses', $result->answerid);
-                    $result->feedback .= $OUTPUT->box(format_text($result->response, $result->responseformat, $options)
-                            , $class);
-                } else {
-                    $result->feedback .= $OUTPUT->box($result->response, $class);
+                        . get_string("youranswer", "lesson").'</em> : <div class="studentanswer m-t-2 m-b-2">';
+
+                $studentanswerarray = explode('<br />', $result->studentanswer);
+                $responsearr = explode('<br />', $result->response);
+                $studentanswerresponse = array_combine($studentanswerarray, $responsearr);
+                // Create a table containing the answers and responses.
+                $table = new html_table();
+                foreach ($studentanswerresponse as $answer => $response) {
+                    // Add a table row containing the answer.
+                    $studentanswer = format_text($answer, $result->studentanswerformat,
+                            array('context' => $context, 'para' => true));
+                    $table->data[] = array($studentanswer);
+                    // If the response exists, add a table row containing the response. If not, add en empty row.
+                    if (!empty(trim($response))) {
+                        if (isset($result->responseformat)) {
+                            $convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php',
+                                $context->id, 'mod_lesson', 'page_responses', $result->answerid);
+                            $studentresponse = format_text($convertstudentresponse, $result->responseformat, $options);
+                        } else {
+                            $studentresponse = $response;
+                        }
+                        $table->data[] = array('<em>'.get_string("response", "lesson").
+                            '</em>: <br/>'.$studentresponse);
+                    } else {
+                        $table->data[] = array('');
+                    }
                 }
-                $result->feedback .= '</div>';
+                $result->feedback .= html_writer::table($table).'</div></div>';
             }
         }
-
         return $result;
     }
 
index 38d314c..7f51e87 100644 (file)
@@ -169,13 +169,12 @@ class lesson_page_type_multichoice extends lesson_page {
             foreach ($answers as $answer) {
                 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);
-                        }
+                        $studentanswerarray[] = format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
+                        $responses[$answerid] = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
                     }
                 }
             }
+            $result->studentanswer = implode('<br />', $studentanswerarray);
             $correctpageid = null;
             $wrongpageid = null;