. /** * A custom renderer class that extends the plugin_renderer_base and * is used by the assignment module. * * @package mod-assignment * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class mod_assignment_renderer extends plugin_renderer_base { /** * @return string */ public function assignment_files($context, $itemid, $filearea='submission') { return $this->render(new assignment_files($context, $itemid, $filearea)); } public function render_assignment_files(assignment_files $tree) { $module = array('name'=>'mod_assignment_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview')); $this->htmlid = 'assignment_files_tree_'.uniqid(); $this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $this->htmlid)); $html = '
'; $html .= $this->htmllize_tree($tree, $tree->dir); $html .= '
'; if ($tree->portfolioform) { $html .= $tree->portfolioform; } return $html; } /** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; $yuiconfig = array(); $yuiconfig['type'] = 'html'; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = ''; return $result; } } class assignment_files implements renderable { public $context; public $dir; public $portfolioform; public $cm; public $course; public function __construct($context, $itemid, $filearea='submission') { global $USER, $CFG; $this->context = $context; list($context, $course, $cm) = get_context_info_array($context->id); $this->cm = $cm; $this->course = $course; $fs = get_file_storage(); $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid); if (!empty($CFG->enableportfolios)) { require_once($CFG->libdir . '/portfoliolib.php'); $files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false); if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button = new portfolio_add_button(); $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $itemid), '/mod/assignment/locallib.php'); $button->reset_formats(); $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); } } $this->preprocess($this->dir, $filearea); } public function preprocess($dir, $filearea) { global $CFG; foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; if (!empty($CFG->enableportfolios)) { $button = new portfolio_add_button(); if (has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename); } } }