mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-27520 assignfeedback_comments: copy files to feedback
This respects the setting 'Comment inline' where the content of a submission is copied into the feedback form.
This commit is contained in:
parent
c9f6ca1142
commit
3672775931
@ -260,18 +260,47 @@ class assign_feedback_comments extends assign_feedback_plugin {
|
||||
*
|
||||
* @param stdClass $submission
|
||||
* @param stdClass $data - Form data to be filled with the converted submission text and format.
|
||||
* @param stdClass|null $grade
|
||||
* @return boolean - True if feedback text was set.
|
||||
*/
|
||||
protected function convert_submission_text_to_feedback($submission, $data) {
|
||||
protected function convert_submission_text_to_feedback($submission, $data, $grade) {
|
||||
global $DB;
|
||||
|
||||
$format = false;
|
||||
$text = '';
|
||||
|
||||
foreach ($this->assignment->get_submission_plugins() as $plugin) {
|
||||
$fields = $plugin->get_editor_fields();
|
||||
if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($submission) && !empty($fields)) {
|
||||
$user = $DB->get_record('user', ['id' => $submission->userid]);
|
||||
// Copy the files to the feedback area.
|
||||
if ($files = $plugin->get_files($submission, $user)) {
|
||||
$fs = get_file_storage();
|
||||
$component = 'assignfeedback_comments';
|
||||
$filearea = ASSIGNFEEDBACK_COMMENTS_FILEAREA;
|
||||
$itemid = $grade->id;
|
||||
$fieldupdates = [
|
||||
'component' => $component,
|
||||
'filearea' => $filearea,
|
||||
'itemid' => $itemid
|
||||
];
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof stored_file) {
|
||||
// Before we create it, check that it doesn't already exist.
|
||||
if (!$fs->file_exists(
|
||||
$file->get_contextid(),
|
||||
$component,
|
||||
$filearea,
|
||||
$itemid,
|
||||
$file->get_filepath(),
|
||||
$file->get_filename())) {
|
||||
$fs->create_file_from_storedfile($fieldupdates, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($fields as $key => $description) {
|
||||
$rawtext = strip_pluginfile_content($plugin->get_editor_text($key, $submission->id));
|
||||
|
||||
$rawtext = clean_text($plugin->get_editor_text($key, $submission->id));
|
||||
$newformat = $plugin->get_editor_format($key, $submission->id);
|
||||
|
||||
if ($format !== false && $newformat != $format) {
|
||||
@ -288,8 +317,8 @@ class assign_feedback_comments extends assign_feedback_plugin {
|
||||
if ($format === false) {
|
||||
$format = FORMAT_HTML;
|
||||
}
|
||||
$data->assignfeedbackcomments_editor['text'] = $text;
|
||||
$data->assignfeedbackcomments_editor['format'] = $format;
|
||||
$data->assignfeedbackcomments = $text;
|
||||
$data->assignfeedbackcommentsformat = $format;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -317,7 +346,7 @@ class assign_feedback_comments extends assign_feedback_plugin {
|
||||
} else {
|
||||
// No feedback given yet - maybe we need to copy the text from the submission?
|
||||
if (!empty($commentinlinenabled) && $submission) {
|
||||
$this->convert_submission_text_to_feedback($submission, $data);
|
||||
$this->convert_submission_text_to_feedback($submission, $data, $grade);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3004,7 +3004,7 @@ class mod_assign_locallib_testcase extends advanced_testcase {
|
||||
* Testing for comment inline settings
|
||||
*/
|
||||
public function test_feedback_comment_commentinline() {
|
||||
global $CFG;
|
||||
global $CFG, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@ -3024,22 +3024,6 @@ Internal link 1:<img src='@@PLUGINFILE@@/logo-240x60.gif' alt='Moodle'/>
|
||||
Internal link 2:<img alt=\"Moodle\" src=\"@@PLUGINFILE@@logo-240x60.gif\"/>
|
||||
Anchor link 1:<a href=\"@@PLUGINFILE@@logo-240x60.gif\" alt=\"bananas\">Link text</a>
|
||||
Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
";
|
||||
|
||||
// Note the internal images have been stripped and the html is purified (quotes fixed in this case).
|
||||
$filteredtext = "Hello!
|
||||
|
||||
I'm writing to you from the Moodle Majlis in Muscat, Oman, where we just had several days of Moodle community goodness.
|
||||
|
||||
URL outside a tag: https://moodle.org/logo/logo-240x60.gif
|
||||
Plugin url outside a tag: @@PLUGINFILE@@/logo-240x60.gif
|
||||
|
||||
External link 1:<img src=\"https://moodle.org/logo/logo-240x60.gif\" alt=\"Moodle\" />
|
||||
External link 2:<img alt=\"Moodle\" src=\"https://moodle.org/logo/logo-240x60.gif\" />
|
||||
Internal link 1:
|
||||
Internal link 2:
|
||||
Anchor link 1:Link text
|
||||
Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
";
|
||||
|
||||
$this->setUser($teacher);
|
||||
@ -3068,6 +3052,27 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$formparams = array($assign, $data, $pagination);
|
||||
$mform = new mod_assign_grade_form(null, [$assign, $data, $pagination]);
|
||||
|
||||
// We need to get the URL these will be transformed to.
|
||||
$context = context_user::instance($USER->id);
|
||||
$itemid = $data->assignfeedbackcomments_editor['itemid'];
|
||||
$url = $CFG->wwwroot . '/draftfile.php/' . $context->id . '/user/draft/' . $itemid;
|
||||
|
||||
// Note the internal images have been stripped and the html is purified (quotes fixed in this case).
|
||||
$filteredtext = "Hello!
|
||||
|
||||
I'm writing to you from the Moodle Majlis in Muscat, Oman, where we just had several days of Moodle community goodness.
|
||||
|
||||
URL outside a tag: https://moodle.org/logo/logo-240x60.gif
|
||||
Plugin url outside a tag: $url/logo-240x60.gif
|
||||
|
||||
External link 1:<img src=\"https://moodle.org/logo/logo-240x60.gif\" alt=\"Moodle\" />
|
||||
External link 2:<img alt=\"Moodle\" src=\"https://moodle.org/logo/logo-240x60.gif\" />
|
||||
Internal link 1:<img src=\"$url/logo-240x60.gif\" alt=\"Moodle\" />
|
||||
Internal link 2:<img alt=\"Moodle\" src=\"@@PLUGINFILE@@logo-240x60.gif\" />
|
||||
Anchor link 1:<a href=\"@@PLUGINFILE@@logo-240x60.gif\">Link text</a>
|
||||
Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
";
|
||||
|
||||
$this->assertEquals($filteredtext, $data->assignfeedbackcomments_editor['text']);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user