MDL-18529 - the editing textbox of questions now has a with of 80 chars.
[moodle.git] / mod / feedback / item / info / lib.php
CommitLineData
ed93c78b 1<?php // $Id$
2defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
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() {
8
9 }
10
11 function &show_edit($item) {
12 global $CFG;
13
14 require_once('info_form.php');
15
16 $item_form = new feedback_info_form();
17
18 $item->presentation = empty($item->presentation) ? '' : $item->presentation;
19 $item->name = empty($item->name) ? '' : htmlspecialchars($item->name);
20
21 $item_form->requiredcheck->setValue(false);
22
23 $item_form->itemname->setValue($item->name);
24
25 $item_form->infotype->setValue($item->presentation);
26
27 return $item_form;
28 }
29
30 //liefert eine Struktur ->name, ->data = array(mit Antworten)
31 function get_analysed($item, $groupid = false, $courseid = false) {
32
33 $presentation = $item->presentation;
34 $aVal = null;
35 $aVal->data = null;
36 $aVal->name = $item->name;
37 //$values = get_records('feedback_value', 'item', $item->id);
38 $values = feedback_get_group_values($item, $groupid, $courseid);
39 if($values) {
40 $data = array();
41 $datavalue = new object();
42 foreach($values as $value) {
43
44 switch($presentation) {
45 case 1:
46 $datavalue->value = $value->value;
47 $datavalue->show = UserDate($datavalue->value);
48 break;
49 case 2:
50 $datavalue->value = $value->value;
51 $datavalue->show = $datavalue->value;
52 break;
53 case 3:
54 $datavalue->value = $value->value;
55 $datavalue->show = $datavalue->value;
56 break;
57 }
58
59 $data[] = $datavalue;
60 }
61 $aVal->data = $data;
62 }
63 return $aVal;
64 }
65
66 function get_printval($item, $value) {
67
68 if(!isset($value->value)) return '';
69 return UserDate($value->value);
70 }
71
72 function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
73 $analysed_item = $this->get_analysed($item, $groupid, $courseid);
74 $data = $analysed_item->data;
75 if(is_array($data)) {
76 echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;' . $item->name .'</th></tr>';
77 for($i = 0; $i < sizeof($data); $i++) {
78 echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;' . str_replace("\n", '<br />', $data[$i]->show) . '</td></tr>';
79 }
80 }
81 // return $itemnr;
82 }
83
84 function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
85 $analysed_item = $this->get_analysed($item, $groupid, $courseid);
86
87 $worksheet->setFormat("<l><f><ro2><vo><c:green>");
88 $worksheet->write_string($rowOffset, 0, $item->name);
89 $data = $analysed_item->data;
90 if(is_array($data)) {
91 $worksheet->setFormat("<l><ro2><vo>");
92 $worksheet->write_string($rowOffset, 1, $data[0]->show);
93 $rowOffset++;
94 for($i = 1; $i < sizeof($data); $i++) {
95 $worksheet->setFormat("<l><vo>");
96 $worksheet->write_string($rowOffset, 1, $data[$i]->show);
97 $rowOffset++;
98 }
99 }
100 $rowOffset++;
101 return $rowOffset;
102 }
103
104 function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
105 global $USER, $DB;
106 $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
107
108 $presentation = $item->presentation;
109 if($highlightrequire AND $item->required AND strval($value) == '') {
110 $highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
111 }else {
112 $highlight = '';
113 }
114 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
115 ?>
116 <td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text($item->name . $requiredmark, true, false, false);?></td>
117 <td valign="top" align="<?php echo $align;?>">
118 <?php
119 if($readonly){
120 // print_simple_box_start($align);
121 print_box_start('generalbox boxalign'.$align);
122 echo $value ? UserDate($value):'&nbsp;';
123 // print_simple_box_end();
124 print_box_end();
125 }else {
126 $feedback = $DB->get_record('feedback', array('id'=>$item->feedback));
127 $course = $DB->get_record('course', array('id'=>$feedback->course));
128 $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
129 switch($presentation) {
130 case 1:
131 $itemvalue = time();
132 $itemshowvalue = UserDate($itemvalue);
133 break;
134 case 2:
135 $itemvalue = $course->shortname;
136 $itemshowvalue = $itemvalue;
137 break;
138 case 3:
139 $itemvalue = $coursecategory->name;
140 $itemshowvalue = $itemvalue;
141 break;
142 }
143 ?>
144 <input type="hidden" name="<?php echo $item->typ . '_' . $item->id;?>"
145 value="<?php echo $itemvalue;?>" />
146 <span><?php echo $itemshowvalue;?></span>
147 <?php
148 }
149 ?>
150 </td>
151 <?php
152 }
153
154 function check_value($value, $item) {
155 return true;
156 }
157
158 function create_value($data) {
159 $data = addslashes(clean_text($data));
160 return $data;
161 }
162
163 function get_presentation($data) {
164 return $data->infotype;
165 }
166
167 function get_hasvalue() {
168 return 1;
169 }
170}
171?>