Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/wiki/editors/wikifiletable.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
00016 
00029 require_once('HTML/QuickForm/element.php');
00030 require_once($CFG->dirroot.'/lib/filelib.php');
00031 
00032 class MoodleQuickForm_wikifiletable extends HTML_QuickForm_element {
00033 
00034     private $_contextid;
00035     private $_filearea;
00036     private $_fileareaitemid;
00037     private $_fileinfo;
00038     private $_value = array();
00039 
00040     function MoodleQuickForm_wikifiletable($elementName = null, $elementLabel = null, $attributes = null, $fileinfo = null, $format = null) {
00041 
00042         parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
00043         $this->_fileinfo = $fileinfo;
00044         $this->_format = $format;
00045     }
00046 
00047     function onQuickFormEvent($event, $arg, &$caller) {
00048         global $OUTPUT;
00049 
00050         switch ($event) {
00051             case 'addElement':
00052                 $this->_contextid = $arg[3]['contextid'];
00053                 $this->_filearea = $arg[3]['filearea'];
00054                 $this->_fileareaitemid = $arg[3]['itemid'];
00055                 $this->_format = $arg[4];
00056                 break;
00057         }
00058 
00059         return parent::onQuickFormEvent($event, $arg, $caller);
00060     }
00061 
00062     function setName($name) {
00063         $this->updateAttributes(array('name' => $name));
00064     }
00065 
00066     function getName() {
00067         return $this->getAttribute('name');
00068     }
00069 
00070     function setValue($value) {
00071         $this->_value = $value;
00072     }
00073 
00074     function getValue() {
00075         return $this->_value;
00076     }
00077 
00078     function toHtml() {
00079         global $CFG, $OUTPUT;
00080 
00081         $htmltable = new html_table();
00082 
00083         $htmltable->head = array(get_string('deleteupload', 'wiki'), get_string('uploadname', 'wiki'), get_string('uploadactions', 'wiki'));
00084 
00085         $fs = get_file_storage();
00086 
00087         $files = $fs->get_area_files($this->_fileinfo['contextid'], 'mod_wiki', 'attachments', $this->_fileinfo['itemid']); //TODO: verify where this is coming from, all params must be validated (skodak)
00088 
00089         if (count($files) < 2) {
00090             return get_string('noattachments', 'wiki');
00091         }
00092 
00093         //get tags
00094         foreach (array('image', 'attach', 'link') as $tag) {
00095             $tags[$tag] = wiki_parser_get_token($this->_format, $tag);
00096         }
00097 
00098         foreach ($files as $file) {
00099             if (!$file->is_directory()) {
00100                 $checkbox = '<input type="checkbox" name="'.$this->_attributes['name'].'[]" value="'.$file->get_pathnamehash().'"';
00101 
00102                 if (in_array($file->get_pathnamehash(), $this->_value)) {
00103                     $checkbox .= ' checked="checked"';
00104                 }
00105                 $checkbox .= " />";
00106 
00107                 //actions
00108                 $icon = mimeinfo_from_type('icon', $file->get_mimetype());
00109                 $file_url = file_encode_url($CFG->wwwroot.'/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/".$file->get_filename());
00110 
00111                 $action_icons = "";
00112                 if(!empty($tags['attach'])) {
00113                     $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/pdf')->out()."\" alt=\"Attach\" /></a>"; //TODO: localize
00114                 }
00115 
00116                 $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/web')->out()."\" alt=\"Link\" /></a>";
00117 
00118                 if ($icon == 'image') {
00119                     $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/image')->out()."\" alt=\"Image\" /></a>"; //TODO: localize
00120                 }
00121 
00122                 $htmltable->data[] = array($checkbox, '<a href="'.$file_url.'">'.$file->get_filename().'</a>', $action_icons);
00123             }
00124         }
00125 
00126         return html_writer::table($htmltable);
00127     }
00128 
00129     private function printInsertTags($tags, $value) {
00130         return "onclick=\"javascript:insertTags('{$tags[0]}', '{$tags[1]}', '$value');\"";
00131     }
00132 }
00133 
00134 //register wikieditor
00135 MoodleQuickForm::registerElementType('wikifiletable', $CFG->dirroot."/mod/wiki/editors/wikifiletable.php", 'MoodleQuickForm_wikifiletable');
00136 
00137 
 All Data Structures Namespaces Files Functions Variables Enumerations