MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / choice / index.php
blobc3a76da85997e3b41357eb4c14096dee2634f9b8
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id',PARAM_INT); // course
8 if (! $course = get_record("course", "id", $id)) {
9 error("Course ID is incorrect");
12 require_course_login($course);
14 add_to_log($course->id, "choice", "view all", "index?id=$course->id", "");
16 $strchoice = get_string("modulename", "choice");
17 $strchoices = get_string("modulenameplural", "choice");
18 $navlinks = array();
19 $navlinks[] = array('name' => $strchoices, 'link' => '', 'type' => 'activity');
20 $navigation = build_navigation($navlinks);
22 print_header_simple("$strchoices", "", $navigation, "", "", true, "", navmenu($course));
25 if (! $choices = get_all_instances_in_course("choice", $course)) {
26 notice("There are no choices", "../../course/view.php?id=$course->id");
29 if ( !empty($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) {
30 foreach ($allanswers as $aa) {
31 $answers[$aa->choiceid] = $aa;
34 } else {
35 $answers = array () ;
39 $timenow = time();
41 if ($course->format == "weeks") {
42 $table->head = array (get_string("week"), get_string("question"), get_string("answer"));
43 $table->align = array ("center", "left", "left");
44 } else if ($course->format == "topics") {
45 $table->head = array (get_string("topic"), get_string("question"), get_string("answer"));
46 $table->align = array ("center", "left", "left");
47 } else {
48 $table->head = array (get_string("question"), get_string("answer"));
49 $table->align = array ("left", "left");
52 $currentsection = "";
54 foreach ($choices as $choice) {
55 if (!empty($answers[$choice->id])) {
56 $answer = $answers[$choice->id];
57 } else {
58 $answer = "";
60 if (!empty($answer->optionid)) {
61 $aa = format_string(choice_get_option_text($choice, $answer->optionid));
62 } else {
63 $aa = "";
65 $printsection = "";
66 if ($choice->section !== $currentsection) {
67 if ($choice->section) {
68 $printsection = $choice->section;
70 if ($currentsection !== "") {
71 $table->data[] = 'hr';
73 $currentsection = $choice->section;
76 //Calculate the href
77 if (!$choice->visible) {
78 //Show dimmed if the mod is hidden
79 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
80 } else {
81 //Show normal if the mod is visible
82 $tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
84 if ($course->format == "weeks" || $course->format == "topics") {
85 $table->data[] = array ($printsection, $tt_href, $aa);
86 } else {
87 $table->data[] = array ($tt_href, $aa);
90 echo "<br />";
91 print_table($table);
93 print_footer($course);