3 * This page lists all the instances of quiz in a particular course
6 * @author Martin Dougiamas and many others.
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 require_once("../../config.php");
11 require_once("locallib.php");
13 $id = required_param('id', PARAM_INT
);
14 if (!$course = get_record("course", "id", $id)) {
15 error("Course ID is incorrect");
17 $coursecontext = get_context_instance(CONTEXT_COURSE
, $id);
18 require_login($course->id
);
19 add_to_log($course->id
, "quiz", "view all", "index.php?id=$course->id", "");
22 $strquizzes = get_string("modulenameplural", "quiz");
23 $streditquestions = '';
24 $editqcontexts = new question_edit_contexts($coursecontext);
25 if ($editqcontexts->have_one_edit_tab_cap('questions')) {
27 "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
29 <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
30 <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
35 $navlinks[] = array('name' => $strquizzes, 'link' => '', 'type' => 'activity');
36 $navigation = build_navigation($navlinks);
38 print_header_simple($strquizzes, '', $navigation,
39 '', '', true, $streditquestions, navmenu($course));
41 // Get all the appropriate data
42 if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
43 notice("There are no quizzes", "../../course/view.php?id=$course->id");
47 // Configure table for displaying the list of instances.
48 $headings = array(get_string('name'), get_string('quizcloses', 'quiz'));
49 $align = array('left', 'left');
50 $colsize = array('', '');
51 if ($course->format
== "weeks" ||
$course->format
== "weekscss") {
52 array_unshift($headings, get_string('week'));
53 array_unshift($align, 'center');
54 array_unshift($colsize, 10);
55 } else if ($course->format
== "topics") {
56 array_unshift($headings, get_string('topic'));
57 array_unshift($align, 'center');
58 array_unshift($colsize, 10);
61 if (has_capability('mod/quiz:viewreports', $coursecontext)) {
62 array_push($headings, get_string('attempts', 'quiz'));
63 array_push($align, 'left');
64 array_push($colsize, '');
66 } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
67 array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
68 array_push($align, 'left', 'left');
69 array_push($colsize, '', '');
73 $table->head
= $headings;
74 $table->align
= $align;
75 $table->size
= $colsize;
77 // Poplate the table with the list of instances.
79 foreach ($quizzes as $quiz) {
81 $cm = get_coursemodule_from_instance('quiz', $quiz->id
);
82 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
85 // Section number if necessary.
87 if ($course->format
== "weeks" ||
$course->format
== "weekscss" ||
$course->format
== "topics") {
88 if ($quiz->section
!== $currentsection) {
90 $strsection = $quiz->section
;
92 if ($currentsection !== "") {
93 $table->data
[] = 'hr';
95 $currentsection = $quiz->section
;
98 $data[] = $strsection;
100 // Link to the instance.
102 if (!$quiz->visible
) {
103 $class = ' class="dimmed"';
105 $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" . format_string($quiz->name
, true) . '</a>';
108 if ($quiz->timeclose
) {
109 $data[] = userdate($quiz->timeclose
);
114 if ($showing == 'stats') {
116 // Number of students who have attempted this quiz.
117 if ($a->attemptnum
= count_records('quiz_attempts', 'quiz', $quiz->id
, 'preview', 0)) {
118 $a->studentnum
= count_records_select('quiz_attempts',
119 "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
120 $a->studentstring
= $course->students
;
121 $data[] = "<a href=\"report.php?mode=overview&q=$quiz->id\">" .
122 get_string('numattempts', 'quiz', $a) . '</a>';
126 } else if ($showing = 'scores') {
128 // Grade and feedback.
129 $bestgrade = quiz_get_best_grade($quiz, $USER->id
);
130 $attempts = quiz_get_user_attempts($quiz->id
, $USER->id
, 'all');
131 list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
135 if ($quiz->grade
&& !is_null($bestgrade)) {
136 if ($alloptions->scores
) {
137 $grade = "$bestgrade / $quiz->grade";
139 if ($alloptions->overallfeedback
) {
140 $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id
);
147 $table->data
[] = $data;
148 } // End of loop over quiz instances.
150 // Display the table.
155 print_footer($course);