Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit f6d09222a2ec0208a280558171da1affd226ff52 1 parent ee8044f
@damyon damyon authored samhemelryk committed
View
4 mod/assign/assignmentplugin.php
@@ -415,9 +415,11 @@ public function get_editor_text($name, $submissionorgradeid) {
*
* @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();
}
View
4 mod/assign/feedback/file/importziplib.php
@@ -112,7 +112,7 @@ public function is_file_modified($assignment, $user, $plugin, $filename, $filein
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 @@ public function delete_import_files($contextid) {
$fs = get_file_storage();
return $fs->delete_area_files($contextid,
- 'assignfeedback_files',
+ 'assignfeedback_file',
ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
$USER->id);
}
View
35 mod/assign/locallib.php
@@ -1897,6 +1897,39 @@ private function view_plugin_content($pluginsubtype) {
}
/**
+ * 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
*
* @param string $filearea
@@ -2045,7 +2078,7 @@ private function download_submissions() {
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();
View
2  mod/assign/submission/file/locallib.php
@@ -228,7 +228,7 @@ public function save(stdClass $submission, stdClass $data) {
* @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();
View
21 mod/assign/submission/onlinetext/locallib.php
@@ -255,29 +255,16 @@ public function view_summary(stdClass $submission, & $showviewlink) {
* 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);
Please sign in to comment.
Something went wrong with that request. Please try again.