Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/files/renderer.php
Go to the documentation of this file.
00001 <?php
00003 //                                                                       //
00004 // This file is part of Moodle - http://moodle.org/                      //
00005 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00006 //                                                                       //
00007 // Moodle is free software: you can redistribute it and/or modify        //
00008 // it under the terms of the GNU General Public License as published by  //
00009 // the Free Software Foundation, either version 3 of the License, or     //
00010 // (at your option) any later version.                                   //
00011 //                                                                       //
00012 // Moodle is distributed in the hope that it will be useful,             //
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00015 // GNU General Public License for more details.                          //
00016 //                                                                       //
00017 // You should have received a copy of the GNU General Public License     //
00018 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
00019 //                                                                       //
00021 
00022 defined('MOODLE_INTERNAL') || die();
00023 
00040 class core_files_renderer extends plugin_renderer_base {
00041 
00042     public function files_tree_viewer(file_info $file_info, array $options = null) {
00043         $tree = new files_tree_viewer($file_info, $options);
00044         return $this->render($tree);
00045     }
00046 
00047     public function render_files_tree_viewer(files_tree_viewer $tree) {
00048         $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
00049 
00050         $html .= $this->output->container_start('coursefilesbreadcrumb');
00051         foreach($tree->path as $path) {
00052             $html .= $path;
00053             $html .= ' / ';
00054         }
00055         $html .= $this->output->container_end();
00056 
00057         $html .= $this->output->box_start();
00058         $table = new html_table();
00059         $table->head = array(get_string('filename', 'backup'), get_string('size'), get_string('modified'));
00060         $table->align = array('left', 'right', 'right');
00061         $table->width = '100%';
00062         $table->data = array();
00063 
00064         foreach ($tree->tree as $file) {
00065             if (!empty($file['isdir'])) {
00066                 $table->data[] = array(
00067                     html_writer::link($file['url'], $this->output->pix_icon('f/folder', 'icon') . ' ' . $file['filename']),
00068                     '',
00069                     $file['filedate'],
00070                     );
00071             } else {
00072                 $table->data[] = array(
00073                     html_writer::link($file['url'], $this->output->pix_icon('f/'.mimeinfo('icon', $file['filename']), get_string('icon')) . ' ' . $file['filename']),
00074                     $file['filesize'],
00075                     $file['filedate'],
00076                     );
00077             }
00078         }
00079 
00080         $html .= html_writer::table($table);
00081         $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get');
00082         $html .= $this->output->box_end();
00083         return $html;
00084     }
00085 }
00086 
00087 
00095 class files_tree_viewer implements renderable {
00096     public $tree;
00097     public $path;
00098     public $context;
00099 
00105     public function __construct(file_info $file_info, array $options = null) {
00106         global $CFG;
00107 
00108         //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
00109         $this->options = (array)$options;
00110         $this->context = $options['context'];
00111 
00112         $this->tree = array();
00113         $children = $file_info->get_children();
00114         $current_file_params = $file_info->get_params();
00115         $parent_info = $file_info->get_parent();
00116         $level = $parent_info;
00117         $this->path = array();
00118         while ($level) {
00119             $params = $level->get_params();
00120             $context = get_context_instance_by_id($params['contextid']);
00121             // $this->context is current context
00122             if ($context->id != $this->context->id or empty($params['filearea'])) {
00123                 break;
00124             }
00125             // unset unused parameters
00126             unset($params['component']);
00127             unset($params['filearea']);
00128             unset($params['filename']);
00129             unset($params['itemid']);
00130             $url = new moodle_url('/files/index.php', $params);
00131             $this->path[] = html_writer::link($url, $level->get_visible_name());
00132             $level = $level->get_parent();
00133         }
00134         $this->path = array_reverse($this->path);
00135         if ($current_file_params['filepath'] != '/') {
00136             $this->path[] = $file_info->get_visible_name();
00137         }
00138 
00139         foreach ($children as $child) {
00140             $filedate = $child->get_timemodified();
00141             $filesize = $child->get_filesize();
00142             $mimetype = $child->get_mimetype();
00143             $params = $child->get_params();
00144             unset($params['component']);
00145             unset($params['filearea']);
00146             unset($params['filename']);
00147             unset($params['itemid']);
00148             $fileitem = array(
00149                     'params'   => $params,
00150                     'filename' => $child->get_visible_name(),
00151                     'filedate' => $filedate ? userdate($filedate) : '',
00152                     'filesize' => $filesize ? display_size($filesize) : ''
00153                     );
00154             $url = new moodle_url('/files/index.php', $params);
00155             if ($child->is_directory()) {
00156                 $fileitem['isdir'] = true;
00157                 $fileitem['url'] = $url->out(false);
00158             } else {
00159                 $fileitem['url'] = $child->get_url();
00160             }
00161             $this->tree[] = $fileitem;
00162         }
00163     }
00164 }
 All Data Structures Namespaces Files Functions Variables Enumerations