. // // // /////////////////////////////////////////////////////////////////////////// defined('MOODLE_INTERNAL') || die(); /** * Rendering of files viewer related widgets. * @package core * @subpackage file * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ /** * File manager render * * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ class core_files_renderer extends plugin_renderer_base { public function files_tree_viewer(file_info $file_info, array $options = null) { $tree = new files_tree_viewer($file_info, $options); return $this->render($tree); } public function render_files_tree_viewer(files_tree_viewer $tree) { $html = '
'; foreach($tree->path as $path) { $html .= $path; $html .= ' / '; } $html .= '
'; $html .= '
'; if (empty($tree->tree)) { $html .= get_string('nofilesavailable', 'repository'); } else { $this->page->requires->js_init_call('M.core_filetree.init'); $html .= ''; } $html .= '
'; return $html; } } /** * Data structure representing a general moodle file tree viewer * * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ class files_tree_viewer implements renderable { public $tree; public $path; /** * Constructor of moodle_file_tree_viewer class * @param file_info $file_info * @param array $options */ public function __construct(file_info $file_info, array $options = null) { global $CFG; //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!! $this->options = (array)$options; if (isset($this->options['visible_areas'])) { $visible_areas = (array)$this->options['visible_areas']; } else { $visible_areas = false; } $this->tree = array(); $children = $file_info->get_children(); $parent_info = $file_info->get_parent(); $level = $parent_info; $this->path = array(); while ($level) { $params = $level->get_params(); $context = get_context_instance_by_id($params['contextid']); // lock user in course level if ($context->contextlevel == CONTEXT_COURSECAT or $context->contextlevel == CONTEXT_SYSTEM) { break; } $url = new moodle_url('/files/index.php', $params); $this->path[] = html_writer::link($url->out(false), $level->get_visible_name()); $level = $level->get_parent(); } $this->path = array_reverse($this->path); $this->path[] = $file_info->get_visible_name(); foreach ($children as $child) { $filedate = $child->get_timemodified(); $filesize = $child->get_filesize(); $mimetype = $child->get_mimetype(); $params = $child->get_params(); $url = new moodle_url('/files/index.php', $params); $fileitem = array( 'params' => $params, 'filename' => $child->get_visible_name(), 'filedate' => $filedate ? userdate($filedate) : '', 'filesize' => $filesize ? display_size($filesize) : '' ); if ($child->is_directory()) { $fileitem['isdir'] = true; $fileitem['url'] = $url->out(false); if ($visible_areas !== false) { if (!isset($visible_areas[$params['component']][$params['filearea']])) { continue; } } } else { $fileitem['url'] = $child->get_url(); } $this->tree[] = $fileitem; } } }