3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id',PARAM_INT
); // course
8 $PAGE->set_url('/mod/choice/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 $eventdata = array('context' => context_course
::instance($id));
18 $event = \mod_choice\event\course_module_instance_list_viewed
::create($eventdata);
19 $event->add_record_snapshot('course', $course);
22 $strchoice = get_string("modulename", "choice");
23 $strchoices = get_string("modulenameplural", "choice");
24 $PAGE->set_title($strchoices);
25 $PAGE->set_heading($course->fullname
);
26 $PAGE->navbar
->add($strchoices);
27 echo $OUTPUT->header();
29 if (! $choices = get_all_instances_in_course("choice", $course)) {
30 notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id");
33 $usesections = course_format_uses_sections($course->format
);
36 FROM {choice} ch, {choice_answers} cha
37 WHERE cha.choiceid = ch.id AND
38 ch.course = ? AND cha.userid = ?";
41 if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id
, $USER->id
))) {
42 foreach ($allanswers as $aa) {
43 $answers[$aa->choiceid
] = $aa;
51 $table = new html_table();
54 $strsectionname = get_string('sectionname', 'format_'.$course->format
);
55 $table->head
= array ($strsectionname, get_string("question"), get_string("answer"));
56 $table->align
= array ("center", "left", "left");
58 $table->head
= array (get_string("question"), get_string("answer"));
59 $table->align
= array ("left", "left");
64 foreach ($choices as $choice) {
65 if (!empty($answers[$choice->id
])) {
66 $answer = $answers[$choice->id
];
70 if (!empty($answer->optionid
)) {
71 $aa = format_string(choice_get_option_text($choice, $answer->optionid
));
77 if ($choice->section
!== $currentsection) {
78 if ($choice->section
) {
79 $printsection = get_section_name($course, $choice->section
);
81 if ($currentsection !== "") {
82 $table->data
[] = 'hr';
84 $currentsection = $choice->section
;
89 if (!$choice->visible
) {
90 //Show dimmed if the mod is hidden
91 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name
,true)."</a>";
93 //Show normal if the mod is visible
94 $tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name
,true)."</a>";
97 $table->data
[] = array ($printsection, $tt_href, $aa);
99 $table->data
[] = array ($tt_href, $aa);
103 echo html_writer
::table($table);
105 echo $OUTPUT->footer();