MDL-19806 Converted print_box* to $OUTPUT->box*
[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);
b7a47958 20 $item->label = empty($item->label) ? '' : $item->label;
ed93c78b 21
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);
28
29 return $item_form;
30 }
31
32 //liefert eine Struktur ->name, ->data = array(mit Antworten)
33 function get_analysed($item, $groupid = false, $courseid = false) {
34
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) {
45
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) {
69
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
86 function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
87 $analysed_item = $this->get_analysed($item, $groupid, $courseid);
88
89 $worksheet->setFormat("<l><f><ro2><vo><c:green>");
b7a47958 90 $worksheet->write_string($rowOffset, 0, $item->label);
91 $worksheet->write_string($rowOffset, 1, $item->name);
ed93c78b 92 $data = $analysed_item->data;
93 if(is_array($data)) {
94 $worksheet->setFormat("<l><ro2><vo>");
b7a47958 95 $worksheet->write_string($rowOffset, 2, $data[0]->show);
ed93c78b 96 $rowOffset++;
97 for($i = 1; $i < sizeof($data); $i++) {
98 $worksheet->setFormat("<l><vo>");
b7a47958 99 $worksheet->write_string($rowOffset, 2, $data[$i]->show);
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){
108 global $USER, $DB;
109 $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
110
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){
130 // print_simple_box_start($align);
131 print_box_start('generalbox boxalign'.$align);
132 echo $value ? UserDate($value):'&nbsp;';
133 // print_simple_box_end();
134 print_box_end();
135 }else {
136 $feedback = $DB->get_record('feedback', array('id'=>$item->feedback));
137 $course = $DB->get_record('course', array('id'=>$feedback->course));
138 $coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
139 switch($presentation) {
140 case 1:
141 $itemvalue = time();
142 $itemshowvalue = UserDate($itemvalue);
143 break;
144 case 2:
145 $itemvalue = $course->shortname;
146 $itemshowvalue = $itemvalue;
147 break;
148 case 3:
149 $itemvalue = $coursecategory->name;
150 $itemshowvalue = $itemvalue;
151 break;
152 }
153 ?>
154 <input type="hidden" name="<?php echo $item->typ . '_' . $item->id;?>"
155 value="<?php echo $itemvalue;?>" />
156 <span><?php echo $itemshowvalue;?></span>
157 <?php
158 }
159 ?>
160 </td>
161 <?php
162 }
163
164 function check_value($value, $item) {
165 return true;
166 }
167
168 function create_value($data) {
169 $data = addslashes(clean_text($data));
170 return $data;
171 }
172
173 function get_presentation($data) {
174 return $data->infotype;
175 }
176
177 function get_hasvalue() {
178 return 1;
179 }
180}
181?>