Skip to content

Commit

Permalink
MDL-51306 mod_folder: Use context_module to find details
Browse files Browse the repository at this point in the history
renderable should not be used for extracting
details. Use cm to get context and dir information
  • Loading branch information
Rajesh Taneja authored and David Monllao committed Feb 10, 2016
1 parent 985dca6 commit cd6e7e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions mod/folder/download_folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@

$folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);

$foldertree = new folder_tree($folder, $cm);
$downloadable = folder_archive_available($folder, $foldertree);
$downloadable = folder_archive_available($folder, $cm);
if (!$downloadable) {
print_error('cannotdownloaddir', 'repository');
}
Expand Down
10 changes: 7 additions & 3 deletions mod/folder/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,20 @@ function folder_view($folder, $course, $cm, $context) {
/**
* Check if the folder can be zipped and downloaded.
* @param stdClass $folder
* @param folder_tree $foldertree
* @param context_module $cm
* @return bool True if the folder can be zipped and downloaded.
* @throws \dml_exception
*/
function folder_archive_available($folder, $foldertree) {
function folder_archive_available($folder, $cm) {
if (!$folder->showdownloadfolder) {
return false;
}

$size = folder_get_directory_size($foldertree->dir);
$context = context_module::instance($cm->id);
$fs = get_file_storage();
$dir = $fs->get_area_tree($context->id, 'mod_folder', 'content', 0);

$size = folder_get_directory_size($dir);
$maxsize = get_config('folder', 'maxsizetodownload') * 1024 * 1024;

if ($size == 0) {
Expand Down
2 changes: 1 addition & 1 deletion mod/folder/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function display_folder(stdClass $folder) {
// Do not append the edit button on the course page.
if ($folder->display != FOLDER_DISPLAY_INLINE) {
$containercontents = '';
$downloadable = folder_archive_available($folder, $foldertree);
$downloadable = folder_archive_available($folder, $cm);

if ($downloadable) {
$containercontents .= $this->output->single_button(
Expand Down

0 comments on commit cd6e7e0

Please sign in to comment.