public function get_visible_name() { if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { return $this->topvisiblename; } return parent::get_visible_name(); }
/** * Returns list of children which are either files matching the specified extensions * or folders that contain at least one such file. * * @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') * @return array of file_info instances */ public function get_non_empty_children($extensions = '*') { $items = $this->gallery->get_items(); $result = array(); foreach ($items as $item) { $file = $item->get_file(); $extension = core_text::strtolower(pathinfo($file->get_filename(), PATHINFO_EXTENSION)); if ($file->is_directory() || $extensions === '*' || !empty($extension) && in_array('.' . $extension, $extensions)) { $fileinfo = new file_info_stored($this->browser, $this->context, $file, $this->urlbase, $this->topvisiblename, $this->itemidused, $this->readaccess, $this->writeaccess, false); if (!$file->is_directory() || $fileinfo->count_non_empty_children($extensions)) { $result[] = $fileinfo; } } } return $result; }
/** * Constructor * * @param file_browser $browser file browser instance * @param stdClass $context context object * @param stored_file $storedfile stored_file instance */ 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 list of children which are either files matching the specified extensions * or folders that contain at least one such file. * * @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') * @return array of file_info instances */ public function get_non_empty_children($extensions = '*') { $result = array(); if (!$this->lf->is_directory()) { return $result; } $fs = get_file_storage(); $storedfiles = $fs->get_directory_files($this->context->id, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), false, true, "filepath, filename"); foreach ($storedfiles as $file) { $extension = core_text::strtolower(pathinfo($file->get_filename(), PATHINFO_EXTENSION)); if ($file->is_directory() || $extensions === '*' || !empty($extension) && in_array('.' . $extension, $extensions)) { $fileinfo = new file_info_stored($this->browser, $this->context, $file, $this->urlbase, $this->topvisiblename, $this->itemidused, $this->readaccess, $this->writeaccess, false); if (!$file->is_directory() || $fileinfo->count_non_empty_children($extensions)) { $result[] = $fileinfo; } } } return $result; }