diff --git a/mod/assign/feedback/file/importziplib.php b/mod/assign/feedback/file/importziplib.php index 8acf0206f05..a5466b175a4 100644 --- a/mod/assign/feedback/file/importziplib.php +++ b/mod/assign/feedback/file/importziplib.php @@ -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 = "/"; diff --git a/mod/assign/gradingoptionsform.php b/mod/assign/gradingoptionsform.php index af6504a079d..4b60f5daac6 100644 --- a/mod/assign/gradingoptionsform.php +++ b/mod/assign/gradingoptionsform.php @@ -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); diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index 097a09f4e74..700b4a3fdea 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -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}'; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 599b3c08eec..cfa9227d770 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -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); diff --git a/mod/assign/module.js b/mod/assign/module.js index 3504927052c..c37dedf113b 100644 --- a/mod/assign/module.js +++ b/mod/assign/module.js @@ -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(); + }); + } }); }; diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index f0943bca99b..a044a03ea7a 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -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; }