|
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 00020 class feedback_item_textarea extends feedback_item_base { 00021 protected $type = "textarea"; 00022 private $commonparams; 00023 private $item_form; 00024 private $item; 00025 00026 public function init() { 00027 00028 } 00029 00030 public function build_editform($item, $feedback, $cm) { 00031 global $DB, $CFG; 00032 require_once('textarea_form.php'); 00033 00034 //get the lastposition number of the feedback_items 00035 $position = $item->position; 00036 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); 00037 if ($position == -1) { 00038 $i_formselect_last = $lastposition + 1; 00039 $i_formselect_value = $lastposition + 1; 00040 $item->position = $lastposition + 1; 00041 } else { 00042 $i_formselect_last = $lastposition; 00043 $i_formselect_value = $item->position; 00044 } 00045 //the elements for position dropdownlist 00046 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); 00047 00048 $item->presentation = empty($item->presentation) ? '' : $item->presentation; 00049 00050 $width_and_height = explode('|', $item->presentation); 00051 00052 if (isset($width_and_height[0]) AND $width_and_height[0] >= 5) { 00053 $itemwidth = $width_and_height[0]; 00054 } else { 00055 $itemwidth = 30; 00056 } 00057 00058 if (isset($width_and_height[1])) { 00059 $itemheight = $width_and_height[1]; 00060 } else { 00061 $itemheight = 5; 00062 } 00063 $item->itemwidth = $itemwidth; 00064 $item->itemheight = $itemheight; 00065 00066 //all items for dependitem 00067 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 00068 $commonparams = array('cmid'=>$cm->id, 00069 'id'=>isset($item->id) ? $item->id : null, 00070 'typ'=>$item->typ, 00071 'items'=>$feedbackitems, 00072 'feedback'=>$feedback->id); 00073 00074 //build the form 00075 $customdata = array('item' => $item, 00076 'common' => $commonparams, 00077 'positionlist' => $positionlist, 00078 'position' => $position); 00079 00080 $this->item_form = new feedback_textarea_form('edit_item.php', $customdata); 00081 } 00082 00083 //this function only can used after the call of build_editform() 00084 public function show_editform() { 00085 $this->item_form->display(); 00086 } 00087 00088 public function is_cancelled() { 00089 return $this->item_form->is_cancelled(); 00090 } 00091 00092 public function get_data() { 00093 if ($this->item = $this->item_form->get_data()) { 00094 return true; 00095 } 00096 return false; 00097 } 00098 00099 public function save_item() { 00100 global $DB; 00101 00102 if (!$item = $this->item_form->get_data()) { 00103 return false; 00104 } 00105 00106 if (isset($item->clone_item) AND $item->clone_item) { 00107 $item->id = ''; //to clone this item 00108 $item->position++; 00109 } 00110 00111 $item->hasvalue = $this->get_hasvalue(); 00112 if (!$item->id) { 00113 $item->id = $DB->insert_record('feedback_item', $item); 00114 } else { 00115 $DB->update_record('feedback_item', $item); 00116 } 00117 00118 return $DB->get_record('feedback_item', array('id'=>$item->id)); 00119 } 00120 00121 00122 //liefert eine Struktur ->name, ->data = array(mit Antworten) 00123 public function get_analysed($item, $groupid = false, $courseid = false) { 00124 global $DB; 00125 00126 $analysed_val = null; 00127 $analysed_val->data = array(); 00128 $analysed_val->name = $item->name; 00129 00130 $values = feedback_get_group_values($item, $groupid, $courseid); 00131 if ($values) { 00132 $data = array(); 00133 foreach ($values as $value) { 00134 $data[] = str_replace("\n", '<br />', $value->value); 00135 } 00136 $analysed_val->data = $data; 00137 } 00138 return $analysed_val; 00139 } 00140 00141 public function get_printval($item, $value) { 00142 00143 if (!isset($value->value)) { 00144 return ''; 00145 } 00146 00147 return $value->value; 00148 } 00149 00150 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 00151 $values = feedback_get_group_values($item, $groupid, $courseid); 00152 if ($values) { 00153 echo '<tr><th colspan="2" align="left">'; 00154 echo $itemnr.' ('.$item->label.') '.$item->name; 00155 echo '</th></tr>'; 00156 foreach ($values as $value) { 00157 echo '<tr>'; 00158 echo '<td valign="top" align="left">'; 00159 echo '- '; 00160 echo '</td>'; 00161 echo '<td align="left" valign="top">'; 00162 echo str_replace("\n", '<br />', $value->value); 00163 echo '</td>'; 00164 echo '</tr>'; 00165 } 00166 } 00167 } 00168 00169 public function excelprint_item(&$worksheet, $row_offset, 00170 $xls_formats, $item, 00171 $groupid, $courseid = false) { 00172 00173 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 00174 00175 $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2); 00176 $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2); 00177 $data = $analysed_item->data; 00178 if (is_array($data)) { 00179 if (isset($data[0])) { 00180 $worksheet->write_string($row_offset, 2, $data[0], $xls_formats->value_bold); 00181 } 00182 $row_offset++; 00183 $sizeofdata = count($data); 00184 for ($i = 1; $i < $sizeofdata; $i++) { 00185 $worksheet->write_string($row_offset, 2, $data[$i], $xls_formats->default); 00186 $row_offset++; 00187 } 00188 } 00189 $row_offset++; 00190 return $row_offset; 00191 } 00192 00200 public function print_item_preview($item) { 00201 global $OUTPUT, $DB; 00202 00203 $align = right_to_left() ? 'right' : 'left'; 00204 $str_required_mark = '<span class="feedback_required_mark">*</span>'; 00205 00206 $presentation = explode ("|", $item->presentation); 00207 $requiredmark = ($item->required == 1) ? $str_required_mark : ''; 00208 //print the question and label 00209 echo '<div class="feedback_item_label_'.$align.'">'; 00210 echo '('.$item->label.') '; 00211 echo format_text($item->name.$requiredmark, true, false, false); 00212 if ($item->dependitem) { 00213 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { 00214 echo ' <span class="feedback_depend">'; 00215 echo '('.$dependitem->label.'->'.$item->dependvalue.')'; 00216 echo '</span>'; 00217 } 00218 } 00219 echo '</div>'; 00220 00221 //print the presentation 00222 echo '<div class="feedback_item_presentation_'.$align.'">'; 00223 echo '<span class="feedback_item_textarea">'; 00224 echo '<textarea name="'.$item->typ.'_'.$item->id.'" '. 00225 'cols="'.$presentation[0].'" '. 00226 'rows="'.$presentation[1].'">'; 00227 echo '</textarea>'; 00228 echo '</span>'; 00229 echo '</div>'; 00230 } 00231 00241 public function print_item_complete($item, $value = '', $highlightrequire = false) { 00242 global $OUTPUT; 00243 $align = right_to_left() ? 'right' : 'left'; 00244 $str_required_mark = '<span class="feedback_required_mark">*</span>'; 00245 00246 $presentation = explode ("|", $item->presentation); 00247 if ($highlightrequire AND $item->required AND strval($value) == '') { 00248 $highlight = ' missingrequire'; 00249 } else { 00250 $highlight = ''; 00251 } 00252 $requiredmark = ($item->required == 1) ? $str_required_mark :''; 00253 00254 //print the question and label 00255 echo '<div class="feedback_item_label_'.$align.$highlight.'">'; 00256 echo format_text($item->name . $requiredmark, true, false, false); 00257 echo '</div>'; 00258 00259 //print the presentation 00260 echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; 00261 echo '<span class="feedback_item_textarea">'; 00262 echo '<textarea name="'.$item->typ.'_'.$item->id.'" '. 00263 'cols="'.$presentation[0].'" '. 00264 'rows="'.$presentation[1].'">'; 00265 echo ($value ? htmlspecialchars($value) : ''); 00266 echo '</textarea>'; 00267 echo '</span>'; 00268 echo '</div>'; 00269 } 00270 00279 public function print_item_show_value($item, $value = '') { 00280 global $OUTPUT; 00281 $align = right_to_left() ? 'right' : 'left'; 00282 $str_required_mark = '<span class="feedback_required_mark">*</span>'; 00283 00284 $presentation = explode ("|", $item->presentation); 00285 $requiredmark = ($item->required == 1) ? $str_required_mark : ''; 00286 00287 //print the question and label 00288 echo '<div class="feedback_item_label_'.$align.'">'; 00289 echo '('.$item->label.') '; 00290 echo format_text($item->name . $requiredmark, true, false, false); 00291 echo '</div>'; 00292 00293 //print the presentation 00294 echo $OUTPUT->box_start('generalbox boxalign'.$align); 00295 echo $value ? str_replace("\n", '<br />', $value) : ' '; 00296 echo $OUTPUT->box_end(); 00297 } 00298 00299 public function check_value($value, $item) { 00300 //if the item is not required, so the check is true if no value is given 00301 if ((!isset($value) OR $value == '') AND $item->required != 1) { 00302 return true; 00303 } 00304 if ($value == "") { 00305 return false; 00306 } 00307 return true; 00308 } 00309 00310 public function create_value($data) { 00311 $data = clean_text($data); 00312 return $data; 00313 } 00314 00315 //compares the dbvalue with the dependvalue 00316 //dbvalue is the value put in by the user 00317 //dependvalue is the value that is compared 00318 public function compare_value($item, $dbvalue, $dependvalue) { 00319 if ($dbvalue == $dependvalue) { 00320 return true; 00321 } 00322 return false; 00323 } 00324 00325 public function get_presentation($data) { 00326 return $data->itemwidth.'|'.$data->itemheight; 00327 } 00328 00329 public function get_hasvalue() { 00330 return 1; 00331 } 00332 00333 public function can_switch_require() { 00334 return true; 00335 } 00336 }