[ 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_textarea extends feedback_item_base { 21 protected $type = "textarea"; 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 ('textarea_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) ? '' : $item->presentation; 49 50 $width_and_height = explode('|', $item->presentation); 51 52 if (isset($width_and_height[0]) AND $width_and_height[0] >= 5) { 53 $itemwidth = $width_and_height[0]; 54 } else { 55 $itemwidth = 30; 56 } 57 58 if (isset($width_and_height[1])) { 59 $itemheight = $width_and_height[1]; 60 } else { 61 $itemheight = 5; 62 } 63 $item->itemwidth = $itemwidth; 64 $item->itemheight = $itemheight; 65 66 //all items for dependitem 67 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 68 $commonparams = array('cmid'=>$cm->id, 69 'id'=>isset($item->id) ? $item->id : null, 70 'typ'=>$item->typ, 71 'items'=>$feedbackitems, 72 'feedback'=>$feedback->id); 73 74 //build the form 75 $customdata = array('item' => $item, 76 'common' => $commonparams, 77 'positionlist' => $positionlist, 78 'position' => $position); 79 80 $this->item_form = new feedback_textarea_form('edit_item.php', $customdata); 81 } 82 83 //this function only can used after the call of build_editform() 84 public function show_editform() { 85 $this->item_form->display(); 86 } 87 88 public function is_cancelled() { 89 return $this->item_form->is_cancelled(); 90 } 91 92 public function get_data() { 93 if ($this->item = $this->item_form->get_data()) { 94 return true; 95 } 96 return false; 97 } 98 99 public function save_item() { 100 global $DB; 101 102 if (!$item = $this->item_form->get_data()) { 103 return false; 104 } 105 106 if (isset($item->clone_item) AND $item->clone_item) { 107 $item->id = ''; //to clone this item 108 $item->position++; 109 } 110 111 $item->hasvalue = $this->get_hasvalue(); 112 if (!$item->id) { 113 $item->id = $DB->insert_record('feedback_item', $item); 114 } else { 115 $DB->update_record('feedback_item', $item); 116 } 117 118 return $DB->get_record('feedback_item', array('id'=>$item->id)); 119 } 120 121 122 //liefert eine Struktur ->name, ->data = array(mit Antworten) 123 public function get_analysed($item, $groupid = false, $courseid = false) { 124 global $DB; 125 126 $analysed_val = new stdClass(); 127 $analysed_val->data = array(); 128 $analysed_val->name = $item->name; 129 130 $values = feedback_get_group_values($item, $groupid, $courseid); 131 if ($values) { 132 $data = array(); 133 foreach ($values as $value) { 134 $data[] = str_replace("\n", '<br />', $value->value); 135 } 136 $analysed_val->data = $data; 137 } 138 return $analysed_val; 139 } 140 141 public function get_printval($item, $value) { 142 143 if (!isset($value->value)) { 144 return ''; 145 } 146 147 return $value->value; 148 } 149 150 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 151 $values = feedback_get_group_values($item, $groupid, $courseid); 152 if ($values) { 153 echo '<tr><th colspan="2" align="left">'; 154 echo $itemnr.' ('.$item->label.') '.$item->name; 155 echo '</th></tr>'; 156 foreach ($values as $value) { 157 echo '<tr>'; 158 echo '<td valign="top" align="left">'; 159 echo '- '; 160 echo '</td>'; 161 echo '<td align="left" valign="top">'; 162 echo str_replace("\n", '<br />', $value->value); 163 echo '</td>'; 164 echo '</tr>'; 165 } 166 } 167 } 168 169 public function excelprint_item(&$worksheet, $row_offset, 170 $xls_formats, $item, 171 $groupid, $courseid = false) { 172 173 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 174 175 $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2); 176 $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2); 177 $data = $analysed_item->data; 178 if (is_array($data)) { 179 if (isset($data[0])) { 180 $worksheet->write_string($row_offset, 2, htmlspecialchars_decode($data[0], ENT_QUOTES), $xls_formats->value_bold); 181 } 182 $row_offset++; 183 $sizeofdata = count($data); 184 for ($i = 1; $i < $sizeofdata; $i++) { 185 $worksheet->write_string($row_offset, 2, htmlspecialchars_decode($data[$i], ENT_QUOTES), $xls_formats->default); 186 $row_offset++; 187 } 188 } 189 $row_offset++; 190 return $row_offset; 191 } 192 193 /** 194 * print the item at the edit-page of feedback 195 * 196 * @global object 197 * @param object $item 198 * @return void 199 */ 200 public function print_item_preview($item) { 201 global $OUTPUT, $DB; 202 203 $align = right_to_left() ? 'right' : 'left'; 204 $strrequiredmark = '<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 205 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />'; 206 207 $presentation = explode ("|", $item->presentation); 208 $requiredmark = ($item->required == 1) ? $strrequiredmark : ''; 209 //print the question and label 210 $inputname = $item->typ . '_' . $item->id; 211 echo '<div class="feedback_item_label_'.$align.'">'; 212 echo '<label for="'. $inputname .'">'; 213 echo '('.$item->label.') '; 214 echo format_text($item->name.$requiredmark, true, false, false); 215 if ($item->dependitem) { 216 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { 217 echo ' <span class="feedback_depend">'; 218 echo '('.$dependitem->label.'->'.$item->dependvalue.')'; 219 echo '</span>'; 220 } 221 } 222 echo '</label>'; 223 echo '</div>'; 224 225 //print the presentation 226 echo '<div class="feedback_item_presentation_'.$align.'">'; 227 echo '<span class="feedback_item_textarea">'; 228 echo '<textarea id="'.$inputname.'" '. 229 'name="'.$inputname.'" '. 230 'cols="'.$presentation[0].'" '. 231 'rows="'.$presentation[1].'">'; 232 echo '</textarea>'; 233 echo '</span>'; 234 echo '</div>'; 235 } 236 237 /** 238 * print the item at the complete-page of feedback 239 * 240 * @global object 241 * @param object $item 242 * @param string $value 243 * @param bool $highlightrequire 244 * @return void 245 */ 246 public function print_item_complete($item, $value = '', $highlightrequire = false) { 247 global $OUTPUT; 248 $align = right_to_left() ? 'right' : 'left'; 249 $strrequiredmark = '<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 250 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />'; 251 252 $presentation = explode ("|", $item->presentation); 253 $requiredmark = ($item->required == 1) ? $strrequiredmark :''; 254 255 //print the question and label 256 $inputname = $item->typ . '_' . $item->id; 257 echo '<div class="feedback_item_label_'.$align.'">'; 258 echo '<label for="'. $inputname .'">'; 259 echo format_text($item->name . $requiredmark, true, false, false); 260 if ($highlightrequire AND $item->required AND strval($value) == '') { 261 echo '<br class="error"><span id="id_error_'.$inputname.'" class="error"> '.get_string('err_required', 'form'). 262 '</span><br id="id_error_break_'.$inputname.'" class="error" >'; 263 } 264 echo '</label>'; 265 echo '</div>'; 266 267 //print the presentation 268 echo '<div class="feedback_item_presentation_'.$align.'">'; 269 echo '<span class="feedback_item_textarea">'; 270 echo '<textarea id="'.$inputname.'" '. 271 'name="'.$inputname.'" '. 272 'cols="'.$presentation[0].'" '. 273 'rows="'.$presentation[1].'">'; 274 echo $value; 275 echo '</textarea>'; 276 echo '</span>'; 277 echo '</div>'; 278 } 279 280 /** 281 * print the item at the complete-page of feedback 282 * 283 * @global object 284 * @param object $item 285 * @param string $value 286 * @return void 287 */ 288 public function print_item_show_value($item, $value = '') { 289 global $OUTPUT; 290 $align = right_to_left() ? 'right' : 'left'; 291 $strrequiredmark = '<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'. 292 get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />'; 293 294 $presentation = explode ("|", $item->presentation); 295 $requiredmark = ($item->required == 1) ? $strrequiredmark : ''; 296 297 //print the question and label 298 echo '<div class="feedback_item_label_'.$align.'">'; 299 echo '('.$item->label.') '; 300 echo format_text($item->name . $requiredmark, true, false, false); 301 echo '</div>'; 302 303 //print the presentation 304 echo $OUTPUT->box_start('generalbox boxalign'.$align); 305 echo $value ? str_replace("\n", '<br />', $value) : ' '; 306 echo $OUTPUT->box_end(); 307 } 308 309 public function check_value($value, $item) { 310 //if the item is not required, so the check is true if no value is given 311 if ((!isset($value) OR $value == '') AND $item->required != 1) { 312 return true; 313 } 314 if ($value == "") { 315 return false; 316 } 317 return true; 318 } 319 320 public function create_value($data) { 321 $data = s($data); 322 return $data; 323 } 324 325 //compares the dbvalue with the dependvalue 326 //dbvalue is the value put in by the user 327 //dependvalue is the value that is compared 328 public function compare_value($item, $dbvalue, $dependvalue) { 329 if ($dbvalue == $dependvalue) { 330 return true; 331 } 332 return false; 333 } 334 335 public function get_presentation($data) { 336 return $data->itemwidth.'|'.$data->itemheight; 337 } 338 339 public function get_hasvalue() { 340 return 1; 341 } 342 343 public function can_switch_require() { 344 return true; 345 } 346 347 public function value_type() { 348 return PARAM_RAW; 349 } 350 351 public function clean_input_value($value) { 352 return s($value); 353 } 354 }
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 |