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