MDL-30431 behat: Fixed wiki behat
[moodle.git] / mod / survey / index.php
blob6c17cdf2cf975f0811cd58dd81fa932d23c9f8a6
1 <?php
3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id', PARAM_INT); // Course Module ID
8 $PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
10 if (!$course = $DB->get_record('course', array('id'=>$id))) {
11 print_error('invalidcourseid');
14 require_course_login($course);
15 $PAGE->set_pagelayout('incourse');
17 $params = array(
18 'context' => context_course::instance($course->id),
19 'courseid' => $course->id
21 $event = \mod_survey\event\course_module_instance_list_viewed::create($params);
22 $event->trigger();
24 $strsurveys = get_string("modulenameplural", "survey");
25 $strname = get_string("name");
26 $strstatus = get_string("status");
27 $strdone = get_string("done", "survey");
28 $strnotdone = get_string("notdone", "survey");
30 $PAGE->navbar->add($strsurveys);
31 $PAGE->set_title($strsurveys);
32 $PAGE->set_heading($course->fullname);
33 echo $OUTPUT->header();
34 echo $OUTPUT->heading($strsurveys);
36 if (! $surveys = get_all_instances_in_course("survey", $course)) {
37 notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
40 $usesections = course_format_uses_sections($course->format);
42 $table = new html_table();
43 $table->width = '100%';
45 if ($usesections) {
46 $strsectionname = get_string('sectionname', 'format_'.$course->format);
47 $table->head = array ($strsectionname, $strname, $strstatus);
48 } else {
49 $table->head = array ($strname, $strstatus);
52 $currentsection = '';
54 foreach ($surveys as $survey) {
55 if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
56 $ss = $strdone;
57 } else {
58 $ss = $strnotdone;
60 $printsection = "";
61 if ($usesections) {
62 if ($survey->section !== $currentsection) {
63 if ($survey->section) {
64 $printsection = get_section_name($course, $survey->section);
66 if ($currentsection !== "") {
67 $table->data[] = 'hr';
69 $currentsection = $survey->section;
72 //Calculate the href
73 if (!$survey->visible) {
74 //Show dimmed if the mod is hidden
75 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
76 } else {
77 //Show normal if the mod is visible
78 $tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
81 if ($usesections) {
82 $table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
83 } else {
84 $table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
88 echo "<br />";
89 echo html_writer::table($table);
90 echo $OUTPUT->footer();