MDL-55327 mod_lesson: Fix for copying essay and match.

Matching and essay questions would display errors when
being duplicated.
This commit is contained in:
Adrian Greeve 2016-09-21 18:04:08 +08:00
parent 6cc077e90f
commit f4eef5fb25
2 changed files with 11 additions and 2 deletions

View File

@ -1721,10 +1721,10 @@ class lesson extends lesson_base {
$this->copy_page_files('page_contents', $pageid, $newlessonpage->id, $context->id);
$j = 0;
foreach ($newanswers as $answer) {
if (strpos($answer->answer, '@@PLUGINFILE@@') !== false) {
if (isset($answer->answer) && strpos($answer->answer, '@@PLUGINFILE@@') !== false) {
$this->copy_page_files('page_answers', $answerids[$j], $answer->id, $context->id);
}
if (strpos($answer->response, '@@PLUGINFILE@@') !== false) {
if (isset($answer->response) && !is_array($answer->response) && strpos($answer->response, '@@PLUGINFILE@@') !== false) {
$this->copy_page_files('page_responses', $answerids[$j], $answer->id, $context->id);
}
$j++;

View File

@ -118,6 +118,15 @@ class lesson_page_type_matching extends lesson_page {
$cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
$context = context_module::instance($cm->id);
// Check for duplicate response format.
$duplicateresponse = array();
if (is_array($properties->response_editor[0])) {
foreach ($properties->response_editor as $response) {
$duplicateresponse[] = $response['text'];
}
$properties->response_editor = $duplicateresponse;
}
$answers = array();
// need to add two to offset correct response and wrong response