From: skodak Date: Wed, 20 May 2009 22:17:53 +0000 (+0000) Subject: MDL-18111 improving file api comments and docs, fixing license header + minor refactoring X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c05e9754cefe892153e4bbcdda1eb83ba70141e9;p=moodle.git MDL-18111 improving file api comments and docs, fixing license header + minor refactoring --- diff --git a/lib/file/file_browser.php b/lib/file/file_browser.php index 31c8b8454f..e446e41165 100644 --- a/lib/file/file_browser.php +++ b/lib/file/file_browser.php @@ -1,4 +1,28 @@ -. + + +/** + * Utility class for browsing of files. + * + * @package moodle-core + * @copyright 2008 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once("$CFG->libdir/file/file_info.php"); require_once("$CFG->libdir/file/file_info_module.php"); @@ -21,11 +45,16 @@ require_once("$CFG->libdir/file/virtual_root_file.php"); * file areas, and a file area contains folders and files. The various file_info * subclasses return info about the things in this tree. They should be obtained * from an instance of this class. + * + * This virtual tree is different for each user depending of his/her current permissions. + * Some branches such as draft areas are hidden, but accessible. + * + * Always use this abstraction when you need to access module files from core code. */ class file_browser { /** - * Looks up file_info object + * Looks up file_info instance * @param object $context * @param string $filearea * @param int $itemid @@ -50,36 +79,6 @@ class file_browser { return null; } - /** - * Returns content of local directory - */ - public function build_stored_file_children($context, $filearea, $itemid, $filepath, $urlbase, $topvisiblename, $itemidused, $readaccess, $writeaccess) { - $result = array(); - $fs = get_file_storage(); - - $storedfiles = $fs->get_directory_files($context->id, $filearea, $itemid, $filepath, false, true, "filepath, filename"); - foreach ($storedfiles as $file) { - $result[] = new file_info_stored($this, $context, $file, $urlbase, $topvisiblename, $itemidused, $readaccess, $writeaccess, false); - } - - return $result; - } - - /** - * Returns content of coursefiles directory - */ - public function build_coursefile_children($context, $filepath) { - $result = array(); - $fs = get_file_storage(); - - $storedfiles = $fs->get_directory_files($context->id, 'course_content', 0, $filepath, false, true, "filepath, filename"); - foreach ($storedfiles as $file) { - $result[] = new file_info_coursefile($this, $context, $file); - } - - return $result; - } - public function encodepath($urlbase, $path, $forcedownload=false, $https=false) { global $CFG; diff --git a/lib/file/file_info_coursefile.php b/lib/file/file_info_coursefile.php index 9e07380f1e..a903a15f12 100644 --- a/lib/file/file_info_coursefile.php +++ b/lib/file/file_info_coursefile.php @@ -1,4 +1,28 @@ -. + + +/** + * Class for browsing of legacy course files. + * + * @package moodle-core + * @copyright 2008 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ /** * Subclass of file_info_stored for files in the course files area. @@ -34,8 +58,15 @@ class file_info_coursefile extends file_info_stored { if (!$this->lf->is_directory()) { return array(); } - return $this->browser->build_coursefile_children($this->context, $this->lf->get_filepath()); - } + $result = array(); + $fs = get_file_storage(); + + $storedfiles = $fs->get_directory_files($this->context->id, 'course_content', 0, $this->lf->get_filepath(), false, true, "filepath, filename"); + foreach ($storedfiles as $file) { + $result[] = new file_info_coursefile($this->browser, $this->context, $file); + } + return $result; + } } diff --git a/lib/file/file_info_stored.php b/lib/file/file_info_stored.php index 316eadfede..ce1d2db81a 100644 --- a/lib/file/file_info_stored.php +++ b/lib/file/file_info_stored.php @@ -1,4 +1,28 @@ -. + + +/** + * Utility class for browsing of stored files. + * + * @package moodle-core + * @copyright 2008 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ /** * Represents an actual file or folder - a row in the file table - @@ -111,9 +135,18 @@ class file_info_stored extends file_info { if (!$this->lf->is_directory()) { return array(); } - return $this->browser->build_stored_file_children($this->context, $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), - $this->urlbase, $this->topvisiblename, $this->itemidused, $this->readaccess, $this->writeaccess, - $this->areaonly); + + $result = array(); + $fs = get_file_storage(); + + $storedfiles = $fs->get_directory_files($this->context->id, $this->lf->get_filearea(), $this->lf->get_itemid(), + $this->lf->get_filepath(), false, true, "filepath, filename"); + foreach ($storedfiles as $file) { + $result[] = new file_info_stored($this->browser, $this->context, $file, $this->urlbase, $this->topvisiblename, + $this->itemidused, $this->readaccess, $this->writeaccess, false); + } + + return $result; } public function get_parent() {