|
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 00018 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 class block_private_files_renderer extends plugin_renderer_base { 00031 00036 public function private_files_tree() { 00037 return $this->render(new private_files_tree); 00038 } 00039 00040 public function render_private_files_tree(private_files_tree $tree) { 00041 $module = array('name'=>'block_private_files', 'fullpath'=>'/blocks/private_files/module.js', 'requires'=>array('yui2-treeview')); 00042 if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) { 00043 $html = $this->output->box(get_string('nofilesavailable', 'repository')); 00044 } else { 00045 $htmlid = 'private_files_tree_'.uniqid(); 00046 $this->page->requires->js_init_call('M.block_private_files.init_tree', array(false, $htmlid)); 00047 $html = '<div id="'.$htmlid.'">'; 00048 $html .= $this->htmllize_tree($tree, $tree->dir); 00049 $html .= '</div>'; 00050 } 00051 00052 return $html; 00053 } 00054 00058 protected function htmllize_tree($tree, $dir) { 00059 global $CFG; 00060 $yuiconfig = array(); 00061 $yuiconfig['type'] = 'html'; 00062 00063 if (empty($dir['subdirs']) and empty($dir['files'])) { 00064 return ''; 00065 } 00066 $result = '<ul>'; 00067 foreach ($dir['subdirs'] as $subdir) { 00068 $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon')); 00069 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>'; 00070 } 00071 foreach ($dir['files'] as $file) { 00072 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true); 00073 $filename = $file->get_filename(); 00074 $icon = mimeinfo("icon", $filename); 00075 $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon')); 00076 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.html_writer::link($url, $image.' '.$filename).'</div></li>'; 00077 } 00078 $result .= '</ul>'; 00079 00080 return $result; 00081 } 00082 } 00083 00084 class private_files_tree implements renderable { 00085 public $context; 00086 public $dir; 00087 public function __construct() { 00088 global $USER; 00089 $this->context = get_context_instance(CONTEXT_USER, $USER->id); 00090 $fs = get_file_storage(); 00091 $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0); 00092 } 00093 }