Commit | Line | Data |
---|---|---|
1adbd2c3 | 1 | <?php |
01910dff | 2 | defined('MOODLE_INTERNAL') OR die('not allowed'); |
ed93c78b | 3 | require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); |
4 | ||
5 | class feedback_item_info extends feedback_item_base { | |
6 | var $type = "info"; | |
a59ff6b0 AG |
7 | var $commonparams; |
8 | var $item_form; | |
9 | var $item; | |
10 | ||
ed93c78b | 11 | function init() { |
d4b1d58c | 12 | |
ed93c78b | 13 | } |
d4b1d58c | 14 | |
a59ff6b0 AG |
15 | function build_editform($item, $feedback, $cm) { |
16 | global $DB, $CFG; | |
ed93c78b | 17 | require_once('info_form.php'); |
d4b1d58c | 18 | |
a59ff6b0 AG |
19 | //get the lastposition number of the feedback_items |
20 | $position = $item->position; | |
21 | $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); | |
22 | if($position == -1){ | |
23 | $i_formselect_last = $lastposition + 1; | |
24 | $i_formselect_value = $lastposition + 1; | |
25 | $item->position = $lastposition + 1; | |
26 | }else { | |
27 | $i_formselect_last = $lastposition; | |
28 | $i_formselect_value = $item->position; | |
29 | } | |
30 | //the elements for position dropdownlist | |
31 | $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); | |
32 | ||
33 | $item->presentation = empty($item->presentation) ? 1 : $item->presentation; | |
34 | $item->required = 0; | |
d4b1d58c | 35 | |
a59ff6b0 AG |
36 | $commonparams = array('cmid'=>$cm->id, |
37 | 'id'=>isset($item->id) ? $item->id : NULL, | |
38 | 'typ'=>$item->typ, | |
39 | 'feedback'=>$feedback->id); | |
d4b1d58c | 40 | |
a59ff6b0 AG |
41 | //build the form |
42 | $this->item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); | |
43 | } | |
ed93c78b | 44 | |
a59ff6b0 AG |
45 | //this function only can used after the call of build_editform() |
46 | function show_editform() { | |
47 | $this->item_form->display(); | |
48 | } | |
49 | ||
50 | function is_cancelled() { | |
51 | return $this->item_form->is_cancelled(); | |
52 | } | |
ed93c78b | 53 | |
a59ff6b0 AG |
54 | function get_data() { |
55 | if($this->item = $this->item_form->get_data()) { | |
56 | return true; | |
57 | } | |
58 | return false; | |
59 | } | |
d4b1d58c | 60 | |
a59ff6b0 AG |
61 | function save_item() { |
62 | global $DB; | |
63 | ||
64 | if(!$item = $this->item_form->get_data()) { | |
65 | return false; | |
66 | } | |
67 | ||
45c2f92a | 68 | $item->hasvalue = $this->get_hasvalue(); |
a59ff6b0 AG |
69 | if(!$item->id) { |
70 | $item->id = $DB->insert_record('feedback_item', $item); | |
71 | }else { | |
72 | $DB->update_record('feedback_item', $item); | |
73 | } | |
74 | ||
75 | return $DB->get_record('feedback_item', array('id'=>$item->id)); | |
ed93c78b | 76 | } |
77 | ||
78 | //liefert eine Struktur ->name, ->data = array(mit Antworten) | |
79 | function get_analysed($item, $groupid = false, $courseid = false) { | |
d4b1d58c | 80 | |
ed93c78b | 81 | $presentation = $item->presentation; |
82 | $aVal = null; | |
83 | $aVal->data = null; | |
84 | $aVal->name = $item->name; | |
85 | //$values = get_records('feedback_value', 'item', $item->id); | |
86 | $values = feedback_get_group_values($item, $groupid, $courseid); | |
87 | if($values) { | |
88 | $data = array(); | |
89 | $datavalue = new object(); | |
90 | foreach($values as $value) { | |
d4b1d58c | 91 | |
ed93c78b | 92 | switch($presentation) { |
93 | case 1: | |
94 | $datavalue->value = $value->value; | |
95 | $datavalue->show = UserDate($datavalue->value); | |
96 | break; | |
97 | case 2: | |
98 | $datavalue->value = $value->value; | |
99 | $datavalue->show = $datavalue->value; | |
100 | break; | |
101 | case 3: | |
102 | $datavalue->value = $value->value; | |
103 | $datavalue->show = $datavalue->value; | |
104 | break; | |
105 | } | |
106 | ||
107 | $data[] = $datavalue; | |
108 | } | |
109 | $aVal->data = $data; | |
110 | } | |
111 | return $aVal; | |
112 | } | |
113 | ||
114 | function get_printval($item, $value) { | |
d4b1d58c | 115 | |
ed93c78b | 116 | if(!isset($value->value)) return ''; |
117 | return UserDate($value->value); | |
118 | } | |
119 | ||
120 | function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { | |
121 | $analysed_item = $this->get_analysed($item, $groupid, $courseid); | |
122 | $data = $analysed_item->data; | |
123 | if(is_array($data)) { | |
b7a47958 | 124 | echo '<tr><th colspan="2" align="left">'. $itemnr . ' ('. $item->label .') ' . $item->name .'</th></tr>'; |
ed93c78b | 125 | for($i = 0; $i < sizeof($data); $i++) { |
126 | echo '<tr><td colspan="2" valign="top" align="left">- ' . str_replace("\n", '<br />', $data[$i]->show) . '</td></tr>'; | |
127 | } | |
128 | } | |
129 | // return $itemnr; | |
130 | } | |
131 | ||
51129b99 | 132 | function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { |
ed93c78b | 133 | $analysed_item = $this->get_analysed($item, $groupid, $courseid); |
134 | ||
51129b99 AG |
135 | // $worksheet->setFormat("<l><f><ro2><vo><c:green>"); |
136 | $worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); | |
137 | $worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2); | |
ed93c78b | 138 | $data = $analysed_item->data; |
139 | if(is_array($data)) { | |
51129b99 AG |
140 | // $worksheet->setFormat("<l><ro2><vo>"); |
141 | $worksheet->write_string($rowOffset, 2, $data[0]->show, $xlsFormats->value_bold); | |
ed93c78b | 142 | $rowOffset++; |
143 | for($i = 1; $i < sizeof($data); $i++) { | |
51129b99 AG |
144 | // $worksheet->setFormat("<l><vo>"); |
145 | $worksheet->write_string($rowOffset, 2, $data[$i]->show, $xlsFormats->default); | |
ed93c78b | 146 | $rowOffset++; |
147 | } | |
148 | } | |
149 | $rowOffset++; | |
150 | return $rowOffset; | |
151 | } | |
9d5fbd65 AG |
152 | |
153 | /** | |
154 | * print the item at the edit-page of feedback | |
155 | * | |
156 | * @global object | |
157 | * @param object $item | |
158 | * @return void | |
159 | */ | |
160 | function print_item_preview($item) { | |
161 | global $USER, $DB, $OUTPUT; | |
162 | $align = right_to_left() ? 'right' : 'left'; | |
ed93c78b | 163 | |
9d5fbd65 AG |
164 | $presentation = $item->presentation; |
165 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
afdb1920 AG |
166 | |
167 | $feedback = $DB->get_record('feedback', array('id'=>$item->feedback)); | |
168 | $course = $DB->get_record('course', array('id'=>$feedback->course)); | |
169 | $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category)); | |
170 | switch($presentation) { | |
171 | case 1: | |
172 | $itemvalue = time(); | |
173 | $itemshowvalue = UserDate($itemvalue); | |
174 | break; | |
175 | case 2: | |
176 | $itemvalue = $course->shortname; | |
177 | $itemshowvalue = $itemvalue; | |
178 | break; | |
179 | case 3: | |
180 | $itemvalue = $coursecategory->name; | |
181 | $itemshowvalue = $itemvalue; | |
182 | break; | |
183 | } | |
184 | ||
185 | //print the question and label | |
186 | echo '<div class="feedback_item_label_'.$align.'">'; | |
187 | echo '('.$item->label.') '; | |
188 | echo format_text($item->name.$requiredmark, true, false, false); | |
189 | echo '</div>'; | |
190 | //print the presentation | |
191 | echo '<div class="feedback_item_presentation_'.$align.'">'; | |
192 | echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; | |
193 | echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; | |
194 | echo '</div>'; | |
9d5fbd65 AG |
195 | } |
196 | ||
197 | /** | |
198 | * print the item at the complete-page of feedback | |
199 | * | |
200 | * @global object | |
201 | * @param object $item | |
202 | * @param string $value | |
203 | * @param bool $highlightrequire | |
204 | * @return void | |
205 | */ | |
206 | function print_item_complete($item, $value = '', $highlightrequire = false) { | |
d4b1d58c | 207 | global $USER, $DB, $OUTPUT; |
e372f4c7 | 208 | $align = right_to_left() ? 'right' : 'left'; |
d4b1d58c | 209 | |
ed93c78b | 210 | $presentation = $item->presentation; |
211 | if($highlightrequire AND $item->required AND strval($value) == '') { | |
afdb1920 | 212 | $highlight = ' missingrequire'; |
ed93c78b | 213 | }else { |
214 | $highlight = ''; | |
215 | } | |
216 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
afdb1920 AG |
217 | |
218 | $feedback = $DB->get_record('feedback', array('id'=>$item->feedback)); | |
219 | $course = $DB->get_record('course', array('id'=>$feedback->course)); | |
220 | $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category)); | |
221 | switch($presentation) { | |
222 | case 1: | |
223 | $itemvalue = time(); | |
224 | $itemshowvalue = UserDate($itemvalue); | |
225 | break; | |
226 | case 2: | |
227 | $itemvalue = $course->shortname; | |
228 | $itemshowvalue = $itemvalue; | |
229 | break; | |
230 | case 3: | |
231 | $itemvalue = $coursecategory->name; | |
232 | $itemshowvalue = $itemvalue; | |
233 | break; | |
234 | } | |
235 | ||
236 | //print the question and label | |
237 | echo '<div class="feedback_item_label_'.$align.$highlight.'">'; | |
238 | echo format_text($item->name.$requiredmark, true, false, false); | |
239 | echo '</div>'; | |
240 | ||
241 | //print the presentation | |
242 | echo '<div class="feedback_item_presentation_'.$align.'">'; | |
243 | echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; | |
244 | echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; | |
245 | echo '</div>'; | |
9d5fbd65 AG |
246 | } |
247 | ||
248 | /** | |
249 | * print the item at the complete-page of feedback | |
250 | * | |
251 | * @global object | |
252 | * @param object $item | |
253 | * @param string $value | |
254 | * @return void | |
255 | */ | |
256 | function print_item_show_value($item, $value = '') { | |
257 | global $USER, $DB, $OUTPUT; | |
258 | $align = right_to_left() ? 'right' : 'left'; | |
259 | ||
260 | $presentation = $item->presentation; | |
261 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
afdb1920 AG |
262 | |
263 | //print the question and label | |
264 | echo '<div class="feedback_item_label_'.$align.'">'; | |
9d5fbd65 AG |
265 | echo '('.$item->label.') '; |
266 | echo format_text($item->name . $requiredmark, true, false, false); | |
afdb1920 AG |
267 | echo '</div>'; |
268 | ||
269 | //print the presentation | |
270 | echo $OUTPUT->box_start('generalbox boxalign'.$align); | |
271 | echo $value ? UserDate($value):' '; | |
272 | echo $OUTPUT->box_end(); | |
ed93c78b | 273 | } |
274 | ||
275 | function check_value($value, $item) { | |
276 | return true; | |
277 | } | |
278 | ||
279 | function create_value($data) { | |
280 | $data = addslashes(clean_text($data)); | |
281 | return $data; | |
282 | } | |
283 | ||
284 | function get_presentation($data) { | |
285 | return $data->infotype; | |
286 | } | |
287 | ||
288 | function get_hasvalue() { | |
289 | return 1; | |
290 | } | |
291 | } | |
292 | ?> |