3 * This page lists all the instances of quiz in a particular course
5 * @author Martin Dougiamas and many others.
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 require_once("../../config.php");
10 require_once("locallib.php");
12 $id = required_param('id', PARAM_INT
);
13 if (!$course = get_record("course", "id", $id)) {
14 error("Course ID is incorrect");
16 $coursecontext = get_context_instance(CONTEXT_COURSE
, $id);
17 require_login($course->id
);
18 add_to_log($course->id
, "quiz", "view all", "index.php?id=$course->id", "");
21 $strquizzes = get_string("modulenameplural", "quiz");
22 $streditquestions = '';
23 $editqcontexts = new question_edit_contexts($coursecontext);
24 if ($editqcontexts->have_one_edit_tab_cap('questions')) {
26 "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
28 <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
29 <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
34 $navlinks[] = array('name' => $strquizzes, 'link' => '', 'type' => 'activity');
35 $navigation = build_navigation($navlinks);
37 print_header_simple($strquizzes, '', $navigation,
38 '', '', true, $streditquestions, navmenu($course));
40 // Get all the appropriate data
41 if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
42 notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id");
46 // Configure table for displaying the list of instances.
47 $headings = array(get_string('name'), get_string('quizcloses', 'quiz'));
48 $align = array('left', 'left');
49 if ($course->format
== 'weeks' or $course->format
== 'weekscss') {
50 array_unshift($headings, get_string('week'));
52 array_unshift($headings, get_string('section'));
54 array_unshift($align, 'center');
56 $showing = 'scores'; // default
58 if (has_capability('mod/quiz:viewreports', $coursecontext)) {
59 array_push($headings, get_string('attempts', 'quiz'));
60 array_push($align, 'left');
62 } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
63 array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
64 array_push($align, 'left', 'left');
67 $table->head
= $headings;
68 $table->align
= $align;
70 /// Populate the table with the list of instances.
72 foreach ($quizzes as $quiz) {
73 $cm = get_coursemodule_from_instance('quiz', $quiz->id
);
74 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
77 // Section number if necessary.
79 if ($quiz->section
!= $currentsection) {
81 $strsection = $quiz->section
;
83 if ($currentsection) {
84 $learningtable->data
[] = 'hr';
86 $currentsection = $quiz->section
;
88 $data[] = $strsection;
90 // Link to the instance.
92 if (!$quiz->visible
) {
93 $class = ' class="dimmed"';
95 $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" . format_string($quiz->name
, true) . '</a>';
98 if ($quiz->timeclose
) {
99 $data[] = userdate($quiz->timeclose
);
104 if ($showing == 'stats') {
105 // The $quiz objects returned by get_all_instances_in_course have the necessary $cm
106 // fields set to make the following call work.
107 $attemptcount = quiz_num_attempt_summary($quiz, $quiz);
109 $data[] = "<a$class href=\"report.php?id=$quiz->coursemodule\">$attemptcount</a>";
113 } else if ($showing == 'scores') {
115 // Grade and feedback.
116 $bestgrade = quiz_get_best_grade($quiz, $USER->id
);
117 $attempts = quiz_get_user_attempts($quiz->id
, $USER->id
, 'all');
118 list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
122 if ($quiz->grade
&& !is_null($bestgrade)) {
123 if ($alloptions->scores
) {
124 $grade = "$bestgrade / $quiz->grade";
126 if ($alloptions->overallfeedback
) {
127 $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id
);
134 $table->data
[] = $data;
135 } // End of loop over quiz instances.
137 // Display the table.
142 print_footer($course);