Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/renderer.php
Go to the documentation of this file.
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 core_user_renderer extends plugin_renderer_base {
00031 
00036     public function user_files_tree() {
00037         return $this->render(new user_files_tree);
00038     }
00039 
00040     public function render_user_files_tree(user_files_tree $tree) {
00041         if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) {
00042             $html = $this->output->box(get_string('nofilesavailable', 'repository'));
00043         } else {
00044             $htmlid = 'user_files_tree_'.uniqid();
00045             $module = array('name'=>'core_user', 'fullpath'=>'/user/module.js');
00046             $this->page->requires->js_init_call('M.core_user.init_tree', array(false, $htmlid), false, $module);
00047             $html = '<div id="'.$htmlid.'">';
00048             $html .= $this->htmllize_tree($tree, $tree->dir);
00049             $html .= '</div>';
00050         }
00051         return $html;
00052     }
00053 
00057     protected function htmllize_tree($tree, $dir) {
00058         global $CFG;
00059         $yuiconfig = array();
00060         $yuiconfig['type'] = 'html';
00061 
00062         if (empty($dir['subdirs']) and empty($dir['files'])) {
00063             return '';
00064         }
00065         $result = '<ul>';
00066         foreach ($dir['subdirs'] as $subdir) {
00067             $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
00068             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
00069         }
00070         foreach ($dir['files'] as $file) {
00071             $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
00072             $filename = $file->get_filename();
00073             $icon = mimeinfo("icon", $filename);
00074             $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
00075             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
00076         }
00077         $result .= '</ul>';
00078 
00079         return $result;
00080     }
00081 }
00082 
00083 class user_files_tree implements renderable {
00084     public $context;
00085     public $dir;
00086     public function __construct() {
00087         global $USER;
00088         $this->context = get_context_instance(CONTEXT_USER, $USER->id);
00089         $fs = get_file_storage();
00090         $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
00091     }
00092 }
 All Data Structures Namespaces Files Functions Variables Enumerations