mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-32639 files: Improved File Manager download and zip support
This commit is contained in:
parent
697ade2850
commit
638d72cd0b
6 changed files with 46 additions and 26 deletions
|
@ -463,23 +463,36 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
|
|||
* @global stdClass $CFG
|
||||
* @global stdClass $USER
|
||||
* @param int $draftitemid the draft area item id.
|
||||
* @param string $filepath path to the directory from which the information have to be retrieved.
|
||||
* @return array with the following entries:
|
||||
* 'filecount' => number of files in the draft area.
|
||||
* 'filesize' => total size of the files in the draft area.
|
||||
* 'foldercount' => number of folders in the draft area.
|
||||
* (more information will be added as needed).
|
||||
*/
|
||||
function file_get_draft_area_info($draftitemid) {
|
||||
function file_get_draft_area_info($draftitemid, $filepath = '/') {
|
||||
global $CFG, $USER;
|
||||
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$results = array();
|
||||
$results = array(
|
||||
'filecount' => 0,
|
||||
'foldercount' => 0,
|
||||
'filesize' => 0
|
||||
);
|
||||
|
||||
// The number of files
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false);
|
||||
$results['filecount'] = count($draftfiles);
|
||||
$results['filesize'] = 0;
|
||||
if ($filepath != '/') {
|
||||
$draftfiles = $fs->get_directory_files($usercontext->id, 'user', 'draft', $draftitemid, $filepath, true, true);
|
||||
} else {
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', true);
|
||||
}
|
||||
foreach ($draftfiles as $file) {
|
||||
if ($file->is_directory()) {
|
||||
$results['foldercount'] += 1;
|
||||
} else {
|
||||
$results['filecount'] += 1;
|
||||
}
|
||||
$results['filesize'] += $file->get_filesize();
|
||||
}
|
||||
|
||||
|
|
|
@ -137,6 +137,12 @@ class zip_packer extends file_packer {
|
|||
}
|
||||
}
|
||||
|
||||
// We can consider that there was an error if the file generated does not contain anything.
|
||||
if ($ziparch->count() == 0) {
|
||||
$result = false;
|
||||
debugging("Nothing was added to the zip file", DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
return ($ziparch->close() && $result);
|
||||
}
|
||||
|
||||
|
|
|
@ -220,9 +220,9 @@ M.form_filemanager.init = function(Y, options) {
|
|||
params: {'filepath':filepath},
|
||||
callback: function(id, obj, args) {
|
||||
scope.filecount = obj.filecount;
|
||||
scope.check_buttons();
|
||||
scope.options = obj;
|
||||
scope.lazyloading = {};
|
||||
scope.check_buttons();
|
||||
scope.render(obj);
|
||||
}
|
||||
}, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue