|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 defined('MOODLE_INTERNAL') || die(); 00027 00028 class mod_folder_renderer extends plugin_renderer_base { 00029 00037 public function folder_tree($folder, $cm, $course) { 00038 $this->render(new folder_tree($folder, $cm, $course)); 00039 } 00040 00041 public function render_folder_tree(folder_tree $tree) { 00042 global $PAGE; 00043 00044 echo '<div id="folder_tree">'; 00045 echo $this->htmllize_tree($tree, $tree->dir); 00046 echo '</div>'; 00047 $this->page->requires->js_init_call('M.mod_folder.init_tree', array(true)); 00048 } 00049 00053 protected function htmllize_tree($tree, $dir) { 00054 global $CFG; 00055 00056 if (empty($dir['subdirs']) and empty($dir['files'])) { 00057 return ''; 00058 } 00059 $result = '<ul>'; 00060 foreach ($dir['subdirs'] as $subdir) { 00061 $result .= '<li>'.s($subdir['dirname']).' '.$this->htmllize_tree($tree, $subdir).'</li>'; 00062 } 00063 foreach ($dir['files'] as $file) { 00064 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_folder/content/'.$tree->folder->revision.$file->get_filepath().$file->get_filename(), true); 00065 $filename = $file->get_filename(); 00066 $result .= '<li><span>'.html_writer::link($url, $filename).'</span></li>'; 00067 } 00068 $result .= '</ul>'; 00069 00070 return $result; 00071 } 00072 } 00073 00074 class folder_tree implements renderable { 00075 public $context; 00076 public $folder; 00077 public $cm; 00078 public $course; 00079 public $dir; 00080 00081 public function __construct($folder, $cm, $course) { 00082 $this->folder = $folder; 00083 $this->cm = $cm; 00084 $this->course = $course; 00085 00086 $this->context = get_context_instance(CONTEXT_MODULE, $cm->id); 00087 $fs = get_file_storage(); 00088 $this->dir = $fs->get_area_tree($this->context->id, 'mod_folder', 'content', 0); 00089 } 00090 }