MDL-56022 Assign: Make folders structure in the downloaded zip optional
Special thanks to Matt McDermott for the contributing the Javascript code to fix this issue.
This commit is contained in:
@@ -237,13 +237,13 @@ class assignfeedback_file_zip_importer {
|
||||
if ($this->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) {
|
||||
$grade = $assignment->get_user_grade($user->id, true);
|
||||
|
||||
// In 3.1 the download structure of the submission files changed so that each student had their own
|
||||
// In 3.1 the default download structure of the submission files changed so that each student had their own
|
||||
// separate folder, the files were not renamed and the folder structure was kept. It is possible that
|
||||
// a user downloaded the submission files in 3.0 (or earlier) and edited the zip to add feedback and
|
||||
// in that time the site was updated to 3.1, the following code means that we will still support the
|
||||
// old file structure. For more information please see - MDL-52489.
|
||||
// a user downloaded the submission files in 3.0 (or earlier) and edited the zip to add feedback or
|
||||
// changed the behavior back to the previous format, the following code means that we will still support the
|
||||
// old file structure. For more information please see - MDL-52489 / MDL-56022.
|
||||
$path = pathinfo($filename);
|
||||
if ($path['dirname'] == '.') { // Old structure as students are not in separate folders.
|
||||
if ($path['dirname'] == '.') { // Student submissions are not in separate folders.
|
||||
$basename = $filename;
|
||||
$dirname = "/";
|
||||
$dirnamewslash = "/";
|
||||
|
||||
@@ -86,6 +86,13 @@ class mod_assign_grading_options_form extends moodleform {
|
||||
$mform->setDefault('showonlyactiveenrol', $instance['showonlyactiveenrol']);
|
||||
}
|
||||
|
||||
// Place student downloads in seperate folders.
|
||||
if ($instance['submissionsenabled']) {
|
||||
$mform->addElement('checkbox', 'downloadasfolders', get_string('downloadasfolders', 'assign'), '', $dirtyclass);
|
||||
$mform->addHelpButton('downloadasfolders', 'downloadasfolders', 'assign');
|
||||
$mform->setDefault('downloadasfolders', $instance['downloadasfolders']);
|
||||
}
|
||||
|
||||
// Hidden params.
|
||||
$mform->addElement('hidden', 'contextid', $instance['contextid']);
|
||||
$mform->setType('contextid', PARAM_INT);
|
||||
|
||||
@@ -137,6 +137,8 @@ $string['deleteallsubmissions'] = 'Delete all submissions';
|
||||
$string['description'] = 'Description';
|
||||
$string['downloadall'] = 'Download all submissions';
|
||||
$string['download all submissions'] = 'Download all submissions in a zip file.';
|
||||
$string['downloadasfolders'] = 'Download as separate folders';
|
||||
$string['downloadasfolders_help'] = 'When enabled downloaded files will be placed in separate folders and files will not be renamed.';
|
||||
$string['downloadselectedsubmissions'] = 'Download selected submissions';
|
||||
$string['duedate'] = 'Due date';
|
||||
$string['duedatecolon'] = 'Due date: {$a}';
|
||||
|
||||
+52
-22
@@ -2902,28 +2902,51 @@ class assign {
|
||||
}
|
||||
|
||||
if ($submission) {
|
||||
$downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
|
||||
foreach ($this->submissionplugins as $plugin) {
|
||||
if ($plugin->is_enabled() && $plugin->is_visible()) {
|
||||
$pluginfiles = $plugin->get_files($submission, $student);
|
||||
foreach ($pluginfiles as $zipfilepath => $file) {
|
||||
$subtype = $plugin->get_subtype();
|
||||
$type = $plugin->get_type();
|
||||
$zipfilename = basename($zipfilepath);
|
||||
$prefixedfilename = clean_filename($prefix .
|
||||
'_' .
|
||||
$subtype .
|
||||
'_' .
|
||||
$type .
|
||||
'_');
|
||||
if ($type == 'file') {
|
||||
$pathfilename = $prefixedfilename . $file->get_filepath() . $zipfilename;
|
||||
} else if ($type == 'onlinetext') {
|
||||
$pathfilename = $prefixedfilename . '/' . $zipfilename;
|
||||
} else {
|
||||
$pathfilename = $prefixedfilename . '/' . $zipfilename;
|
||||
if ($downloadasfolders) {
|
||||
// Create a folder for each user for each assignment plugin.
|
||||
// This is the default behavior for version of Moodle >= 3.1.
|
||||
$submission->exportfullpath = true;
|
||||
$pluginfiles = $plugin->get_files($submission, $student);
|
||||
foreach ($pluginfiles as $zipfilepath => $file) {
|
||||
$subtype = $plugin->get_subtype();
|
||||
$type = $plugin->get_type();
|
||||
$zipfilename = basename($zipfilepath);
|
||||
$prefixedfilename = clean_filename($prefix .
|
||||
'_' .
|
||||
$subtype .
|
||||
'_' .
|
||||
$type .
|
||||
'_');
|
||||
if ($type == 'file') {
|
||||
$pathfilename = $prefixedfilename . $file->get_filepath() . $zipfilename;
|
||||
} else if ($type == 'onlinetext') {
|
||||
$pathfilename = $prefixedfilename . '/' . $zipfilename;
|
||||
} else {
|
||||
$pathfilename = $prefixedfilename . '/' . $zipfilename;
|
||||
}
|
||||
$pathfilename = clean_param($pathfilename, PARAM_PATH);
|
||||
$filesforzipping[$pathfilename] = $file;
|
||||
}
|
||||
} else {
|
||||
// Create a single folder for all users of all assignment plugins.
|
||||
// This was the default behavior for version of Moodle < 3.1.
|
||||
$submission->exportfullpath = false;
|
||||
$pluginfiles = $plugin->get_files($submission, $student);
|
||||
foreach ($pluginfiles as $zipfilename => $file) {
|
||||
$subtype = $plugin->get_subtype();
|
||||
$type = $plugin->get_type();
|
||||
$prefixedfilename = clean_filename($prefix .
|
||||
'_' .
|
||||
$subtype .
|
||||
'_' .
|
||||
$type .
|
||||
'_' .
|
||||
$zipfilename);
|
||||
$filesforzipping[$prefixedfilename] = $file;
|
||||
}
|
||||
$pathfilename = clean_param($pathfilename, PARAM_PATH);
|
||||
$filesforzipping[$pathfilename] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3679,6 +3702,7 @@ class assign {
|
||||
$showquickgrading = empty($controller) && $this->can_grade();
|
||||
$quickgrading = get_user_preferences('assign_quickgrading', false);
|
||||
$showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
|
||||
$downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
|
||||
|
||||
$markingallocation = $this->get_instance()->markingworkflow &&
|
||||
$this->get_instance()->markingallocation &&
|
||||
@@ -3715,7 +3739,8 @@ class assign {
|
||||
'markingworkflowopt'=>$markingworkflowoptions,
|
||||
'markingallocationopt'=>$markingallocationoptions,
|
||||
'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
|
||||
'showonlyactiveenrol'=>$this->show_only_active_users());
|
||||
'showonlyactiveenrol' => $this->show_only_active_users(),
|
||||
'downloadasfolders' => $downloadasfolders);
|
||||
|
||||
$classoptions = array('class'=>'gradingoptionsform');
|
||||
$gradingoptionsform = new mod_assign_grading_options_form(null,
|
||||
@@ -6178,8 +6203,8 @@ class assign {
|
||||
'markingworkflowopt' => $markingworkflowoptions,
|
||||
'markingallocationopt' => $markingallocationoptions,
|
||||
'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
|
||||
'showonlyactiveenrol'=>$this->show_only_active_users());
|
||||
|
||||
'showonlyactiveenrol' => $this->show_only_active_users(),
|
||||
'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1));
|
||||
$mform = new mod_assign_grading_options_form(null, $gradingoptionsparams);
|
||||
if ($formdata = $mform->get_data()) {
|
||||
set_user_preference('assign_perpage', $formdata->perpage);
|
||||
@@ -6195,6 +6220,11 @@ class assign {
|
||||
if ($showquickgrading) {
|
||||
set_user_preference('assign_quickgrading', isset($formdata->quickgrading));
|
||||
}
|
||||
if (isset($formdata->downloadasfolders)) {
|
||||
set_user_preference('assign_downloadasfolders', 1); // Enabled.
|
||||
} else {
|
||||
set_user_preference('assign_downloadasfolders', 0); // Disabled.
|
||||
}
|
||||
if (!empty($showonlyactiveenrolopt)) {
|
||||
$showonlyactiveenrol = isset($formdata->showonlyactiveenrol);
|
||||
set_user_preference('grade_report_showonlyactiveenrol', $showonlyactiveenrol);
|
||||
|
||||
@@ -147,6 +147,12 @@ M.mod_assign.init_grading_options = function(Y) {
|
||||
Y.one('form.gradingoptionsform').submit();
|
||||
});
|
||||
}
|
||||
var downloadasfolderselement = Y.one('#id_downloadasfolders');
|
||||
if (downloadasfolderselement) {
|
||||
downloadasfolderselement.on('change', function(e) {
|
||||
Y.one('form.gradingoptionsform').submit();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -304,7 +304,12 @@ class assign_submission_file extends assign_submission_plugin {
|
||||
false);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$result[$file->get_filepath().$file->get_filename()] = $file;
|
||||
// Do we return the full folder path or just the file name?
|
||||
if (isset($submission->exportfullpath) && $submission->exportfullpath == false) {
|
||||
$result[$file->get_filename()] = $file;
|
||||
} else {
|
||||
$result[$file->get_filepath().$file->get_filename()] = $file;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user