diff --git a/mod/lesson/backup/moodle2/backup_lesson_stepslib.php b/mod/lesson/backup/moodle2/backup_lesson_stepslib.php index 388d55d9a4675..11b5f0ace2164 100644 --- a/mod/lesson/backup/moodle2/backup_lesson_stepslib.php +++ b/mod/lesson/backup/moodle2/backup_lesson_stepslib.php @@ -197,6 +197,7 @@ protected function define_structure() { $answer->annotate_files('mod_lesson', 'page_answers', 'id'); $answer->annotate_files('mod_lesson', 'page_responses', 'id'); $attempt->annotate_files('mod_lesson', 'essay_responses', 'id'); + $attempt->annotate_files('mod_lesson', 'essay_answers', 'id'); // Prepare and return the structure we have just created for the lesson module. return $this->prepare_activity_structure($lesson); diff --git a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php index d4217296a147f..5cefa64e6d814 100644 --- a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php +++ b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php @@ -253,6 +253,7 @@ protected function after_execute() { $this->add_related_files('mod_lesson', 'page_answers', 'lesson_answer'); $this->add_related_files('mod_lesson', 'page_responses', 'lesson_answer'); $this->add_related_files('mod_lesson', 'essay_responses', 'lesson_attempt'); + $this->add_related_files('mod_lesson', 'essay_answers', 'lesson_attempt'); // Remap all the restored prevpageid and nextpageid now that we have all the pages and their mappings $rs = $DB->get_recordset('lesson_pages', array('lessonid' => $this->task->get_activityid()), diff --git a/mod/lesson/classes/privacy/provider.php b/mod/lesson/classes/privacy/provider.php index f525be2527340..61efd9db2450e 100644 --- a/mod/lesson/classes/privacy/provider.php +++ b/mod/lesson/classes/privacy/provider.php @@ -445,6 +445,7 @@ public static function delete_data_for_all_users_in_context(context $context) { $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses'); + $fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers'); } /** @@ -485,6 +486,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $cmid = $lessonidstocmids[$record->lessonid]; $context = context_module::instance($cmid); $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $record->id); + $fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers', $record->id); } $recordset->close(); @@ -522,6 +524,7 @@ public static function delete_data_for_users(approved_userlist $userlist) { $recordset = $DB->get_recordset_select('lesson_attempts', $sql, $params, '', 'id, lessonid'); foreach ($recordset as $record) { $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $record->id); + $fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers', $record->id); } $recordset->close(); @@ -616,7 +619,21 @@ protected static function transform_attempt(stdClass $data, context_module $cont if ($data->page_qtype == LESSON_PAGE_ESSAY) { // Essay questions serialise data in the answer field. $info = \lesson_page_type_essay::extract_useranswer($answer); - $answer = format_text($info->answer, $info->answerformat, $options); + $answerfilespath = [get_string('privacy:path:essayanswers', 'mod_lesson'), $data->attempt_id]; + $answer = format_text( + writer::with_context($context)->rewrite_pluginfile_urls( + $answerfilespath, + 'mod_lesson', + 'essay_answers', + $data->attempt_id, + $info->answer + ), + $info->answerformat, + $options + ); + writer::with_context($context)->export_area_files($answerfilespath, 'mod_lesson', + 'essay_answers', $data->page_id); + if ($info->response !== null) { // We export the files in a subfolder to avoid conflicting files, and tell the user // where those files were exported. That is because we are not using a subfolder for @@ -636,6 +653,7 @@ protected static function transform_attempt(stdClass $data, context_module $cont ); writer::with_context($context)->export_area_files($responsefilespath, 'mod_lesson', 'essay_responses', $data->page_id); + } } else if ($data->page_qtype == LESSON_PAGE_MULTICHOICE && $data->page_qoption) { diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index 24e5094887bc3..368106fbc77ee 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -248,7 +248,7 @@ $currentpage = $lesson->load_page($attempt->pageid); $a->question = format_text($currentpage->contents, $currentpage->contentsformat, $formattextdefoptions); $answer = file_rewrite_pluginfile_urls($essayinfo->answer, 'pluginfile.php', $context->id, - 'mod_lesson', 'essay_responses', $attempt->id); + 'mod_lesson', 'essay_answers', $attempt->id); $a->response = format_text($answer, $essayinfo->answerformat, array('context' => $context, 'para' => true)); $a->comment = $essayinfo->response; @@ -457,7 +457,7 @@ // Expects the following to be set: $attemptid, $answer, $user, $page, $attempt $essayinfo = lesson_page_type_essay::extract_useranswer($attempt->useranswer); $answer = file_rewrite_pluginfile_urls($essayinfo->answer, 'pluginfile.php', $context->id, - 'mod_lesson', 'essay_responses', $attempt->id); + 'mod_lesson', 'essay_answers', $attempt->id); $currentpage = $lesson->load_page($attempt->pageid); $mform = new essay_grading_form(null, array('scoreoptions'=>$scoreoptions, 'user'=>$user)); diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index b8b16abd3ddf4..948c96356e0dc 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -474,6 +474,7 @@ $string['privacy:metadata:overrides'] = 'A record of overrides per lesson'; $string['privacy:metadata:userpref:lessonview'] = 'The preferred display mode when editing lessons'; $string['privacy:path:essayresponses'] = 'Essay responses'; +$string['privacy:path:essayanswers'] = 'Essay answers'; $string['privacy:path:pages'] = 'Pages'; $string['processerror'] = 'Error occurred during processing!'; $string['progressbar'] = 'Progress bar'; diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 9f5d1bc512a7b..2adefdb6c20b3 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -1088,6 +1088,7 @@ function lesson_reset_userdata($data) { } $context = context_module::instance($cm->id); $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses'); + $fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers'); } } @@ -1366,7 +1367,7 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl } $fullpath = "/$context->id/mod_lesson/$filearea/$itemid/".implode('/', $args); - } else if ($filearea === 'essay_responses') { + } else if ($filearea === 'essay_responses' || $filearea === 'essay_answers') { $itemid = (int)array_shift($args); if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $itemid))) { return false; @@ -1408,6 +1409,7 @@ function lesson_get_file_areas() { $areas['page_answers'] = get_string('pageanswers', 'mod_lesson'); $areas['page_responses'] = get_string('pageresponses', 'mod_lesson'); $areas['essay_responses'] = get_string('essayresponses', 'mod_lesson'); + $areas['essay_answers'] = get_string('essayresponses', 'mod_lesson'); return $areas; } diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index bd73d2e6b700c..f6f7f97be90b4 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3923,6 +3923,7 @@ final public function delete() { if ($attempts = $DB->get_records('lesson_attempts', array("pageid" => $this->properties->id))) { foreach ($attempts as $attempt) { $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $attempt->id); + $fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers', $attempt->id); } } diff --git a/mod/lesson/pagetypes/essay.php b/mod/lesson/pagetypes/essay.php index ff4bdb91bcb8a..ac2ebc283bdae 100644 --- a/mod/lesson/pagetypes/essay.php +++ b/mod/lesson/pagetypes/essay.php @@ -91,7 +91,7 @@ public function display($renderer, $attempt) { } $data = file_prepare_standard_editor($data, 'answer', $options['editoroptions'], - $context, 'mod_lesson', 'essay_responses'); + $context, 'mod_lesson', 'essay_answers'); $mform->set_data($data); // Trigger an event question viewed. @@ -147,7 +147,7 @@ public function on_after_write_attempt($attempt, $result) { ); $formdata = file_postupdate_standard_editor($formdata, 'answer', $editoroptions, - $editoroptions['context'], 'mod_lesson', 'essay_responses', $attempt->id); + $editoroptions['context'], 'mod_lesson', 'essay_answers', $attempt->id); // Update the student response to have the modified link. $useranswer = unserialize($attempt->useranswer); @@ -174,7 +174,7 @@ public function on_after_write_attempt($attempt, $result) { */ public function format_answer($answer, $context, $answerformat, $options = []) { $answer = file_rewrite_pluginfile_urls($answer, 'pluginfile.php', $context->id, - 'mod_lesson', 'essay_responses', $options->attemptid); + 'mod_lesson', 'essay_answers', $options->attemptid); return parent::format_answer($answer, $context, $answerformat, $options); } @@ -303,7 +303,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats if ($useranswer != null) { $essayinfo = self::extract_useranswer($useranswer->useranswer); $essayinfo->answer = file_rewrite_pluginfile_urls($essayinfo->answer, 'pluginfile.php', - $context->id, 'mod_lesson', 'essay_responses', $useranswer->id); + $context->id, 'mod_lesson', 'essay_answers', $useranswer->id); if ($essayinfo->response == null) { $answerdata->response = get_string("nocommentyet", "lesson"); @@ -426,7 +426,7 @@ public function definition() { $mform->setType('answer', PARAM_RAW); $mform->addElement('html', $OUTPUT->container(get_string('youranswer', 'lesson'), 'youranswer')); $useranswer = file_rewrite_pluginfile_urls($useranswer, 'pluginfile.php', $editoroptions['context']->id, - 'mod_lesson', 'essay_responses', $this->_customdata['attemptid']); + 'mod_lesson', 'essay_answers', $this->_customdata['attemptid']); $mform->addElement('html', $OUTPUT->container($useranswer, 'reviewessay')); $this->add_action_buttons(null, get_string("nextpage", "lesson")); } else {