Moodle release 2.5beta
[moodle.git] / mod / survey / lib.php
bloba4e3e7ba4e0db73e67df6929def71e0145c7cf4f
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;
270 // SQL FUNCTIONS ////////////////////////////////////////////////////////
273 * @global object
274 * @param sting $log
275 * @return array
277 function survey_log_info($log) {
278 global $DB;
279 return $DB->get_record_sql("SELECT s.name, u.firstname, u.lastname, u.picture
280 FROM {survey} s, {user} u
281 WHERE s.id = ? AND u.id = ?", array($log->info, $log->userid));
285 * @global object
286 * @param int $surveyid
287 * @param int $groupid
288 * @param int $groupingid
289 * @return array
291 function survey_get_responses($surveyid, $groupid, $groupingid) {
292 global $DB;
294 $params = array('surveyid'=>$surveyid, 'groupid'=>$groupid, 'groupingid'=>$groupingid);
296 if ($groupid) {
297 $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid AND gm.groupid = :groupid ";
299 } else if ($groupingid) {
300 $groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid
301 JOIN {groupings_groups} gg ON gm.groupid = gg.groupid AND gg.groupingid = :groupingid ";
302 } else {
303 $groupsjoin = "";
306 $userfields = user_picture::fields('u');
307 return $DB->get_records_sql("SELECT $userfields, MAX(a.time) as time
308 FROM {survey_answers} a
309 JOIN {user} u ON a.userid = u.id
310 $groupsjoin
311 WHERE a.survey = :surveyid
312 GROUP BY $userfields
313 ORDER BY time ASC", $params);
317 * @global object
318 * @param int $survey
319 * @param int $user
320 * @return array
322 function survey_get_analysis($survey, $user) {
323 global $DB;
325 return $DB->get_record_sql("SELECT notes
326 FROM {survey_analysis}
327 WHERE survey=? AND userid=?", array($survey, $user));
331 * @global object
332 * @param int $survey
333 * @param int $user
334 * @param string $notes
336 function survey_update_analysis($survey, $user, $notes) {
337 global $DB;
339 return $DB->execute("UPDATE {survey_analysis}
340 SET notes=?
341 WHERE survey=?
342 AND userid=?", array($notes, $survey, $user));
346 * @global object
347 * @param int $surveyid
348 * @param int $groupid
349 * @param string $sort
350 * @return array
352 function survey_get_user_answers($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC") {
353 global $DB;
355 $params = array('surveyid'=>$surveyid, 'questionid'=>$questionid);
357 if ($groupid) {
358 $groupfrom = ', {groups_members} gm';
359 $groupsql = 'AND gm.groupid = :groupid AND u.id = gm.userid';
360 $params['groupid'] = $groupid;
361 } else {
362 $groupfrom = '';
363 $groupsql = '';
366 $userfields = user_picture::fields('u');
367 return $DB->get_records_sql("SELECT sa.*, $userfields
368 FROM {survey_answers} sa, {user} u $groupfrom
369 WHERE sa.survey = :surveyid
370 AND sa.question = :questionid
371 AND u.id = sa.userid $groupsql
372 ORDER BY $sort", $params);
376 * @global object
377 * @param int $surveyid
378 * @param int $questionid
379 * @param int $userid
380 * @return array
382 function survey_get_user_answer($surveyid, $questionid, $userid) {
383 global $DB;
385 return $DB->get_record_sql("SELECT sa.*
386 FROM {survey_answers} sa
387 WHERE sa.survey = ?
388 AND sa.question = ?
389 AND sa.userid = ?", array($surveyid, $questionid, $userid));
392 // MODULE FUNCTIONS ////////////////////////////////////////////////////////
394 * @global object
395 * @param int $survey
396 * @param int $user
397 * @param string $notes
398 * @return bool|int
400 function survey_add_analysis($survey, $user, $notes) {
401 global $DB;
403 $record = new stdClass();
404 $record->survey = $survey;
405 $record->userid = $user;
406 $record->notes = $notes;
408 return $DB->insert_record("survey_analysis", $record, false);
411 * @global object
412 * @param int $survey
413 * @param int $user
414 * @return bool
416 function survey_already_done($survey, $user) {
417 global $DB;
419 return $DB->record_exists("survey_answers", array("survey"=>$survey, "userid"=>$user));
422 * @param int $surveyid
423 * @param int $groupid
424 * @param int $groupingid
425 * @return int
427 function survey_count_responses($surveyid, $groupid, $groupingid) {
428 if ($responses = survey_get_responses($surveyid, $groupid, $groupingid)) {
429 return count($responses);
430 } else {
431 return 0;
436 * @param int $cmid
437 * @param array $results
438 * @param int $courseid
440 function survey_print_all_responses($cmid, $results, $courseid) {
441 global $OUTPUT;
442 $table = new html_table();
443 $table->head = array ("", get_string("name"), get_string("time"));
444 $table->align = array ("", "left", "left");
445 $table->size = array (35, "", "" );
447 foreach ($results as $a) {
448 $table->data[] = array($OUTPUT->user_picture($a, array('courseid'=>$courseid)),
449 html_writer::link("report.php?action=student&student=$a->id&id=$cmid", fullname($a)),
450 userdate($a->time));
453 echo html_writer::table($table);
457 * @global object
458 * @param int $templateid
459 * @return string
461 function survey_get_template_name($templateid) {
462 global $DB;
464 if ($templateid) {
465 if ($ss = $DB->get_record("surveys", array("id"=>$templateid))) {
466 return $ss->name;
468 } else {
469 return "";
475 * @param string $name
476 * @param array $numwords
477 * @return string
479 function survey_shorten_name ($name, $numwords) {
480 $words = explode(" ", $name);
481 $output = '';
482 for ($i=0; $i < $numwords; $i++) {
483 $output .= $words[$i]." ";
485 return $output;
489 * @todo Check this function
491 * @global object
492 * @global object
493 * @global int
494 * @global void This is never defined
495 * @global object This is defined twice?
496 * @param object $question
498 function survey_print_multi($question) {
499 global $USER, $DB, $qnum, $checklist, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
501 $stripreferthat = get_string("ipreferthat", "survey");
502 $strifoundthat = get_string("ifoundthat", "survey");
503 $strdefault = get_string('notyetanswered', 'survey');
504 $strresponses = get_string('responses', 'survey');
506 echo $OUTPUT->heading($question->text, 3, 'questiontext');
507 echo "\n<table width=\"90%\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\" class=\"surveytable\">";
509 $options = explode( ",", $question->options);
510 $numoptions = count($options);
512 $oneanswer = ($question->type == 1 || $question->type == 2) ? true : false;
514 echo "<tr class=\"smalltext\"><th scope=\"row\">$strresponses</th>";
515 echo "<th scope=\"col\" class=\"hresponse\">". get_string('notyetanswered', 'survey'). "</th>";
516 while (list ($key, $val) = each ($options)) {
517 echo "<th scope=\"col\" class=\"hresponse\">$val</th>\n";
519 echo "</tr>\n";
521 if ($oneanswer) {
522 echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
523 } else {
524 echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
527 $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
529 foreach ($subquestions as $q) {
530 $qnum++;
531 $rowclass = survey_question_rowclass($qnum);
532 if ($q->text) {
533 $q->text = get_string($q->text, "survey");
536 $oneanswer = ($q->type == 1 || $q->type == 2) ? true : false;
537 if ($q->type == 2) {
538 $P = "P";
539 } else {
540 $P = "";
543 echo "<tr class=\"$rowclass rblock\">";
544 if ($oneanswer) {
545 echo "<th scope=\"row\" class=\"optioncell\">";
546 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
547 echo $q->text ."</th>\n";
549 $default = get_accesshide($strdefault);
550 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>";
552 for ($i=1;$i<=$numoptions;$i++) {
553 $hiddentext = get_accesshide($options[$i-1]);
554 $id = "q$P" . $q->id . "_$i";
555 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
557 $checklist["q$P$q->id"] = 0;
559 } else {
560 // yu : fix for MDL-7501, possibly need to use user flag as this is quite ugly.
561 echo "<th scope=\"row\" class=\"optioncell\">";
562 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
563 $qnum++;
564 echo "<span class=\"preferthat smalltext\">$stripreferthat</span> &nbsp; ";
565 echo "<span class=\"option\">$q->text</span></th>\n";
567 $default = get_accesshide($strdefault);
568 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>';
571 for ($i=1;$i<=$numoptions;$i++) {
572 $hiddentext = get_accesshide($options[$i-1]);
573 $id = "qP" . $q->id . "_$i";
574 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"qP$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
576 echo "</tr>";
578 echo "<tr class=\"$rowclass rblock\">";
579 echo "<th scope=\"row\" class=\"optioncell\">";
580 echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
581 echo "<span class=\"foundthat smalltext\">$strifoundthat</span> &nbsp; ";
582 echo "<span class=\"option\">$q->text</span></th>\n";
584 $default = get_accesshide($strdefault);
585 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>';
587 for ($i=1;$i<=$numoptions;$i++) {
588 $hiddentext = get_accesshide($options[$i-1]);
589 $id = "q" . $q->id . "_$i";
590 echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
593 $checklist["qP$q->id"] = 0;
594 $checklist["q$q->id"] = 0;
596 echo "</tr>\n";
598 echo "</table>";
603 * @global object
604 * @global int
605 * @param object $question
607 function survey_print_single($question) {
608 global $DB, $qnum, $OUTPUT;
610 $rowclass = survey_question_rowclass(0);
612 $qnum++;
614 echo "<br />\n";
615 echo "<table width=\"90%\" cellpadding=\"4\" cellspacing=\"0\">\n";
616 echo "<tr class=\"$rowclass\">";
617 echo "<th scope=\"row\" class=\"optioncell\"><label for=\"q$question->id\"><b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
618 echo "<span class=\"questioncell\">$question->text</span></label></th>\n";
619 echo "<td class=\"questioncell smalltext\">\n";
622 if ($question->type == 0) { // Plain text field
623 echo "<textarea rows=\"3\" cols=\"30\" name=\"q$question->id\" id=\"q$question->id\">$question->options</textarea>";
625 } else if ($question->type > 0) { // Choose one of a number
626 $strchoose = get_string("choose");
627 echo "<select name=\"q$question->id\" id=\"q$question->id\">";
628 echo "<option value=\"0\" selected=\"selected\">$strchoose...</option>";
629 $options = explode( ",", $question->options);
630 foreach ($options as $key => $val) {
631 $key++;
632 echo "<option value=\"$key\">$val</option>";
634 echo "</select>";
636 } else if ($question->type < 0) { // Choose several of a number
637 $options = explode( ",", $question->options);
638 echo $OUTPUT->notification("This question type not supported yet");
641 echo "</td></tr></table>";
647 * @param int $qnum
648 * @return string
650 function survey_question_rowclass($qnum) {
652 if ($qnum) {
653 return $qnum % 2 ? 'r0' : 'r1';
654 } else {
655 return 'r0';
660 * @global object
661 * @global int
662 * @global int
663 * @param string $url
665 function survey_print_graph($url) {
666 global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH;
668 echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"".
669 " src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />";
673 * @return array
675 function survey_get_view_actions() {
676 return array('download','view all','view form','view graph','view report');
680 * @return array
682 function survey_get_post_actions() {
683 return array('submit');
688 * Implementation of the function for printing the form elements that control
689 * whether the course reset functionality affects the survey.
691 * @param object $mform form passed by reference
693 function survey_reset_course_form_definition(&$mform) {
694 $mform->addElement('header', 'surveyheader', get_string('modulenameplural', 'survey'));
695 $mform->addElement('checkbox', 'reset_survey_answers', get_string('deleteallanswers','survey'));
696 $mform->addElement('checkbox', 'reset_survey_analysis', get_string('deleteanalysis','survey'));
697 $mform->disabledIf('reset_survey_analysis', 'reset_survey_answers', 'checked');
701 * Course reset form defaults.
702 * @return array
704 function survey_reset_course_form_defaults($course) {
705 return array('reset_survey_answers'=>1, 'reset_survey_analysis'=>1);
709 * Actual implementation of the reset course functionality, delete all the
710 * survey responses for course $data->courseid.
712 * @global object
713 * @param $data the data submitted from the reset course.
714 * @return array status array
716 function survey_reset_userdata($data) {
717 global $DB;
719 $componentstr = get_string('modulenameplural', 'survey');
720 $status = array();
722 $surveyssql = "SELECT ch.id
723 FROM {survey} ch
724 WHERE ch.course=?";
725 $params = array($data->courseid);
727 if (!empty($data->reset_survey_answers)) {
728 $DB->delete_records_select('survey_answers', "survey IN ($surveyssql)", $params);
729 $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
730 $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
733 if (!empty($data->reset_survey_analysis)) {
734 $DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
735 $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
738 // no date shifting
739 return $status;
743 * Returns all other caps used in module
745 * @return array
747 function survey_get_extra_capabilities() {
748 return array('moodle/site:accessallgroups');
752 * @uses FEATURE_GROUPS
753 * @uses FEATURE_GROUPINGS
754 * @uses FEATURE_GROUPMEMBERSONLY
755 * @uses FEATURE_MOD_INTRO
756 * @uses FEATURE_COMPLETION_TRACKS_VIEWS
757 * @uses FEATURE_GRADE_HAS_GRADE
758 * @uses FEATURE_GRADE_OUTCOMES
759 * @param string $feature FEATURE_xx constant for requested feature
760 * @return mixed True if module supports feature, false if not, null if doesn't know
762 function survey_supports($feature) {
763 switch($feature) {
764 case FEATURE_GROUPS: return true;
765 case FEATURE_GROUPINGS: return true;
766 case FEATURE_GROUPMEMBERSONLY: return true;
767 case FEATURE_MOD_INTRO: return true;
768 case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
769 case FEATURE_GRADE_HAS_GRADE: return false;
770 case FEATURE_GRADE_OUTCOMES: return false;
771 case FEATURE_BACKUP_MOODLE2: return true;
772 case FEATURE_SHOW_DESCRIPTION: return true;
774 default: return null;
779 * This function extends the settings navigation block for the site.
781 * It is safe to rely on PAGE here as we will only ever be within the module
782 * context when this is called
784 * @param navigation_node $settings
785 * @param navigation_node $surveynode
787 function survey_extend_settings_navigation($settings, $surveynode) {
788 global $PAGE;
790 if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
791 $responsesnode = $surveynode->add(get_string("responsereports", "survey"));
793 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
794 $responsesnode->add(get_string("summary", "survey"), $url);
796 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales'));
797 $responsesnode->add(get_string("scales", "survey"), $url);
799 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions'));
800 $responsesnode->add(get_string("question", "survey"), $url);
802 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students'));
803 $responsesnode->add(get_string('participants'), $url);
805 if (has_capability('mod/survey:download', $PAGE->cm->context)) {
806 $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download'));
807 $surveynode->add(get_string('downloadresults', 'survey'), $url);
813 * Return a list of page types
814 * @param string $pagetype current page type
815 * @param stdClass $parentcontext Block's parent context
816 * @param stdClass $currentcontext Current context of block
818 function survey_page_type_list($pagetype, $parentcontext, $currentcontext) {
819 $module_pagetype = array('mod-survey-*'=>get_string('page-mod-survey-x', 'survey'));
820 return $module_pagetype;