[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 23 public function build_editform($item, $feedback, $cm) { 24 global $DB, $CFG; 25 require_once ('textarea_form.php'); 26 27 //get the lastposition number of the feedback_items 28 $position = $item->position; 29 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); 30 if ($position == -1) { 31 $i_formselect_last = $lastposition + 1; 32 $i_formselect_value = $lastposition + 1; 33 $item->position = $lastposition + 1; 34 } else { 35 $i_formselect_last = $lastposition; 36 $i_formselect_value = $item->position; 37 } 38 //the elements for position dropdownlist 39 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); 40 41 $item->presentation = empty($item->presentation) ? '' : $item->presentation; 42 43 $width_and_height = explode('|', $item->presentation); 44 45 if (isset($width_and_height[0]) AND $width_and_height[0] >= 5) { 46 $itemwidth = $width_and_height[0]; 47 } else { 48 $itemwidth = 30; 49 } 50 51 if (isset($width_and_height[1])) { 52 $itemheight = $width_and_height[1]; 53 } else { 54 $itemheight = 5; 55 } 56 $item->itemwidth = $itemwidth; 57 $item->itemheight = $itemheight; 58 59 //all items for dependitem 60 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 61 $commonparams = array('cmid'=>$cm->id, 62 'id'=>isset($item->id) ? $item->id : null, 63 'typ'=>$item->typ, 64 'items'=>$feedbackitems, 65 'feedback'=>$feedback->id); 66 67 //build the form 68 $customdata = array('item' => $item, 69 'common' => $commonparams, 70 'positionlist' => $positionlist, 71 'position' => $position); 72 73 $this->item_form = new feedback_textarea_form('edit_item.php', $customdata); 74 } 75 76 public function save_item() { 77 global $DB; 78 79 if (!$item = $this->item_form->get_data()) { 80 return false; 81 } 82 83 if (isset($item->clone_item) AND $item->clone_item) { 84 $item->id = ''; //to clone this item 85 $item->position++; 86 } 87 88 $item->hasvalue = $this->get_hasvalue(); 89 if (!$item->id) { 90 $item->id = $DB->insert_record('feedback_item', $item); 91 } else { 92 $DB->update_record('feedback_item', $item); 93 } 94 95 return $DB->get_record('feedback_item', array('id'=>$item->id)); 96 } 97 98 /** 99 * Helper function for collected data for exporting to excel 100 * 101 * @param stdClass $item the db-object from feedback_item 102 * @param int $groupid 103 * @param int $courseid 104 * @return stdClass 105 */ 106 protected function get_analysed($item, $groupid = false, $courseid = false) { 107 global $DB; 108 109 $analysed_val = new stdClass(); 110 $analysed_val->data = array(); 111 $analysed_val->name = $item->name; 112 113 $values = feedback_get_group_values($item, $groupid, $courseid); 114 if ($values) { 115 $data = array(); 116 foreach ($values as $value) { 117 $data[] = str_replace("\n", '<br />', $value->value); 118 } 119 $analysed_val->data = $data; 120 } 121 return $analysed_val; 122 } 123 124 public function get_printval($item, $value) { 125 126 if (!isset($value->value)) { 127 return ''; 128 } 129 130 return $value->value; 131 } 132 133 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 134 $values = feedback_get_group_values($item, $groupid, $courseid); 135 if ($values) { 136 echo "<table class=\"analysis itemtype_{$item->typ}\">"; 137 echo '<tr><th colspan="2" align="left">'; 138 echo $itemnr . ' '; 139 if (strval($item->label) !== '') { 140 echo '('. format_string($item->label).') '; 141 } 142 echo format_text($item->name, FORMAT_HTML, array('noclean' => true, 'para' => false)); 143 echo '</th></tr>'; 144 foreach ($values as $value) { 145 $class = strlen(trim($value->value)) ? '' : ' class="isempty"'; 146 echo '<tr'.$class.'>'; 147 echo '<td colspan="2" class="singlevalue">'; 148 echo str_replace("\n", '<br />', $value->value); 149 echo '</td>'; 150 echo '</tr>'; 151 } 152 echo '</table>'; 153 } 154 } 155 156 public function excelprint_item(&$worksheet, $row_offset, 157 $xls_formats, $item, 158 $groupid, $courseid = false) { 159 160 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 161 162 $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2); 163 $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2); 164 $data = $analysed_item->data; 165 if (is_array($data)) { 166 if (isset($data[0])) { 167 $worksheet->write_string($row_offset, 2, htmlspecialchars_decode($data[0], ENT_QUOTES), $xls_formats->value_bold); 168 } 169 $row_offset++; 170 $sizeofdata = count($data); 171 for ($i = 1; $i < $sizeofdata; $i++) { 172 $worksheet->write_string($row_offset, 2, htmlspecialchars_decode($data[$i], ENT_QUOTES), $xls_formats->default); 173 $row_offset++; 174 } 175 } 176 $row_offset++; 177 return $row_offset; 178 } 179 180 /** 181 * Adds an input element to the complete form 182 * 183 * @param stdClass $item 184 * @param mod_feedback_complete_form $form 185 */ 186 public function complete_form_element($item, $form) { 187 $name = $this->get_display_name($item); 188 $inputname = $item->typ . '_' . $item->id; 189 list($cols, $rows) = explode ("|", $item->presentation); 190 $form->add_form_element($item, 191 ['textarea', $inputname, $name, array('rows' => $rows, 'cols' => $cols)]); 192 $form->set_element_type($inputname, PARAM_NOTAGS); 193 } 194 195 public function create_value($data) { 196 return s($data); 197 } 198 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |