navigation MDL-22044 Added setting to limit content that is shown on the navigation...
[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 }
106
107 function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
d4b1d58c 108 global $USER, $DB, $OUTPUT;
e372f4c7 109 $align = right_to_left() ? 'right' : 'left';
d4b1d58c 110
ed93c78b 111 $presentation = $item->presentation;
112 if($highlightrequire AND $item->required AND strval($value) == '') {
113 $highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
114 }else {
115 $highlight = '';
116 }
117 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
118 ?>
b7a47958 119 <td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>">
120 <?php
121 if($edit OR $readonly) {
122 echo '('.$item->label.') ';
123 }
124 echo format_text($item->name . $requiredmark, true, false, false);
125 ?>
126 </td>
ed93c78b 127 <td valign="top" align="<?php echo $align;?>">
128 <?php
129 if($readonly){
d4b1d58c 130 echo $OUTPUT->box_start('generalbox boxalign'.$align);
ed93c78b 131 echo $value ? UserDate($value):'&nbsp;';
d4b1d58c 132 echo $OUTPUT->box_end();
ed93c78b 133 }else {
134 $feedback = $DB->get_record('feedback', array('id'=>$item->feedback));
135 $course = $DB->get_record('course', array('id'=>$feedback->course));
136 $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
137 switch($presentation) {
138 case 1:
139 $itemvalue = time();
140 $itemshowvalue = UserDate($itemvalue);
141 break;
142 case 2:
143 $itemvalue = $course->shortname;
144 $itemshowvalue = $itemvalue;
145 break;
146 case 3:
147 $itemvalue = $coursecategory->name;
148 $itemshowvalue = $itemvalue;
149 break;
150 }
151 ?>
152 <input type="hidden" name="<?php echo $item->typ . '_' . $item->id;?>"
153 value="<?php echo $itemvalue;?>" />
154 <span><?php echo $itemshowvalue;?></span>
155 <?php
156 }
157 ?>
158 </td>
159 <?php
160 }
161
162 function check_value($value, $item) {
163 return true;
164 }
165
166 function create_value($data) {
167 $data = addslashes(clean_text($data));
168 return $data;
169 }
170
171 function get_presentation($data) {
172 return $data->infotype;
173 }
174
175 function get_hasvalue() {
176 return 1;
177 }
178}
179?>