MDL-55327 mod_lesson: Fix for copying essay and match.
authorAdrian Greeve <adrian@moodle.com>
Wed, 21 Sep 2016 10:04:08 +0000 (18:04 +0800)
committerAdrian Greeve <adrian@moodle.com>
Wed, 21 Sep 2016 10:04:08 +0000 (18:04 +0800)
Matching and essay questions would display errors when
being duplicated.

mod/lesson/locallib.php
mod/lesson/pagetypes/matching.php

index 80e2547..b49e3f6 100644 (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++;
index b784f8e..a4260f2 100644 (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