mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-39261 mod_lesson: Move essay answer files to new file area
* Moved answers to a different file area * Added backup and restore calls * Include privacy/reset related calls similar to essay responses
This commit is contained in:
parent
676eca7b9b
commit
a4606b7efe
@ -197,6 +197,7 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
|
||||
$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);
|
||||
|
@ -253,6 +253,7 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
|
||||
$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()),
|
||||
|
@ -445,6 +445,7 @@ class provider implements
|
||||
|
||||
$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 @@ class provider implements
|
||||
$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 @@ class provider implements
|
||||
$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 @@ class provider implements
|
||||
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 @@ class provider implements
|
||||
);
|
||||
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) {
|
||||
|
@ -248,7 +248,7 @@ switch ($mode) {
|
||||
$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 @@ switch ($mode) {
|
||||
// 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));
|
||||
|
@ -474,6 +474,7 @@ $string['privacy:metadata:overrides:password'] = 'The password to access the les
|
||||
$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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -3923,6 +3923,7 @@ abstract class lesson_page extends lesson_base {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ class lesson_page_type_essay extends lesson_page {
|
||||
}
|
||||
|
||||
$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 @@ class lesson_page_type_essay extends lesson_page {
|
||||
);
|
||||
|
||||
$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 @@ class lesson_page_type_essay extends lesson_page {
|
||||
*/
|
||||
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 @@ class lesson_page_type_essay extends lesson_page {
|
||||
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 @@ class lesson_display_answer_form_essay extends moodleform {
|
||||
$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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user