d1290cec |
1 | <?php // $Id$ |
f9903ed0 |
2 | |
3 | // Graph size |
551b0b98 |
4 | $SURVEY_GHEIGHT = 500; |
5 | $SURVEY_GWIDTH = 900; |
f9903ed0 |
6 | |
551b0b98 |
7 | $SURVEY_QTYPE = array ( |
f9903ed0 |
8 | "-3" => "Virtual Actual and Preferred", |
9 | "-2" => "Virtual Preferred", |
10 | "-1" => "Virtual Actual", |
11 | "0" => "Text", |
12 | "1" => "Actual", |
13 | "2" => "Preferred", |
14 | "3" => "Actual and Preferred", |
15 | ); |
16 | |
b6b3deb4 |
17 | |
18 | define("SURVEY_COLLES_ACTUAL", "1"); |
19 | define("SURVEY_COLLES_PREFERRED", "2"); |
20 | define("SURVEY_COLLES_PREFERRED_ACTUAL", "3"); |
21 | define("SURVEY_ATTLS", "4"); |
22 | define("SURVEY_CIQ", "5"); |
23 | |
24 | |
66ea15f3 |
25 | // STANDARD FUNCTIONS //////////////////////////////////////////////////////// |
04eba58f |
26 | |
27 | function survey_add_instance($survey) { |
c18269c7 |
28 | global $DB; |
04eba58f |
29 | // Given an object containing all the necessary data, |
7cac0c4b |
30 | // (defined by the form in mod_form.php) this function |
04eba58f |
31 | // will create a new instance and return the id number |
32 | // of the new instance. |
33 | |
c18269c7 |
34 | if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) { |
04eba58f |
35 | return 0; |
36 | } |
37 | |
38 | $survey->questions = $template->questions; |
39 | $survey->timecreated = time(); |
40 | $survey->timemodified = $survey->timecreated; |
41 | |
c18269c7 |
42 | return $DB->insert_record("survey", $survey); |
04eba58f |
43 | |
44 | } |
45 | |
46 | |
47 | function survey_update_instance($survey) { |
c18269c7 |
48 | global $DB; |
04eba58f |
49 | // Given an object containing all the necessary data, |
7cac0c4b |
50 | // (defined by the form in mod_form.php) this function |
04eba58f |
51 | // will update an existing instance with new data. |
52 | |
c18269c7 |
53 | if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) { |
04eba58f |
54 | return 0; |
55 | } |
56 | |
57 | $survey->id = $survey->instance; |
58 | $survey->questions = $template->questions; |
59 | $survey->timemodified = time(); |
60 | |
c18269c7 |
61 | return $DB->update_record("survey", $survey); |
04eba58f |
62 | } |
63 | |
64 | function survey_delete_instance($id) { |
c18269c7 |
65 | global $DB; |
04eba58f |
66 | // Given an ID of an instance of this module, |
67 | // this function will permanently delete the instance |
68 | // and any data that depends on it. |
69 | |
c18269c7 |
70 | if (! $survey = $DB->get_record("survey", array("id"=>$id))) { |
04eba58f |
71 | return false; |
72 | } |
73 | |
74 | $result = true; |
75 | |
c18269c7 |
76 | if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) { |
04eba58f |
77 | $result = false; |
78 | } |
79 | |
c18269c7 |
80 | if (! $DB->delete_records("survey_answers", array("survey"=>$survey->id))) { |
04eba58f |
81 | $result = false; |
82 | } |
83 | |
c18269c7 |
84 | if (! $DB->delete_records("survey", array("id"=>$survey->id))) { |
04eba58f |
85 | $result = false; |
86 | } |
87 | |
88 | return $result; |
89 | } |
90 | |
66ea15f3 |
91 | function survey_user_outline($course, $user, $mod, $survey) { |
deb3a60d |
92 | global $DB; |
66ea15f3 |
93 | |
deb3a60d |
94 | if ($answers = $DB->get_records("survey_answers", array('survey'=>$survey->id, 'userid'=>$user->id))) { |
66ea15f3 |
95 | $lastanswer = array_pop($answers); |
96 | |
deb3a60d |
97 | $result = new object(); |
66ea15f3 |
98 | $result->info = get_string("done", "survey"); |
99 | $result->time = $lastanswer->time; |
100 | return $result; |
101 | } |
102 | return NULL; |
103 | } |
104 | |
105 | |
106 | function survey_user_complete($course, $user, $mod, $survey) { |
44e1b7d7 |
107 | global $CFG, $DB; |
66ea15f3 |
108 | |
109 | if (survey_already_done($survey->id, $user->id)) { |
b6b3deb4 |
110 | if ($survey->template == SURVEY_CIQ) { // print out answers for critical incidents |
111 | $table = NULL; |
112 | $table->align = array("left", "left"); |
113 | |
44e1b7d7 |
114 | $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); |
b6b3deb4 |
115 | $questionorder = explode(",", $survey->questions); |
116 | |
117 | foreach ($questionorder as $key=>$val) { |
118 | $question = $questions[$val]; |
119 | $questiontext = get_string($question->shorttext, "survey"); |
120 | |
121 | if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) { |
122 | $answertext = "$answer->answer1"; |
123 | } else { |
124 | $answertext = "No answer"; |
125 | } |
126 | $table->data[] = array("<b>$questiontext</b>", $answertext); |
127 | } |
128 | print_table($table); |
129 | |
130 | } else { |
131 | |
839f2456 |
132 | survey_print_graph("id=$mod->id&sid=$user->id&type=student.png"); |
b6b3deb4 |
133 | } |
134 | |
66ea15f3 |
135 | } else { |
136 | print_string("notdone", "survey"); |
137 | } |
138 | } |
139 | |
dd97c328 |
140 | function survey_print_recent_activity($course, $viewfullnames, $timestart) { |
deb3a60d |
141 | global $CFG, $DB; |
54634efc |
142 | |
dd97c328 |
143 | $modinfo = get_fast_modinfo($course); |
144 | $ids = array(); |
145 | foreach ($modinfo->cms as $cm) { |
146 | if ($cm->modname != 'survey') { |
147 | continue; |
148 | } |
149 | if (!$cm->uservisible) { |
150 | continue; |
151 | } |
152 | $ids[$cm->instance] = $cm->instance; |
153 | } |
54634efc |
154 | |
dd97c328 |
155 | if (!$ids) { |
1b5910c4 |
156 | return false; |
157 | } |
158 | |
dd97c328 |
159 | $slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right? |
160 | |
deb3a60d |
161 | if (!$rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time, |
162 | u.firstname, u.lastname, u.email, u.picture |
163 | FROM {survey_answers} sa |
164 | JOIN {user} u ON u.id = sa.userid |
165 | WHERE sa.survey IN ($slist) AND sa.time > ? |
166 | GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture |
167 | ORDER BY time ASC", array($timestart))) { |
dd97c328 |
168 | return false; |
54634efc |
169 | } |
170 | |
dd97c328 |
171 | $surveys = array(); |
172 | |
deb3a60d |
173 | foreach ($rs as $survey) { |
dd97c328 |
174 | $cm = $modinfo->instances['survey'][$survey->survey]; |
175 | $survey->name = $cm->name; |
176 | $survey->cmid = $cm->id; |
177 | $surveys[] = $survey; |
178 | } |
deb3a60d |
179 | $rs->close(); |
dd97c328 |
180 | |
181 | if (!$surveys) { |
182 | return false; |
183 | } |
184 | |
185 | print_headline(get_string('newsurveyresponses', 'survey').':'); |
186 | foreach ($surveys as $survey) { |
d5edb961 |
187 | $url = $CFG->wwwroot.'/mod/survey/view.php?id='.$survey->cmid; |
dd97c328 |
188 | print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames); |
54634efc |
189 | } |
190 | |
dd97c328 |
191 | return true; |
54634efc |
192 | } |
04eba58f |
193 | |
05855091 |
194 | function survey_get_participants($surveyid) { |
195 | //Returns the users with data in one survey |
196 | //(users with records in survey_analysis and survey_answers, students) |
deb3a60d |
197 | global $DB; |
05855091 |
198 | |
199 | //Get students from survey_analysis |
deb3a60d |
200 | $st_analysis = $DB->get_records_sql("SELECT DISTINCT u.id, u.id |
201 | FROM {user} u, {survey_analysis} a |
202 | WHERE a.survey = ? AND |
203 | u.id = a.userid", array($surveyid)); |
05855091 |
204 | //Get students from survey_answers |
deb3a60d |
205 | $st_answers = $DB->get_records_sql("SELECT DISTINCT u.id, u.id |
206 | FROM {user} u, {survey_answers} a |
207 | WHERE a.survey = ? AND |
208 | u.id = a.userid", array($surveyid)); |
05855091 |
209 | |
210 | //Add st_answers to st_analysis |
211 | if ($st_answers) { |
212 | foreach ($st_answers as $st_answer) { |
213 | $st_analysis[$st_answer->id] = $st_answer; |
214 | } |
215 | } |
216 | //Return st_analysis array (it contains an array of unique users) |
217 | return ($st_analysis); |
218 | } |
66ea15f3 |
219 | |
e323955d |
220 | // SQL FUNCTIONS //////////////////////////////////////////////////////// |
66ea15f3 |
221 | |
f9903ed0 |
222 | |
e323955d |
223 | function survey_log_info($log) { |
deb3a60d |
224 | global $DB; |
225 | return $DB->get_record_sql("SELECT s.name, u.firstname, u.lastname, u.picture |
226 | FROM {survey} s, {user} u |
227 | WHERE s.id = ? AND u.id = ?", array($log->info, $log->userid)); |
e323955d |
228 | } |
f9903ed0 |
229 | |
07aa2057 |
230 | function survey_get_responses($surveyid, $groupid, $groupingid) { |
deb3a60d |
231 | global $DB; |
232 | |
233 | $params = array('surveyid'=>$surveyid, 'groupid'=>$groupid, 'groupingid'=>$groupingid); |
a9ccbf60 |
234 | |
235 | if ($groupid) { |
deb3a60d |
236 | $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid AND gm.groupid = :groupid "; |
1d684195 |
237 | |
07aa2057 |
238 | } else if ($groupingid) { |
deb3a60d |
239 | $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid |
240 | JOIN {groupings_groups} gg ON gm.groupid = gg.groupid AND gg.groupingid = :groupingid "; |
a9ccbf60 |
241 | } else { |
07aa2057 |
242 | $groupsjoin = ""; |
a9ccbf60 |
243 | } |
244 | |
deb3a60d |
245 | return $DB->get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, MAX(a.time) as time |
246 | FROM {survey_answers} a |
247 | JOIN {user} u ON a.userid = u.id |
248 | $groupsjoin |
249 | WHERE a.survey = :surveyid |
250 | GROUP BY u.id, u.firstname, u.lastname, u.picture |
251 | ORDER BY time ASC", $params); |
e323955d |
252 | } |
253 | |
254 | function survey_get_analysis($survey, $user) { |
deb3a60d |
255 | global $DB; |
e323955d |
256 | |
deb3a60d |
257 | return $DB->get_record_sql("SELECT notes |
258 | FROM {survey_analysis} |
259 | WHERE survey=? AND userid=?", array($survey, $user)); |
e323955d |
260 | } |
261 | |
262 | function survey_update_analysis($survey, $user, $notes) { |
deb3a60d |
263 | global $DB; |
e323955d |
264 | |
deb3a60d |
265 | return $DB->execute("UPDATE {survey_analysis} |
266 | SET notes=? |
267 | WHERE survey=? |
268 | AND userid=?", array($notes, $survey, $user)); |
e323955d |
269 | } |
270 | |
271 | |
a9ccbf60 |
272 | function survey_get_user_answers($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC") { |
deb3a60d |
273 | global $DB; |
274 | |
275 | $params = array('surveyid'=>$surveyid, 'questionid'=>$questionid, 'groupid'=>$groupid); |
e323955d |
276 | |
a9ccbf60 |
277 | if ($groupid) { |
deb3a60d |
278 | $groupsql = "AND gm.groupid = :groupid AND u.id = gm.userid"; |
a9ccbf60 |
279 | } else { |
280 | $groupsql = ""; |
281 | } |
282 | |
deb3a60d |
283 | return $DB->get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture |
284 | FROM {survey_answers} sa, {user} u, {groups_members} gm |
285 | WHERE sa.survey = :surveyid |
286 | AND sa.question = :questionid |
287 | AND u.id = sa.userid $groupsql |
288 | ORDER BY $sort", $params); |
7c8c335f |
289 | } |
290 | |
291 | function survey_get_user_answer($surveyid, $questionid, $userid) { |
deb3a60d |
292 | global $DB; |
7c8c335f |
293 | |
deb3a60d |
294 | return $DB->get_record_sql("SELECT sa.* |
295 | FROM {survey_answers} sa |
296 | WHERE sa.survey = ? |
297 | AND sa.question = ? |
298 | AND sa.userid = ?", array($surveyid, $questionid, $userid)); |
e323955d |
299 | } |
300 | |
301 | // MODULE FUNCTIONS //////////////////////////////////////////////////////// |
302 | |
ebc3bd2b |
303 | function survey_add_analysis($survey, $user, $notes) { |
deb3a60d |
304 | global $DB; |
ebc3bd2b |
305 | |
deb3a60d |
306 | $record = new object(); |
ebc3bd2b |
307 | $record->survey = $survey; |
308 | $record->userid = $user; |
309 | $record->notes = $notes; |
310 | |
deb3a60d |
311 | return $DB->insert_record("survey_analysis", $record, false); |
ebc3bd2b |
312 | } |
313 | |
e323955d |
314 | function survey_already_done($survey, $user) { |
deb3a60d |
315 | global $DB; |
316 | |
317 | return $DB->record_exists("survey_answers", array("survey"=>$survey, "userid"=>$user)); |
551b0b98 |
318 | } |
f9903ed0 |
319 | |
07aa2057 |
320 | function survey_count_responses($surveyid, $groupid, $groupingid) { |
321 | if ($responses = survey_get_responses($surveyid, $groupid, $groupingid)) { |
551b0b98 |
322 | return count($responses); |
323 | } else { |
324 | return 0; |
325 | } |
f9903ed0 |
326 | } |
327 | |
b416a1c3 |
328 | |
7c8c335f |
329 | function survey_print_all_responses($cmid, $results, $courseid) { |
b416a1c3 |
330 | |
deb3a60d |
331 | $table = new object(); |
a30f997e |
332 | $table->head = array ("", get_string("name"), get_string("time")); |
333 | $table->align = array ("", "left", "left"); |
334 | $table->size = array (35, "", "" ); |
b416a1c3 |
335 | |
336 | foreach ($results as $a) { |
7c8c335f |
337 | $table->data[] = array(print_user_picture($a->id, $courseid, $a->picture, false, true, false), |
839f2456 |
338 | "<a href=\"report.php?action=student&student=$a->id&id=$cmid\">".fullname($a)."</a>", |
a30f997e |
339 | userdate($a->time)); |
b416a1c3 |
340 | } |
7c8c335f |
341 | |
342 | print_table($table); |
b416a1c3 |
343 | } |
344 | |
b416a1c3 |
345 | |
551b0b98 |
346 | function survey_get_template_name($templateid) { |
fd0e6640 |
347 | global $DB; |
f9903ed0 |
348 | |
349 | if ($templateid) { |
deb3a60d |
350 | if ($ss = $DB->get_record("surveys", array("id"=>$templateid))) { |
e323955d |
351 | return $ss->name; |
f9903ed0 |
352 | } |
353 | } else { |
354 | return ""; |
355 | } |
356 | } |
357 | |
0d22e7cc |
358 | |
f9903ed0 |
359 | |
0e30c987 |
360 | function survey_shorten_name ($name, $numwords) { |
361 | $words = explode(" ", $name); |
362 | for ($i=0; $i < $numwords; $i++) { |
363 | $output .= $words[$i]." "; |
364 | } |
365 | return $output; |
366 | } |
f9903ed0 |
367 | |
368 | |
0e30c987 |
369 | |
370 | function survey_print_multi($question) { |
44e1b7d7 |
371 | global $USER, $DB, $qnum, $checklist, $DB; |
0e30c987 |
372 | |
98899fc0 |
373 | $stripreferthat = get_string("ipreferthat", "survey"); |
374 | $strifoundthat = get_string("ifoundthat", "survey"); |
532f494d |
375 | $strdefault = get_string('default'); |
376 | $strresponses = get_string('responses', 'survey'); |
377 | |
378 | print_heading($question->text, null, 3, 'questiontext'); |
379 | echo "\n<table width=\"90%\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\">"; |
0e30c987 |
380 | |
381 | $options = explode( ",", $question->options); |
382 | $numoptions = count($options); |
383 | |
384 | $oneanswer = ($question->type == 1 || $question->type == 2) ? true : false; |
8a12a132 |
385 | if ($question->type == 2) { |
386 | $P = "P"; |
387 | } else { |
388 | $P = ""; |
389 | } |
0e30c987 |
390 | |
532f494d |
391 | echo "<tr class=\"smalltext\"><th scope=\"row\">$strresponses</th>"; |
0e30c987 |
392 | while (list ($key, $val) = each ($options)) { |
532f494d |
393 | echo "<th scope=\"col\" class=\"hresponse\">$val</th>\n"; |
394 | } |
395 | echo "<th> </th></tr>\n"; |
396 | |
397 | if ($oneanswer) { |
398 | echo "<tr><th scope=\"col\" colspan=\"6\">$question->intro</th></tr>\n"; |
399 | } else { |
400 | echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n"; |
0e30c987 |
401 | } |
0e30c987 |
402 | |
44e1b7d7 |
403 | $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi)); |
532f494d |
404 | |
0e30c987 |
405 | foreach ($subquestions as $q) { |
406 | $qnum++; |
f1c1d2f1 |
407 | $rowclass = survey_question_rowclass($qnum); |
f762c448 |
408 | if ($q->text) { |
409 | $q->text = get_string($q->text, "survey"); |
410 | } |
411 | |
532f494d |
412 | echo "<tr class=\"$rowclass rblock\">"; |
0e30c987 |
413 | if ($oneanswer) { |
3a2e0fe9 |
414 | |
532f494d |
415 | echo "<th scope=\"row\" class=\"optioncell\">"; |
416 | echo "<b class=\"qnumtopcell\">$qnum</b> "; |
417 | echo $q->text ."</th>\n"; |
418 | for ($i=1;$i<=$numoptions;$i++) { |
419 | $hiddentext = get_accesshide($options[$i-1]); |
420 | $id = "q$P" . $q->id . "_$i"; |
421 | echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>"; |
0e30c987 |
422 | } |
532f494d |
423 | $default = get_accesshide($strdefault, 'label', '', "for=\"q$P$q->id\""); |
424 | echo "<td class=\"whitecell\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" />$default</td>"; |
0e30c987 |
425 | $checklist["q$P$q->id"] = $numoptions; |
426 | |
3a2e0fe9 |
427 | } else { |
f40aee6f |
428 | // yu : fix for MDL-7501, possibly need to use user flag as this is quite ugly. |
532f494d |
429 | echo "<th scope=\"row\" class=\"optioncell\">"; |
430 | echo "<b class=\"qnumtopcell\">$qnum</b> "; |
5d1a5ef4 |
431 | $qnum++; |
532f494d |
432 | echo "<span class=\"preferthat smalltext\">$stripreferthat</span> "; |
433 | echo "<span class=\"option\">$q->text</span></th>\n"; |
0e30c987 |
434 | for ($i=1;$i<=$numoptions;$i++) { |
532f494d |
435 | $hiddentext = get_accesshide($options[$i-1]); |
436 | $id = "qP" . $q->id . "_$i"; |
437 | echo "<td><label for=\"$id\"><input type=\"radio\" name=\"qP$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>"; |
0e30c987 |
438 | } |
532f494d |
439 | $default = get_accesshide($strdefault, 'label', '', "for=\"qP$q->id\""); |
440 | echo "<td><input type=\"radio\" name=\"qP$q->id\" id=\"qP$q->id\" value=\"0\" checked=\"checked\" />$default</td>"; |
d1290cec |
441 | echo "</tr>"; |
0e30c987 |
442 | |
532f494d |
443 | echo "<tr class=\"$rowclass rblock\">"; |
444 | echo "<th scope=\"row\" class=\"optioncell\">"; |
445 | echo "<b class=\"qnumtopcell\">$qnum</b> "; |
446 | echo "<span class=\"foundthat smalltext\">$strifoundthat</span> "; |
447 | echo "<span class=\"option\">$q->text</span></th>\n"; |
0e30c987 |
448 | for ($i=1;$i<=$numoptions;$i++) { |
532f494d |
449 | $hiddentext = get_accesshide($options[$i-1]); |
450 | $id = "q" . $q->id . "_$i"; |
451 | echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>"; |
0e30c987 |
452 | } |
532f494d |
453 | $default = get_accesshide($strdefault, 'label', '', "for=\"q$q->id\""); |
454 | echo "<td class=\"buttoncell\"><input type=\"radio\" name=\"q$q->id\" id=\"q$q->id\" value=\"0\" checked=\"checked\" />$default</td>"; |
0e30c987 |
455 | $checklist["qP$q->id"] = $numoptions; |
5d1a5ef4 |
456 | $checklist["q$q->id"] = $numoptions; |
0e30c987 |
457 | } |
d1290cec |
458 | echo "</tr>\n"; |
0e30c987 |
459 | } |
d1290cec |
460 | echo "</table>"; |
0e30c987 |
461 | } |
462 | |
463 | |
464 | |
465 | function survey_print_single($question) { |
fd0e6640 |
466 | global $DB, $qnum; |
0e30c987 |
467 | |
f1c1d2f1 |
468 | $rowclass = survey_question_rowclass(0); |
0e30c987 |
469 | |
470 | $qnum++; |
471 | |
caf261b0 |
472 | echo "<br />\n"; |
795b56b3 |
473 | echo "<table width=\"90%\" cellpadding=\"4\" cellspacing=\"0\">\n"; |
f1c1d2f1 |
474 | echo "<tr class=\"$rowclass\">"; |
532f494d |
475 | echo "<th scope=\"row\" class=\"optioncell\"><label for=\"q$question->id\"><b class=\"qnumtopcell\">$qnum</b> "; |
476 | echo "<span class=\"questioncell\">$question->text</span></label></th>\n"; |
477 | echo "<td class=\"questioncell smalltext\">\n"; |
0e30c987 |
478 | |
479 | |
480 | if ($question->type == 0) { // Plain text field |
532f494d |
481 | echo "<textarea rows=\"3\" cols=\"30\" name=\"q$question->id\" id=\"q$question->id\">$question->options</textarea>"; |
0e30c987 |
482 | |
483 | } else if ($question->type > 0) { // Choose one of a number |
98899fc0 |
484 | $strchoose = get_string("choose"); |
532f494d |
485 | echo "<select name=\"q$question->id\" id=\"q$question->id\">"; |
e0b7b090 |
486 | echo "<option value=\"0\" selected=\"selected\">$strchoose...</option>"; |
0e30c987 |
487 | $options = explode( ",", $question->options); |
488 | foreach ($options as $key => $val) { |
489 | $key++; |
d1290cec |
490 | echo "<option value=\"$key\">$val</option>"; |
0e30c987 |
491 | } |
d1290cec |
492 | echo "</select>"; |
0e30c987 |
493 | |
494 | } else if ($question->type < 0) { // Choose several of a number |
495 | $options = explode( ",", $question->options); |
f762c448 |
496 | notify("This question type not supported yet"); |
0e30c987 |
497 | } |
498 | |
532f494d |
499 | echo "</td></tr></table>"; |
0e30c987 |
500 | |
501 | } |
502 | |
f1c1d2f1 |
503 | function survey_question_rowclass($qnum) { |
0e30c987 |
504 | |
505 | if ($qnum) { |
f1c1d2f1 |
506 | return $qnum % 2 ? 'r0' : 'r1'; |
0e30c987 |
507 | } else { |
f1c1d2f1 |
508 | return 'r0'; |
0e30c987 |
509 | } |
510 | } |
511 | |
607809b3 |
512 | function survey_print_graph($url) { |
513 | global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH; |
514 | |
515 | if (empty($CFG->gdversion)) { |
516 | echo "(".get_string("gdneed").")"; |
517 | |
518 | } else { |
795b56b3 |
519 | echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"". |
7150b8ae |
520 | " src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />"; |
607809b3 |
521 | } |
522 | } |
523 | |
f3221af9 |
524 | function survey_get_view_actions() { |
525 | return array('download','view all','view form','view graph','view report'); |
526 | } |
527 | |
528 | function survey_get_post_actions() { |
529 | return array('submit'); |
530 | } |
531 | |
0b5a80a1 |
532 | |
533 | /** |
534 | * Implementation of the function for printing the form elements that control |
535 | * whether the course reset functionality affects the survey. |
536 | * @param $mform form passed by reference |
537 | */ |
538 | function survey_reset_course_form_definition(&$mform) { |
539 | $mform->addElement('header', 'surveyheader', get_string('modulenameplural', 'survey')); |
540 | $mform->addElement('checkbox', 'reset_survey_answers', get_string('deleteallanswers','survey')); |
541 | $mform->addElement('checkbox', 'reset_survey_analysis', get_string('deleteanalysis','survey')); |
542 | $mform->disabledIf('reset_survey_analysis', 'reset_survey_answers', 'checked'); |
543 | } |
544 | |
545 | /** |
546 | * Course reset form defaults. |
547 | */ |
548 | function survey_reset_course_form_defaults($course) { |
549 | return array('reset_survey_answers'=>1, 'reset_survey_analysis'=>1); |
550 | } |
551 | |
552 | /** |
553 | * Actual implementation of the rest coures functionality, delete all the |
554 | * survey responses for course $data->courseid. |
555 | * @param $data the data submitted from the reset course. |
556 | * @return array status array |
557 | */ |
558 | function survey_reset_userdata($data) { |
deb3a60d |
559 | global $DB; |
0b5a80a1 |
560 | |
561 | $componentstr = get_string('modulenameplural', 'survey'); |
562 | $status = array(); |
563 | |
564 | $surveyssql = "SELECT ch.id |
deb3a60d |
565 | FROM {survey} ch |
566 | WHERE ch.course=?"; |
567 | $params = array($data->courseid); |
0b5a80a1 |
568 | |
569 | if (!empty($data->reset_survey_answers)) { |
deb3a60d |
570 | $DB->delete_records_select('survey_answers', "survey IN ($surveyssql)", $params); |
571 | $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params); |
0b5a80a1 |
572 | $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false); |
573 | } |
574 | |
575 | if (!empty($data->reset_survey_analysis)) { |
deb3a60d |
576 | $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params); |
0b5a80a1 |
577 | $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false); |
578 | } |
579 | |
580 | // no date shifting |
581 | return $status; |
582 | } |
583 | |
f432bebf |
584 | /** |
585 | * Returns all other caps used in module |
586 | */ |
587 | function survey_get_extra_capabilities() { |
588 | return array('moodle/site:accessallgroups'); |
589 | } |
590 | |
42f103be |
591 | /** |
592 | * @param string $feature FEATURE_xx constant for requested feature |
593 | * @return mixed True if module supports feature, null if doesn't know |
594 | */ |
595 | function survey_supports($feature) { |
596 | switch($feature) { |
597 | case FEATURE_GROUPS: return true; |
598 | case FEATURE_GROUPINGS: return true; |
599 | case FEATURE_GROUPMEMBERSONLY: return true; |
dc5c2bd9 |
600 | case FEATURE_MOD_INTRO: return true; |
42f103be |
601 | case FEATURE_COMPLETION_TRACKS_VIEWS: return true; |
602 | case FEATURE_GRADE_HAS_GRADE: return true; |
603 | case FEATURE_GRADE_OUTCOMES: return true; |
604 | |
605 | default: return null; |
606 | } |
607 | } |