3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * A custom renderer class that extends the plugin_renderer_base and
20 * is used by the assignment module.
22 * @package mod-assignment
23 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 class mod_assignment_renderer extends plugin_renderer_base {
31 public function assignment_files($context, $itemid) {
32 return $this->render(new assignment_files($context, $itemid));
35 public function render_assignment_files(assignment_files $tree) {
36 $module = array('name'=>'mod_assignment_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview'));
37 $htmlid = 'assignment_files_tree_'.uniqid();
38 $this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $htmlid));
39 $html = '<div id="'.$htmlid.'">';
40 $html .= $this->htmllize_tree($tree, $tree->dir);
46 * Internal function - creates htmls structure suitable for YUI tree.
48 protected function htmllize_tree($tree, $dir) {
51 $yuiconfig['type'] = 'html';
53 if (empty($dir['subdirs']) and empty($dir['files'])) {
57 foreach ($dir['subdirs'] as $subdir) {
58 $image = $this->output->pix_icon("/f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
59 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
61 foreach ($dir['files'] as $file) {
62 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_assignment/submission/'.$file->get_itemid().'/'.$file->get_filepath().$file->get_filename(), true);
63 $filename = $file->get_filename();
64 $icon = substr(mimeinfo("icon", $filename), 0, -4);
65 $image = $this->output->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));
66 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
74 class assignment_files implements renderable {
77 public function __construct($context, $itemid) {
79 $this->context = $context;
80 $fs = get_file_storage();
81 $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', 'submission', $itemid);