diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 69e313ace08..c666bef183e 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -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 .= '
' - . get_string("youranswer", "lesson").' : ' . $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").' :
'; + + $studentanswerarray = explode('
', $result->studentanswer); + $responsearr = explode('
', $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(''.get_string("response", "lesson"). + ':
'.$studentresponse); + } else { + $table->data[] = array(''); + } } - $result->feedback .= '
'; + $result->feedback .= html_writer::table($table).'
'; } } - return $result; } diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php index 38d314cf8f0..7f51e87b7a1 100644 --- a/mod/lesson/pagetypes/multichoice.php +++ b/mod/lesson/pagetypes/multichoice.php @@ -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 .= '
'.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('
', $studentanswerarray); $correctpageid = null; $wrongpageid = null;