[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 defined('MOODLE_INTERNAL') OR die('not allowed'); 18 require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); 19 20 class feedback_item_info extends feedback_item_base { 21 protected $type = "info"; 22 private $commonparams; 23 private $item_form; 24 private $item; 25 26 public function init() { 27 28 } 29 30 public function build_editform($item, $feedback, $cm) { 31 global $DB, $CFG; 32 require_once ('info_form.php'); 33 34 //get the lastposition number of the feedback_items 35 $position = $item->position; 36 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); 37 if ($position == -1) { 38 $i_formselect_last = $lastposition + 1; 39 $i_formselect_value = $lastposition + 1; 40 $item->position = $lastposition + 1; 41 } else { 42 $i_formselect_last = $lastposition; 43 $i_formselect_value = $item->position; 44 } 45 //the elements for position dropdownlist 46 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); 47 48 $item->presentation = empty($item->presentation) ? 1 : $item->presentation; 49 $item->required = 0; 50 51 //all items for dependitem 52 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 53 $commonparams = array('cmid'=>$cm->id, 54 'id'=>isset($item->id) ? $item->id : null, 55 'typ'=>$item->typ, 56 'items'=>$feedbackitems, 57 'feedback'=>$feedback->id); 58 59 //build the form 60 $this->item_form = new feedback_info_form('edit_item.php', 61 array('item'=>$item, 62 'common'=>$commonparams, 63 'positionlist'=>$positionlist, 64 'position' => $position)); 65 } 66 67 //this function only can used after the call of build_editform() 68 public function show_editform() { 69 $this->item_form->display(); 70 } 71 72 public function is_cancelled() { 73 return $this->item_form->is_cancelled(); 74 } 75 76 public function get_data() { 77 if ($this->item = $this->item_form->get_data()) { 78 return true; 79 } 80 return false; 81 } 82 83 public function save_item() { 84 global $DB; 85 86 if (!$item = $this->item_form->get_data()) { 87 return false; 88 } 89 90 if (isset($item->clone_item) AND $item->clone_item) { 91 $item->id = ''; //to clone this item 92 $item->position++; 93 } 94 95 $item->hasvalue = $this->get_hasvalue(); 96 if (!$item->id) { 97 $item->id = $DB->insert_record('feedback_item', $item); 98 } else { 99 $DB->update_record('feedback_item', $item); 100 } 101 102 return $DB->get_record('feedback_item', array('id'=>$item->id)); 103 } 104 105 //liefert eine Struktur ->name, ->data = array(mit Antworten) 106 public function get_analysed($item, $groupid = false, $courseid = false) { 107 108 $presentation = $item->presentation; 109 $analysed_val = new stdClass(); 110 $analysed_val->data = null; 111 $analysed_val->name = $item->name; 112 $values = feedback_get_group_values($item, $groupid, $courseid); 113 if ($values) { 114 $data = array(); 115 foreach ($values as $value) { 116 $datavalue = new stdClass(); 117 118 switch($presentation) { 119 case 1: 120 $datavalue->value = $value->value; 121 $datavalue->show = userdate($datavalue->value); 122 break; 123 case 2: 124 $datavalue->value = $value->value; 125 $datavalue->show = $datavalue->value; 126 break; 127 case 3: 128 $datavalue->value = $value->value; 129 $datavalue->show = $datavalue->value; 130 break; 131 } 132 133 $data[] = $datavalue; 134 } 135 $analysed_val->data = $data; 136 } 137 return $analysed_val; 138 } 139 140 public function get_printval($item, $value) { 141 142 if (!isset($value->value)) { 143 return ''; 144 } 145 return userdate($value->value); 146 } 147 148 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 149 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 150 $data = $analysed_item->data; 151 if (is_array($data)) { 152 echo '<tr><th colspan="2" align="left">'; 153 echo $itemnr.' ('.$item->label.') '.$item->name; 154 echo '</th></tr>'; 155 $sizeofdata = count($data); 156 for ($i = 0; $i < $sizeofdata; $i++) { 157 echo '<tr><td colspan="2" valign="top" align="left">- '; 158 echo str_replace("\n", '<br />', $data[$i]->show); 159 echo '</td></tr>'; 160 } 161 } 162 } 163 164 public function excelprint_item(&$worksheet, $row_offset, 165 $xls_formats, $item, 166 $groupid, $courseid = false) { 167 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 168 169 $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2); 170 $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2); 171 $data = $analysed_item->data; 172 if (is_array($data)) { 173 $worksheet->write_string($row_offset, 2, $data[0]->show, $xls_formats->value_bold); 174 $row_offset++; 175 $sizeofdata = count($data); 176 for ($i = 1; $i < $sizeofdata; $i++) { 177 $worksheet->write_string($row_offset, 2, $data[$i]->show, $xls_formats->default); 178 $row_offset++; 179 } 180 } 181 $row_offset++; 182 return $row_offset; 183 } 184 185 /** 186 * print the item at the edit-page of feedback 187 * 188 * @global object 189 * @param object $item 190 * @return void 191 */ 192 public function print_item_preview($item) { 193 global $USER, $DB, $OUTPUT; 194 195 $align = right_to_left() ? 'right' : 'left'; 196 $presentation = $item->presentation; 197 $requiredmark = ($item->required == 1)?'<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 198 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />':''; 199 200 if ($item->feedback) { 201 $courseid = $DB->get_field('feedback', 'course', array('id'=>$item->feedback)); 202 } else { // the item must be a template item 203 $cmid = required_param('id', PARAM_INT); 204 $courseid = $DB->get_field('course_modules', 'course', array('id'=>$cmid)); 205 } 206 if (!$course = $DB->get_record('course', array('id'=>$courseid))) { 207 print_error('error'); 208 } 209 if ($course->id !== SITEID) { 210 $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category)); 211 } else { 212 $coursecategory = false; 213 } 214 switch($presentation) { 215 case 1: 216 $itemvalue = time(); 217 $itemshowvalue = userdate($itemvalue); 218 break; 219 case 2: 220 $coursecontext = context_course::instance($course->id); 221 $itemvalue = format_string($course->shortname, 222 true, 223 array('context' => $coursecontext)); 224 225 $itemshowvalue = $itemvalue; 226 break; 227 case 3: 228 if ($coursecategory) { 229 $category_context = context_coursecat::instance($coursecategory->id); 230 $itemvalue = format_string($coursecategory->name, 231 true, 232 array('context' => $category_context)); 233 234 $itemshowvalue = $itemvalue; 235 } else { 236 $itemvalue = ''; 237 $itemshowvalue = ''; 238 } 239 break; 240 } 241 242 //print the question and label 243 echo '<div class="feedback_item_label_'.$align.'">'; 244 echo '('.$item->label.') '; 245 echo format_text($item->name.$requiredmark, true, false, false); 246 if ($item->dependitem) { 247 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { 248 echo ' <span class="feedback_depend">'; 249 echo '('.$dependitem->label.'->'.$item->dependvalue.')'; 250 echo '</span>'; 251 } 252 } 253 echo '</div>'; 254 //print the presentation 255 echo '<div class="feedback_item_presentation_'.$align.'">'; 256 echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; 257 echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; 258 echo '</div>'; 259 } 260 261 /** 262 * print the item at the complete-page of feedback 263 * 264 * @global object 265 * @param object $item 266 * @param string $value 267 * @param bool $highlightrequire 268 * @return void 269 */ 270 public function print_item_complete($item, $value = '', $highlightrequire = false) { 271 global $USER, $DB, $OUTPUT; 272 $align = right_to_left() ? 'right' : 'left'; 273 274 $presentation = $item->presentation; 275 if ($highlightrequire AND $item->required AND strval($value) == '') { 276 $highlight = 'error'; 277 } else { 278 $highlight = ''; 279 } 280 $requiredmark = ($item->required == 1)?'<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 281 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />':''; 282 283 $feedback = $DB->get_record('feedback', array('id'=>$item->feedback)); 284 285 if ($courseid = optional_param('courseid', 0, PARAM_INT)) { 286 $course = $DB->get_record('course', array('id'=>$courseid)); 287 } else { 288 $course = $DB->get_record('course', array('id'=>$feedback->course)); 289 } 290 291 if ($course->id !== SITEID) { 292 $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category)); 293 } else { 294 $coursecategory = false; 295 } 296 297 switch($presentation) { 298 case 1: 299 if ($feedback->anonymous == FEEDBACK_ANONYMOUS_YES) { 300 $itemvalue = 0; 301 $itemshowvalue = '-'; 302 } else { 303 $itemvalue = time(); 304 $itemshowvalue = userdate($itemvalue); 305 } 306 break; 307 case 2: 308 $coursecontext = context_course::instance($course->id); 309 $itemvalue = format_string($course->shortname, 310 true, 311 array('context' => $coursecontext)); 312 313 $itemshowvalue = $itemvalue; 314 break; 315 case 3: 316 if ($coursecategory) { 317 $category_context = context_coursecat::instance($coursecategory->id); 318 $itemvalue = format_string($coursecategory->name, 319 true, 320 array('context' => $category_context)); 321 322 $itemshowvalue = $itemvalue; 323 } else { 324 $itemvalue = ''; 325 $itemshowvalue = ''; 326 } 327 break; 328 } 329 330 //print the question and label 331 echo '<div class="feedback_item_label_'.$align.'">'; 332 echo '<span class="'.$highlight.'">'; 333 echo format_text($item->name.$requiredmark, true, false, false); 334 echo '</span>'; 335 echo '</div>'; 336 337 //print the presentation 338 echo '<div class="feedback_item_presentation_'.$align.'">'; 339 echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; 340 echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; 341 echo '</div>'; 342 } 343 344 /** 345 * print the item at the complete-page of feedback 346 * 347 * @global object 348 * @param object $item 349 * @param string $value 350 * @return void 351 */ 352 public function print_item_show_value($item, $value = '') { 353 global $USER, $DB, $OUTPUT; 354 $align = right_to_left() ? 'right' : 'left'; 355 356 $presentation = $item->presentation; 357 $requiredmark = ($item->required == 1)?'<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 358 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />':''; 359 360 if ($presentation == 1) { 361 $value = $value ? userdate($value) : ' '; 362 } 363 364 //print the question and label 365 echo '<div class="feedback_item_label_'.$align.'">'; 366 echo '('.$item->label.') '; 367 echo format_text($item->name . $requiredmark, true, false, false); 368 echo '</div>'; 369 370 //print the presentation 371 echo $OUTPUT->box_start('generalbox boxalign'.$align); 372 echo $value; 373 echo $OUTPUT->box_end(); 374 } 375 376 public function check_value($value, $item) { 377 return true; 378 } 379 380 public function create_value($data) { 381 $data = clean_text($data); 382 return $data; 383 } 384 385 //compares the dbvalue with the dependvalue 386 //the values can be the shortname of a course or the category name 387 //the date is not compareable :(. 388 public function compare_value($item, $dbvalue, $dependvalue) { 389 if ($dbvalue == $dependvalue) { 390 return true; 391 } 392 return false; 393 } 394 395 public function get_presentation($data) { 396 return $data->infotype; 397 } 398 399 public function get_hasvalue() { 400 return 1; 401 } 402 403 public function can_switch_require() { 404 return false; 405 } 406 407 public function value_type() { 408 return PARAM_TEXT; 409 } 410 411 public function clean_input_value($value) { 412 return clean_param($value, $this->value_type()); 413 } 414 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |