|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00017 defined('MOODLE_INTERNAL') OR die('not allowed'); 00018 require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); 00019 require_once($CFG->libdir.'/formslib.php'); 00020 00021 class feedback_item_label extends feedback_item_base { 00022 protected $type = "label"; 00023 private $presentationoptions = null; 00024 private $commonparams; 00025 private $item_form; 00026 private $context; 00027 private $item; 00028 00029 public function init() { 00030 global $CFG; 00031 $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 00032 'trusttext'=>true); 00033 00034 } 00035 00036 public function build_editform($item, $feedback, $cm) { 00037 global $DB, $CFG; 00038 require_once('label_form.php'); 00039 00040 //get the lastposition number of the feedback_items 00041 $position = $item->position; 00042 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); 00043 if ($position == -1) { 00044 $i_formselect_last = $lastposition + 1; 00045 $i_formselect_value = $lastposition + 1; 00046 $item->position = $lastposition + 1; 00047 } else { 00048 $i_formselect_last = $lastposition; 00049 $i_formselect_value = $item->position; 00050 } 00051 //the elements for position dropdownlist 00052 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); 00053 00054 //all items for dependitem 00055 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 00056 $commonparams = array('cmid'=>$cm->id, 00057 'id'=>isset($item->id) ? $item->id : null, 00058 'typ'=>$item->typ, 00059 'items'=>$feedbackitems, 00060 'feedback'=>$feedback->id); 00061 00062 $this->context = get_context_instance(CONTEXT_MODULE, $cm->id); 00063 00064 //preparing the editor for new file-api 00065 $item->presentationformat = FORMAT_HTML; 00066 $item->presentationtrust = 1; 00067 00068 // Append editor context to presentation options, giving preference to existing context. 00069 $this->presentationoptions = array_merge(array('context' => $this->context), 00070 $this->presentationoptions); 00071 00072 $item = file_prepare_standard_editor($item, 00073 'presentation', //name of the form element 00074 $this->presentationoptions, 00075 $this->context, 00076 'mod_feedback', 00077 'item', //the filearea 00078 $item->id); 00079 00080 //build the form 00081 $customdata = array('item' => $item, 00082 'common' => $commonparams, 00083 'positionlist' => $positionlist, 00084 'position' => $position, 00085 'presentationoptions' => $this->presentationoptions); 00086 00087 $this->item_form = new feedback_label_form('edit_item.php', $customdata); 00088 } 00089 00090 //this function only can used after the call of build_editform() 00091 public function show_editform() { 00092 $this->item_form->display(); 00093 } 00094 00095 public function is_cancelled() { 00096 return $this->item_form->is_cancelled(); 00097 } 00098 00099 public function get_data() { 00100 if ($this->item = $this->item_form->get_data()) { 00101 return true; 00102 } 00103 return false; 00104 } 00105 00106 public function save_item() { 00107 global $DB; 00108 00109 if (!$item = $this->item_form->get_data()) { 00110 return false; 00111 } 00112 00113 if (isset($item->clone_item) AND $item->clone_item) { 00114 $item->id = ''; //to clone this item 00115 $item->position++; 00116 } 00117 00118 $item->presentation = ''; 00119 00120 $item->hasvalue = $this->get_hasvalue(); 00121 if (!$item->id) { 00122 $item->id = $DB->insert_record('feedback_item', $item); 00123 } else { 00124 $DB->update_record('feedback_item', $item); 00125 } 00126 00127 $item = file_postupdate_standard_editor($item, 00128 'presentation', 00129 $this->presentationoptions, 00130 $this->context, 00131 'mod_feedback', 00132 'item', 00133 $item->id); 00134 00135 $DB->update_record('feedback_item', $item); 00136 00137 return $DB->get_record('feedback_item', array('id'=>$item->id)); 00138 } 00139 00140 public function print_item($item) { 00141 global $DB, $CFG; 00142 00143 require_once($CFG->libdir . '/filelib.php'); 00144 00145 //is the item a template? 00146 if (!$item->feedback AND $item->template) { 00147 $template = $DB->get_record('feedback_template', array('id'=>$item->template)); 00148 if ($template->ispublic) { 00149 $context = get_system_context(); 00150 } else { 00151 $context = get_context_instance(CONTEXT_COURSE, $template->course); 00152 } 00153 $filearea = 'template'; 00154 } else { 00155 $cm = get_coursemodule_from_instance('feedback', $item->feedback); 00156 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00157 $filearea = 'item'; 00158 } 00159 00160 $item->presentationformat = FORMAT_HTML; 00161 $item->presentationtrust = 1; 00162 00163 $output = file_rewrite_pluginfile_urls($item->presentation, 00164 'pluginfile.php', 00165 $context->id, 00166 'mod_feedback', 00167 $filearea, 00168 $item->id); 00169 00170 echo format_text($output, FORMAT_HTML, array('overflowdiv'=>true)); 00171 } 00172 00180 public function print_item_preview($item) { 00181 global $OUTPUT, $DB; 00182 00183 if ($item->dependitem) { 00184 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { 00185 echo ' <span class="feedback_depend">'; 00186 echo '('.$dependitem->label.'->'.$item->dependvalue.')'; 00187 echo '</span>'; 00188 } 00189 } 00190 $this->print_item($item); 00191 } 00192 00202 public function print_item_complete($item, $value = '', $highlightrequire = false) { 00203 $this->print_item($item); 00204 } 00205 00214 public function print_item_show_value($item, $value = '') { 00215 $this->print_item($item); 00216 } 00217 00218 public function create_value($data) { 00219 return false; 00220 } 00221 00222 public function compare_value($item, $dbvalue, $dependvalue) { 00223 return false; 00224 } 00225 00226 //used by create_item and update_item functions, 00227 //when provided $data submitted from feedback_show_edit 00228 public function get_presentation($data) { 00229 } 00230 00231 public function postupdate($item) { 00232 global $DB; 00233 00234 $context = get_context_instance(CONTEXT_MODULE, $item->cmid); 00235 $item = file_postupdate_standard_editor($item, 00236 'presentation', 00237 $this->presentationoptions, 00238 $context, 00239 'mod_feedback', 00240 'item', 00241 $item->id); 00242 00243 $DB->update_record('feedback_item', $item); 00244 return $item->id; 00245 } 00246 00247 public function get_hasvalue() { 00248 return 0; 00249 } 00250 00251 public function can_switch_require() { 00252 return false; 00253 } 00254 00255 public function check_value($value, $item) { 00256 } 00257 00258 public function excelprint_item(&$worksheet, 00259 $row_offset, 00260 $xls_formats, 00261 $item, 00262 $groupid, 00263 $courseid = false) { 00264 } 00265 00266 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 00267 } 00268 public function get_printval($item, $value) { 00269 } 00270 public function get_analysed($item, $groupid = false, $courseid = false) { 00271 } 00272 }