Skip to content

Commit

Permalink
MDL-39359 - mod/assign: Allow zipped folder to be uploaded for return…
Browse files Browse the repository at this point in the history
…ing feedback files

The "Upload multiple feedback files in a zip" feature is convenient, but requires that
the files sit directly within the zip file. As the files will most likely be extracted
to a folder after downloading, it's quite reasonable to expect teachers to zip the
folder up rather than selecting all files and zipping them.  This patch allows for a
zipped folder to be uploaded; if the only file found after extracting is a directory,
the contents of the directory are used instead of the results of the extraction.
  • Loading branch information
pauln committed Jul 24, 2013
1 parent ffc3f53 commit 381e6d7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mod/assign/feedback/file/importziplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ public function get_import_files($contextid) {
$USER->id,
'/import/');

$keys = array_keys($files);
if (count($files) == 1 && $files[$keys[0]]->is_directory()) {
// An entire folder was zipped, rather than its contents.
// We need to return the contents of the folder instead, so the import can continue.
$files = $fs->get_directory_files($contextid,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
$USER->id,
$files[$keys[0]]->get_filepath());
}

return $files;
}

Expand All @@ -205,7 +216,7 @@ public function get_import_files($contextid) {
* @return string - The html response
*/
public function import_zip_files($assignment, $fileplugin) {
global $USER, $CFG, $PAGE, $DB;
global $CFG, $PAGE, $DB;

@set_time_limit(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME);
$packer = get_file_packer('application/zip');
Expand All @@ -216,11 +227,7 @@ public function import_zip_files($assignment, $fileplugin) {
$contextid = $assignment->get_context()->id;

$fs = get_file_storage();
$files = $fs->get_directory_files($contextid,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
$USER->id,
'/import/');
$files = $this->get_import_files($contextid);

$currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
$allusers = $assignment->list_participants($currentgroup, false);
Expand Down

0 comments on commit 381e6d7

Please sign in to comment.