MDL-37030 Assignment: Fix error on download all submissions.
When group submissions and blind marking are enabled, an error is thrown when a teacher trys to download all submissions in a zip. The fix is to move the url rewriting from the plugin to the assign class so it is done in a standard way by all modules. The rewriting is done to make images in a text editor field resolve correctly.
This commit is contained in:
committed by
Sam Hemelryk
parent
ee8044f2e6
commit
f6d09222a2
@@ -415,9 +415,11 @@ abstract class assign_plugin {
|
||||
*
|
||||
* @param stdClass $submissionorgrade assign_submission or assign_grade
|
||||
* For submission plugins this is the submission data, for feedback plugins it is the grade data
|
||||
* @param stdClass $user The user record for the current submission.
|
||||
* Needed for url rewriting if this is a group submission.
|
||||
* @return array - return an array of files indexed by filename
|
||||
*/
|
||||
public function get_files(stdClass $submissionorgrade) {
|
||||
public function get_files(stdClass $submissionorgrade, stdClass $user) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class assignfeedback_file_zip_importer {
|
||||
if (!$sg) {
|
||||
return true;
|
||||
}
|
||||
foreach ($plugin->get_files($sg) as $pluginfilename => $file) {
|
||||
foreach ($plugin->get_files($sg, $user) as $pluginfilename => $file) {
|
||||
if ($pluginfilename == $filename) {
|
||||
// Extract the file and compare hashes.
|
||||
$contenthash = '';
|
||||
@@ -144,7 +144,7 @@ class assignfeedback_file_zip_importer {
|
||||
$fs = get_file_storage();
|
||||
|
||||
return $fs->delete_area_files($contextid,
|
||||
'assignfeedback_files',
|
||||
'assignfeedback_file',
|
||||
ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
|
||||
$USER->id);
|
||||
}
|
||||
|
||||
+34
-1
@@ -1896,6 +1896,39 @@ class assign {
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite plugin file urls so they resolve correctly in an exported zip.
|
||||
*
|
||||
* @param stdClass $user - The user record
|
||||
* @param assign_plugin $plugin - The assignment plugin
|
||||
*/
|
||||
public function download_rewrite_pluginfile_urls($text, $user, $plugin) {
|
||||
$groupmode = groups_get_activity_groupmode($this->get_course_module());
|
||||
$groupname = '';
|
||||
if ($groupmode) {
|
||||
$groupid = groups_get_activity_group($this->get_course_module(), true);
|
||||
$groupname = groups_get_group_name($groupid).'-';
|
||||
}
|
||||
|
||||
if ($this->is_blind_marking()) {
|
||||
$prefix = $groupname . get_string('participant', 'assign');
|
||||
$prefix = str_replace('_', ' ', $prefix);
|
||||
$prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($user->id) . '_');
|
||||
} else {
|
||||
$prefix = $groupname . fullname($user);
|
||||
$prefix = str_replace('_', ' ', $prefix);
|
||||
$prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($user->id) . '_');
|
||||
}
|
||||
|
||||
$subtype = $plugin->get_subtype();
|
||||
$type = $plugin->get_type();
|
||||
$prefix = $prefix . $subtype . '_' . $type . '_';
|
||||
|
||||
$result = str_replace('@@PLUGINFILE@@/', $prefix, $text);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* render the content in editor that is often used by plugin
|
||||
*
|
||||
@@ -2045,7 +2078,7 @@ class assign {
|
||||
if ($submission) {
|
||||
foreach ($this->submissionplugins as $plugin) {
|
||||
if ($plugin->is_enabled() && $plugin->is_visible()) {
|
||||
$pluginfiles = $plugin->get_files($submission);
|
||||
$pluginfiles = $plugin->get_files($submission, $student);
|
||||
foreach ($pluginfiles as $zipfilename => $file) {
|
||||
$subtype = $plugin->get_subtype();
|
||||
$type = $plugin->get_type();
|
||||
|
||||
@@ -228,7 +228,7 @@ class assign_submission_file extends assign_submission_plugin {
|
||||
* @param stdClass $submission The submission
|
||||
* @return array - return an array of files indexed by filename
|
||||
*/
|
||||
public function get_files(stdClass $submission) {
|
||||
public function get_files(stdClass $submission, stdClass $user) {
|
||||
$result = array();
|
||||
$fs = get_file_storage();
|
||||
|
||||
|
||||
@@ -255,29 +255,16 @@ class assign_submission_onlinetext extends assign_submission_plugin {
|
||||
* Produce a list of files suitable for export that represent this submission
|
||||
*
|
||||
* @param stdClass $submission - For this is the submission data
|
||||
* @param stdClass $user - This is the user record for this submission
|
||||
* @return array - return an array of files indexed by filename
|
||||
*/
|
||||
public function get_files(stdClass $submission) {
|
||||
public function get_files(stdClass $submission, stdClass $user) {
|
||||
global $DB;
|
||||
$files = array();
|
||||
$onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
|
||||
if ($onlinetextsubmission) {
|
||||
$user = $DB->get_record("user", array("id"=>$submission->userid),'id,username,firstname,lastname', MUST_EXIST);
|
||||
|
||||
if (!$this->assignment->is_blind_marking()) {
|
||||
$filename = str_replace('_', '', fullname($user)) . '_' .
|
||||
$this->assignment->get_uniqueid_for_user($submission->userid) . '_' .
|
||||
$this->get_name() . '_';
|
||||
$prefix = clean_filename($filename);
|
||||
} else {
|
||||
$filename = get_string('participant', 'assign') . '_' .
|
||||
$this->assignment->get_uniqueid_for_user($submission->userid) . '_' .
|
||||
$this->get_name() . '_';
|
||||
$prefix = clean_filename($filename);
|
||||
}
|
||||
|
||||
$finaltext = str_replace('@@PLUGINFILE@@/', $prefix, $onlinetextsubmission->onlinetext);
|
||||
$submissioncontent = "<html><body>". format_text($finaltext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())). "</body></html>"; //fetched from database
|
||||
$finaltext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
|
||||
$submissioncontent = "<html><body>". format_text($finaltext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())). "</body></html>";
|
||||
|
||||
$files[get_string('onlinetextfilename', 'assignsubmission_onlinetext')] = array($submissioncontent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user