Merge branch 'm22_MDL-27368' of git://github.com/danmarsden/moodle into MOODLE_22_STABLE
[moodle.git] / mod / survey / lib.php
blob2ce8548c5d0bb23424a80cdc53c08e37dd587be2
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * @package mod-survey
20 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 /**
25 * Graph size
26 * @global int $SURVEY_GHEIGHT
28 global $SURVEY_GHEIGHT;
29 $SURVEY_GHEIGHT = 500;
30 /**
31 * Graph size
32 * @global int $SURVEY_GWIDTH
34 global $SURVEY_GWIDTH;
35 $SURVEY_GWIDTH = 900;
36 /**
37 * Question Type
38 * @global array $SURVEY_QTYPE
40 global $SURVEY_QTYPE;
41 $SURVEY_QTYPE = array (
42 "-3" => "Virtual Actual and Preferred",
43 "-2" => "Virtual Preferred",
44 "-1" => "Virtual Actual",
45 "0" => "Text",
46 "1" => "Actual",
47 "2" => "Preferred",
48 "3" => "Actual and Preferred",
52 define("SURVEY_COLLES_ACTUAL", "1");
53 define("SURVEY_COLLES_PREFERRED", "2");
54 define("SURVEY_COLLES_PREFERRED_ACTUAL", "3");
55 define("SURVEY_ATTLS", "4");
56 define("SURVEY_CIQ", "5");
59 // STANDARD FUNCTIONS ////////////////////////////////////////////////////////
60 /**
61 * Given an object containing all the necessary data,
62 * (defined by the form in mod_form.php) this function
63 * will create a new instance and return the id number
64 * of the new instance.
66 * @global object
67 * @param object $survey
68 * @return int|bool
70 function survey_add_instance($survey) {
71 global $DB;
73 if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
74 return 0;
77 $survey->questions = $template->questions;
78 $survey->timecreated = time();
79 $survey->timemodified = $survey->timecreated;
81 return $DB->insert_record("survey", $survey);
85 /**
86 * Given an object containing all the necessary data,
87 * (defined by the form in mod_form.php) this function
88 * will update an existing instance with new data.
90 * @global object
91 * @param object $survey
92 * @return bool
94 function survey_update_instance($survey) {
95 global $DB;
97 if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
98 return 0;
101 $survey->id = $survey->instance;
102 $survey->questions = $template->questions;
103 $survey->timemodified = time();
105 return $DB->update_record("survey", $survey);
109 * Given an ID of an instance of this module,
110 * this function will permanently delete the instance
111 * and any data that depends on it.
113 * @global object
114 * @param int $id
115 * @return bool
117 function survey_delete_instance($id) {
118 global $DB;
120 if (! $survey = $DB->get_record("survey", array("id"=>$id))) {
121 return false;
124 $result = true;
126 if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) {
127 $result = false;
130 if (! $DB->delete_records("survey_answers", array("survey"=>$survey->id))) {
131 $result = false;
134 if (! $DB->delete_records("survey", array("id"=>$survey->id))) {
135 $result = false;
138 return $result;
142 * @global object
143 * @param object $course
144 * @param object $user
145 * @param object $mod
146 * @param object $survey
147 * @return $result
149 function survey_user_outline($course, $user, $mod, $survey) {
150 global $DB;
152 if ($answers = $DB->get_records("survey_answers", array('survey'=>$survey->id, 'userid'=>$user->id))) {
153 $lastanswer = array_pop($answers);
155 $result = new stdClass();
156 $result->info = get_string("done", "survey");
157 $result->time = $lastanswer->time;
158 return $result;
160 return NULL;
164 * @global stdObject
165 * @global object
166 * @uses SURVEY_CIQ
167 * @param object $course
168 * @param object $user
169 * @param object $mod
170 * @param object $survey
172 function survey_user_complete($course, $user, $mod, $survey) {
173 global $CFG, $DB, $OUTPUT;
175 if (survey_already_done($survey->id, $user->id)) {
176 if ($survey->template == SURVEY_CIQ) { // print out answers for critical incidents
177 $table = new html_table();
178 $table->align = array("left", "left");
180 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
181 $questionorder = explode(",", $survey->questions);
183 foreach ($questionorder as $key=>$val) {
184 $question = $questions[$val];
185 $questiontext = get_string($question->shorttext, "survey");
187 if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) {
188 $answertext = "$answer->answer1";
189 } else {
190 $answertext = "No answer";
192 $table->data[] = array("<b>$questiontext</b>", $answertext);
194 echo html_writer::table($table);
196 } else {
198 survey_print_graph("id=$mod->id&amp;sid=$user->id&amp;type=student.png");
201 } else {
202 print_string("notdone", "survey");
207 * @global stdClass
208 * @global object
209 * @param object $course
210 * @param mixed $viewfullnames
211 * @param int $timestamp
212 * @return bool
214 function survey_print_recent_activity($course, $viewfullnames, $timestart) {
215 global $CFG, $DB, $OUTPUT;
217 $modinfo = get_fast_modinfo($course);
218 $ids = array();
219 foreach ($modinfo->cms as $cm) {
220 if ($cm->modname != 'survey') {
221 continue;
223 if (!$cm->uservisible) {
224 continue;
226 $ids[$cm->instance] = $cm->instance;
229 if (!$ids) {
230 return false;
233 $slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
235 $rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time,
236 u.firstname, u.lastname, u.email, u.picture
237 FROM {survey_answers} sa
238 JOIN {user} u ON u.id = sa.userid
239 WHERE sa.survey IN ($slist) AND sa.time > ?
240 GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture
241 ORDER BY time ASC", array($timestart));
242 if (!$rs->valid()) {
243 $rs->close(); // Not going to iterate (but exit), close rs
244 return false;
247 $surveys = array();
249 foreach ($rs as $survey) {
250 $cm = $modinfo->instances['survey'][$survey->survey];
251 $survey->name = $cm->name;
252 $survey->cmid = $cm->id;
253 $surveys[] = $survey;
255 $rs->close();
257 if (!$surveys) {
258 return false;
261 echo $OUTPUT->heading(get_string('newsurveyresponses', 'survey').':');
262 foreach ($surveys as $survey) {
263 $url = $CFG->wwwroot.'/mod/survey/view.php?id='.$survey->cmid;
264 print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames);
267 return true;
271 * Returns the users with data in one survey
272 * (users with records in survey_analysis and survey_answers, students)
274 * @todo: deprecated - to be deleted in 2.2
276 * @param int $surveyid
277 * @return array
279 function survey_get_participants($surveyid) {
280 global $DB;
282 //Get students from survey_analysis
283 $st_analysis = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
284 FROM {user} u, {survey_analysis} a
285 WHERE a.survey = ? AND
286 u.id = a.userid", array($surveyid));
287 //Get students from survey_answers
288 $st_answers = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
289 FROM {user} u, {survey_answers} a
290 WHERE a.survey = ? AND
291 u.id = a.userid", array($surveyid));
293 //Add st_answers to st_analysis
294 if ($st_answers) {
295 foreach ($st_answers as $st_answer) {
296 $st_analysis[$st_answer->id] = $st_answer;
299 //Return st_analysis array (it contains an array of unique users)
300 return ($st_analysis);
303 // SQL FUNCTIONS ////////////////////////////////////////////////////////
306 * @global object
307 * @param sting $log
308 * @return array
310 function survey_log_info($log) {
311 global $DB;
312 return $DB->get_record_sql("SELECT s.name, u.firstname, u.lastname, u.picture
313 FROM {survey} s, {user} u
314 WHERE s.id = ? AND u.id = ?", array($log->info, $log->userid));
318 * @global object
319 * @param int $surveyid
320 * @param int $groupid
321 * @param int $groupingid
322 * @return array
324 function survey_get_responses($surveyid, $groupid, $groupingid) {
325 global $DB;
327 $params = array('surveyid'=>$surveyid, 'groupid'=>$groupid, 'groupingid'=>$groupingid);
329 if ($groupid) {
330 $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid AND gm.groupid = :groupid ";
332 } else if ($groupingid) {
333 $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid
334 JOIN {groupings_groups} gg ON gm.groupid = gg.groupid AND gg.groupingid = :groupingid ";
335 } else {
336 $groupsjoin = "";
339 $userfields = user_picture::fields('u');
340 return $DB->get_records_sql("SELECT $userfields, MAX(a.time) as time
341 FROM {survey_answers} a
342 JOIN {user} u ON a.userid = u.id
343 $groupsjoin
344 WHERE a.survey = :surveyid
345 GROUP BY $userfields
346 ORDER BY time ASC", $params);
350 * @global object
351 * @param int $survey
352 * @param int $user
353 * @return array
355 function survey_get_analysis($survey, $user) {
356 global $DB;
358 return $DB->get_record_sql("SELECT notes
359 FROM {survey_analysis}
360 WHERE survey=? AND userid=?", array($survey, $user));
364 * @global object
365 * @param int $survey
366 * @param int $user
367 * @param string $notes
369 function survey_update_analysis($survey, $user, $notes) {
370 global $DB;
372 return $DB->execute("UPDATE {survey_analysis}
373 SET notes=?
374 WHERE survey=?
375 AND userid=?", array($notes, $survey, $user));
379 * @global object
380 * @param int $surveyid
381 * @param int $groupid
382 * @param string $sort
383 * @return array
385 function survey_get_user_answers($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC") {
386 global $DB;
388 $params = array('surveyid'=>$surveyid, 'questionid'=>$questionid);
390 if ($groupid) {
391 $groupfrom = ', {groups_members} gm';
392 $groupsql = 'AND gm.groupid = :groupid AND u.id = gm.userid';
393 $params['groupid'] = $groupid;
394 } else {
395 $groupfrom = '';
396 $groupsql = '';
399 $userfields = user_picture::fields('u');
400 return $DB->get_records_sql("SELECT sa.*, $userfields
401 FROM {survey_answers} sa, {user} u $groupfrom
402 WHERE sa.survey = :surveyid
403 AND sa.question = :questionid
404 AND u.id = sa.userid $groupsql
405 ORDER BY $sort", $params);
409 * @global object
410 * @param int $surveyid
411 * @param int $questionid
412 * @param int $userid
413 * @return array
415 function survey_get_user_answer($surveyid, $questionid, $userid) {
416 global $DB;
418 return $DB->get_record_sql("SELECT sa.*
419 FROM {survey_answers} sa
420 WHERE sa.survey = ?
421 AND sa.question = ?
422 AND sa.userid = ?", array($surveyid, $questionid, $userid));
425 // MODULE FUNCTIONS ////////////////////////////////////////////////////////
427 * @global object
428 * @param int $survey
429 * @param int $user
430 * @param string $notes
431 * @return bool|int
433 function survey_add_analysis($survey, $user, $notes) {
434 global $DB;
436 $record = new stdClass();
437 $record->survey = $survey;
438 $record->userid = $user;
439 $record->notes = $notes;
441 return $DB->insert_record("survey_analysis", $record, false);
444 * @global object
445 * @param int $survey
446 * @param int $user
447 * @return bool
449 function survey_already_done($survey, $user) {
450 global $DB;
452 return $DB->record_exists("survey_answers", array("survey"=>$survey, "userid"=>$user));
455 * @param int $surveyid
456 * @param int $groupid
457 * @param int $groupingid
458 * @return int
460 function survey_count_responses($surveyid, $groupid, $groupingid) {
461 if ($responses = survey_get_responses($surveyid, $groupid, $groupingid)) {
462 return count($responses);
463 } else {
464 return 0;
469 * @param int $cmid
470 * @param array $results
471 * @param int $courseid
473 function survey_print_all_responses($cmid, $results, $courseid) {
474 global $OUTPUT;
475 $table = new html_table();
476 $table->head = array ("", get_string("name"), get_string("time"));
477 $table->align = array ("", "left", "left");
478 $table->size = array (35, "", "" );
480 foreach ($results as $a) {
481 $table->data[] = array($OUTPUT->user_picture($a, array('courseid'=>$courseid)),
482 html_writer::link("report.php?action=student&student=$a->id&id=$cmid", fullname($a)),
483 userdate($a->time));
486 echo html_writer::table($table);
490 * @global object
491 * @param int $templateid
492 * @return string
494 function survey_get_template_name($templateid) {
495 global $DB;
497 if ($templateid) {
498 if ($ss = $DB->get_record("surveys", array("id"=>$templateid))) {
499 return $ss->name;
501 } else {
502 return "";
508 * @param string $name
509 * @param array $numwords
510 * @return string
512 function survey_shorten_name ($name, $numwords) {
513 $words = explode(" ", $name);
514 $output = '';
515 for ($i=0; $i < $numwords; $i++) {
516 $output .= $words[$i]." ";
518 return $output;
522 * @todo Check this function
524 * @global object
525 * @global object
526 * @global int
527 * @global void This is never defined
528 * @global object This is defined twice?
529 * @param object $question
531 function survey_print_multi($question) {
532 global $USER, $DB, $qnum, $checklist, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
534 $stripreferthat = get_string("ipreferthat", "survey");
535 $strifoundthat = get_string("ifoundthat", "survey");
536 $strdefault = get_string('notyetanswered', 'survey');
537 $strresponses = get_string('responses', 'survey');
539 echo $OUTPUT->heading($question->text, 3, 'questiontext');
540 echo "\n<table width=\"90%\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\" class=\"surveytable\">";
542 $options = explode( ",", $question->options);
543 $numoptions = count($options);
545 $oneanswer = ($question->type == 1 || $question->type == 2) ? true : false;
547 echo "<tr class=\"smalltext\"><th scope=\"row\">$strresponses</th>";
548 echo "<th scope=\"col\" class=\"hresponse\">". get_string('notyetanswered', 'survey'). "</th>";
549 while (list ($key, $val) = each ($options)) {
550 echo "<th scope=\"col\" class=\"hresponse\">$val</th>\n";
552 echo "</tr>\n";
554 if ($oneanswer) {
555 echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
556 } else {
557 echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
560 $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
562 foreach ($subquestions as $q) {
563 $qnum++;
564 $rowclass = survey_question_rowclass($qnum);
565 if ($q->text) {
566 $q->text = get_string($q->text, "survey");
569 $oneanswer = ($q->type == 1 || $q->type == 2) ? true : false;
570 if ($q->type == 2) {
571 $P = "P";
572 } else {
573 $P = "";
576 echo "<tr class=\"$rowclass rblock\">";
577 if ($oneanswer) {
578 echo "<th scope=\"row\" class=\"optioncell\">";
579 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
580 echo $q->text ."</th>\n";
582 $default = get_accesshide($strdefault);
583 echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" />$default</label></td>";
585 for ($i=1;$i<=$numoptions;$i++) {
586 $hiddentext = get_accesshide($options[$i-1]);
587 $id = "q$P" . $q->id . "_$i";
588 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
590 $checklist["q$P$q->id"] = 0;
592 } else {
593 // yu : fix for MDL-7501, possibly need to use user flag as this is quite ugly.
594 echo "<th scope=\"row\" class=\"optioncell\">";
595 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
596 $qnum++;
597 echo "<span class=\"preferthat smalltext\">$stripreferthat</span> &nbsp; ";
598 echo "<span class=\"option\">$q->text</span></th>\n";
600 $default = get_accesshide($strdefault);
601 echo '<td class="whitecell"><label for="qP'. $P.$q->id .'"><input type="radio" name="qP'.$P.$q->id. '" id="qP'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
604 for ($i=1;$i<=$numoptions;$i++) {
605 $hiddentext = get_accesshide($options[$i-1]);
606 $id = "qP" . $q->id . "_$i";
607 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"qP$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
609 echo "</tr>";
611 echo "<tr class=\"$rowclass rblock\">";
612 echo "<th scope=\"row\" class=\"optioncell\">";
613 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
614 echo "<span class=\"foundthat smalltext\">$strifoundthat</span> &nbsp; ";
615 echo "<span class=\"option\">$q->text</span></th>\n";
617 $default = get_accesshide($strdefault);
618 echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
620 for ($i=1;$i<=$numoptions;$i++) {
621 $hiddentext = get_accesshide($options[$i-1]);
622 $id = "q" . $q->id . "_$i";
623 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
626 $checklist["qP$q->id"] = 0;
627 $checklist["q$q->id"] = 0;
629 echo "</tr>\n";
631 echo "</table>";
636 * @global object
637 * @global int
638 * @param object $question
640 function survey_print_single($question) {
641 global $DB, $qnum, $OUTPUT;
643 $rowclass = survey_question_rowclass(0);
645 $qnum++;
647 echo "<br />\n";
648 echo "<table width=\"90%\" cellpadding=\"4\" cellspacing=\"0\">\n";
649 echo "<tr class=\"$rowclass\">";
650 echo "<th scope=\"row\" class=\"optioncell\"><label for=\"q$question->id\"><b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
651 echo "<span class=\"questioncell\">$question->text</span></label></th>\n";
652 echo "<td class=\"questioncell smalltext\">\n";
655 if ($question->type == 0) { // Plain text field
656 echo "<textarea rows=\"3\" cols=\"30\" name=\"q$question->id\" id=\"q$question->id\">$question->options</textarea>";
658 } else if ($question->type > 0) { // Choose one of a number
659 $strchoose = get_string("choose");
660 echo "<select name=\"q$question->id\" id=\"q$question->id\">";
661 echo "<option value=\"0\" selected=\"selected\">$strchoose...</option>";
662 $options = explode( ",", $question->options);
663 foreach ($options as $key => $val) {
664 $key++;
665 echo "<option value=\"$key\">$val</option>";
667 echo "</select>";
669 } else if ($question->type < 0) { // Choose several of a number
670 $options = explode( ",", $question->options);
671 echo $OUTPUT->notification("This question type not supported yet");
674 echo "</td></tr></table>";
680 * @param int $qnum
681 * @return string
683 function survey_question_rowclass($qnum) {
685 if ($qnum) {
686 return $qnum % 2 ? 'r0' : 'r1';
687 } else {
688 return 'r0';
693 * @global object
694 * @global int
695 * @global int
696 * @param string $url
698 function survey_print_graph($url) {
699 global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH;
701 if (empty($CFG->gdversion)) {
702 echo "(".get_string("gdneed").")";
704 } else {
705 echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"".
706 " src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />";
711 * @return array
713 function survey_get_view_actions() {
714 return array('download','view all','view form','view graph','view report');
718 * @return array
720 function survey_get_post_actions() {
721 return array('submit');
726 * Implementation of the function for printing the form elements that control
727 * whether the course reset functionality affects the survey.
729 * @param object $mform form passed by reference
731 function survey_reset_course_form_definition(&$mform) {
732 $mform->addElement('header', 'surveyheader', get_string('modulenameplural', 'survey'));
733 $mform->addElement('checkbox', 'reset_survey_answers', get_string('deleteallanswers','survey'));
734 $mform->addElement('checkbox', 'reset_survey_analysis', get_string('deleteanalysis','survey'));
735 $mform->disabledIf('reset_survey_analysis', 'reset_survey_answers', 'checked');
739 * Course reset form defaults.
740 * @return array
742 function survey_reset_course_form_defaults($course) {
743 return array('reset_survey_answers'=>1, 'reset_survey_analysis'=>1);
747 * Actual implementation of the reset course functionality, delete all the
748 * survey responses for course $data->courseid.
750 * @global object
751 * @param $data the data submitted from the reset course.
752 * @return array status array
754 function survey_reset_userdata($data) {
755 global $DB;
757 $componentstr = get_string('modulenameplural', 'survey');
758 $status = array();
760 $surveyssql = "SELECT ch.id
761 FROM {survey} ch
762 WHERE ch.course=?";
763 $params = array($data->courseid);
765 if (!empty($data->reset_survey_answers)) {
766 $DB->delete_records_select('survey_answers', "survey IN ($surveyssql)", $params);
767 $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
768 $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
771 if (!empty($data->reset_survey_analysis)) {
772 $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
773 $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
776 // no date shifting
777 return $status;
781 * Returns all other caps used in module
783 * @return array
785 function survey_get_extra_capabilities() {
786 return array('moodle/site:accessallgroups');
790 * @uses FEATURE_GROUPS
791 * @uses FEATURE_GROUPINGS
792 * @uses FEATURE_GROUPMEMBERSONLY
793 * @uses FEATURE_MOD_INTRO
794 * @uses FEATURE_COMPLETION_TRACKS_VIEWS
795 * @uses FEATURE_GRADE_HAS_GRADE
796 * @uses FEATURE_GRADE_OUTCOMES
797 * @param string $feature FEATURE_xx constant for requested feature
798 * @return mixed True if module supports feature, false if not, null if doesn't know
800 function survey_supports($feature) {
801 switch($feature) {
802 case FEATURE_GROUPS: return true;
803 case FEATURE_GROUPINGS: return true;
804 case FEATURE_GROUPMEMBERSONLY: return true;
805 case FEATURE_MOD_INTRO: return true;
806 case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
807 case FEATURE_GRADE_HAS_GRADE: return false;
808 case FEATURE_GRADE_OUTCOMES: return false;
809 case FEATURE_BACKUP_MOODLE2: return true;
810 case FEATURE_SHOW_DESCRIPTION: return true;
812 default: return null;
817 * This function extends the settings navigation block for the site.
819 * It is safe to rely on PAGE here as we will only ever be within the module
820 * context when this is called
822 * @param navigation_node $settings
823 * @param navigation_node $surveynode
825 function survey_extend_settings_navigation($settings, $surveynode) {
826 global $PAGE;
828 if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
829 $responsesnode = $surveynode->add(get_string("responsereports", "survey"));
831 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
832 $responsesnode->add(get_string("summary", "survey"), $url);
834 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales'));
835 $responsesnode->add(get_string("scales", "survey"), $url);
837 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions'));
838 $responsesnode->add(get_string("question", "survey"), $url);
840 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students'));
841 $responsesnode->add(get_string('participants'), $url);
843 if (has_capability('mod/survey:download', $PAGE->cm->context)) {
844 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download'));
845 $surveynode->add(get_string('downloadresults', 'survey'), $url);
851 * Return a list of page types
852 * @param string $pagetype current page type
853 * @param stdClass $parentcontext Block's parent context
854 * @param stdClass $currentcontext Current context of block
856 function survey_page_type_list($pagetype, $parentcontext, $currentcontext) {
857 $module_pagetype = array('mod-survey-*'=>get_string('page-mod-survey-x', 'survey'));
858 return $module_pagetype;