. /** * Utility class for browsing of coursefiles. * * @package moodlecore * @subpackage file-browser * @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. */ class file_info_coursefile extends file_info_stored { public function __construct($browser, $context, $storedfile) { global $CFG; $urlbase = $CFG->wwwroot.'/file.php'; parent::__construct($browser, $context, $storedfile, $urlbase, get_string('coursefiles'), false, true, true, false); } /** * Returns file download url * @param bool $forcedownload * @param bool $htts force https * @return string url */ public function get_url($forcedownload=false, $https=false) { global $CFG; if (!$this->is_readable()) { return null; } if ($this->lf->is_directory()) { return null; } $filepath = $this->lf->get_filepath(); $filename = $this->lf->get_filename(); $courseid = $this->context->instanceid; $path = '/'.$courseid.$filepath.$filename; return file_encode_url($this->urlbase, $path, $forcedownload, $https); } /** * Returns list of children. * @return array of file_info instances */ public function get_children() { if (!$this->lf->is_directory()) { return array(); } $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; } }