|
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 00026 class mod_assignment_renderer extends plugin_renderer_base { 00030 public function assignment_files($context, $itemid, $filearea='submission') { 00031 return $this->render(new assignment_files($context, $itemid, $filearea)); 00032 } 00033 00034 public function render_assignment_files(assignment_files $tree) { 00035 $module = array('name'=>'mod_assignment_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview')); 00036 $this->htmlid = 'assignment_files_tree_'.uniqid(); 00037 $this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $this->htmlid)); 00038 $html = '<div id="'.$this->htmlid.'">'; 00039 $html .= $this->htmllize_tree($tree, $tree->dir); 00040 $html .= '</div>'; 00041 00042 if ($tree->portfolioform) { 00043 $html .= $tree->portfolioform; 00044 } 00045 return $html; 00046 } 00047 00051 protected function htmllize_tree($tree, $dir) { 00052 global $CFG; 00053 $yuiconfig = array(); 00054 $yuiconfig['type'] = 'html'; 00055 00056 if (empty($dir['subdirs']) and empty($dir['files'])) { 00057 return ''; 00058 } 00059 00060 $result = '<ul>'; 00061 foreach ($dir['subdirs'] as $subdir) { 00062 $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon')); 00063 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>'; 00064 } 00065 00066 foreach ($dir['files'] as $file) { 00067 $filename = $file->get_filename(); 00068 $icon = mimeinfo("icon", $filename); 00069 if ($CFG->enableplagiarism) { 00070 require_once($CFG->libdir.'/plagiarismlib.php'); 00071 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course)); 00072 } else { 00073 $plagiarsmlinks = ''; 00074 } 00075 $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon')); 00076 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>'; 00077 } 00078 00079 $result .= '</ul>'; 00080 00081 return $result; 00082 } 00083 } 00084 00085 class assignment_files implements renderable { 00086 public $context; 00087 public $dir; 00088 public $portfolioform; 00089 public $cm; 00090 public $course; 00091 public function __construct($context, $itemid, $filearea='submission') { 00092 global $USER, $CFG; 00093 $this->context = $context; 00094 list($context, $course, $cm) = get_context_info_array($context->id); 00095 $this->cm = $cm; 00096 $this->course = $course; 00097 $fs = get_file_storage(); 00098 $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid); 00099 if (!empty($CFG->enableportfolios)) { 00100 require_once($CFG->libdir . '/portfoliolib.php'); 00101 $files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false); 00102 if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) { 00103 $button = new portfolio_add_button(); 00104 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $itemid), '/mod/assignment/locallib.php'); 00105 $button->reset_formats(); 00106 $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); 00107 } 00108 } 00109 $this->preprocess($this->dir, $filearea); 00110 } 00111 public function preprocess($dir, $filearea) { 00112 global $CFG; 00113 foreach ($dir['subdirs'] as $subdir) { 00114 $this->preprocess($subdir, $filearea); 00115 } 00116 foreach ($dir['files'] as $file) { 00117 $file->portfoliobutton = ''; 00118 if (!empty($CFG->enableportfolios)) { 00119 $button = new portfolio_add_button(); 00120 if (has_capability('mod/assignment:exportownsubmission', $this->context)) { 00121 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); 00122 $button->set_format_by_file($file); 00123 $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); 00124 } 00125 } 00126 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true); 00127 $filename = $file->get_filename(); 00128 $file->fileurl = html_writer::link($url, $filename); 00129 } 00130 } 00131 }