-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
208 lines (177 loc) · 6.83 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
// This file is part of mod_offlinequiz for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script lists all the instances of offlinequiz in a particular course
*
* @package mod
* @subpackage offlinequiz
* @author Juergen Zimmer <[email protected]>
* @copyright 2015 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @since Moodle 2.2
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
require_once("../../config.php");
require_once("locallib.php");
$id = required_param('id', PARAM_INT);
$PAGE->set_url('/mod/offlinequiz/index.php', array('id' => $id));
$PAGE->set_pagelayout('incourse');
if (!$course = $DB->get_record('course', array('id' => $id))) {
print_error('invalidcourseid');
}
$coursecontext = context_course::instance($id);
require_login($course);
$PAGE->set_pagelayout('incourse');
// Log this request.
$params = array(
'context' => $coursecontext
);
$event = \mod_offlinequiz\event\course_module_instance_list_viewed::create($params);
$event->trigger();
// Print the header.
$strofflinequizzes = get_string("modulenameplural", "offlinequiz");
$streditquestions = '';
$editqcontexts = new question_edit_contexts($coursecontext);
if ($editqcontexts->have_one_edit_tab_cap('questions')) {
$streditquestions = "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
<div>
<input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
<input type=\"submit\" value=\"".get_string("editquestions", "offlinequiz")."\" />
</div>
</form>";
}
$PAGE->navbar->add($strofflinequizzes);
$PAGE->set_title($strofflinequizzes);
$PAGE->set_button($streditquestions);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
// Get all the appropriate data.
if (!$offlinequizzes = get_all_instances_in_course('offlinequiz', $course)) {
notice(get_string('thereareno', 'moodle', $strofflinequizzes), "../../course/view.php?id=$course->id");
echo $OUTPUT->footer();
die;
}
$isteacher = has_capability('mod/offlinequiz:viewreports', $coursecontext);
// Check if we need the closing date header.
$showclosingheader = false;
$showfeedback = false;
$therearesome = false;
foreach ($offlinequizzes as $offlinequiz) {
if ($offlinequiz->timeclose != 0 ) {
$showclosingheader = true;
}
if ($offlinequiz->visible || $isteacher) {
$therearesome = true;
}
}
if (!$therearesome) {
notice(get_string('thereareno', 'moodle', $strofflinequizzes), "../../course/view.php?id=$course->id");
echo $OUTPUT->footer();
die;
}
// Configure table for displaying the list of instances.
$headings = array(get_string('name'));
$align = array('left');
if ($showclosingheader) {
array_push($headings, get_string('offlinequizcloses', 'offlinequiz'));
array_push($align, 'left');
}
array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
array_unshift($align, 'center');
$showing = '';
if (has_capability('mod/offlinequiz:viewreports', $coursecontext)) {
array_push($headings, get_string('results', 'offlinequiz'));
array_push($align, 'left');
$showing = 'stats';
} else if (has_capability('mod/offlinequiz:attempt', $coursecontext)) {
array_push($headings, get_string('grade', 'offlinequiz'));
array_push($align, 'left');
if ($showfeedback) {
array_push($headings, get_string('feedback', 'offlinequiz'));
array_push($align, 'left');
}
$showing = 'grades';
}
$table = new html_table();
$table->head = $headings;
$table->align = $align;
// Populate the table with the list of instances.
$currentsection = '';
foreach ($offlinequizzes as $offlinequiz) {
$cm = get_coursemodule_from_instance('offlinequiz', $offlinequiz->id);
$context = context_module::instance($cm->id);
$data = array();
$grades = array();
if ($showing == 'grades') {
if ($gradearray = offlinequiz_get_user_grades($offlinequiz, $USER->id)) {
$grades[$offlinequiz->id] = $gradearray[$USER->id]['rawgrade'];
} else {
$grades[$offlinequiz->id] = null;
}
}
// Section number if necessary.
$strsection = '';
if ($offlinequiz->section != $currentsection) {
if ($offlinequiz->section) {
$strsection = $offlinequiz->section;
$strsection = get_section_name($course, $offlinequiz->section);
}
if ($currentsection) {
$learningtable->data[] = 'hr';
}
$currentsection = $offlinequiz->section;
}
$data[] = $strsection;
// Link to the instance.
$class = '';
if (!$offlinequiz->visible) {
$class = ' class="dimmed"';
}
$data[] = "<a$class href=\"view.php?id=$offlinequiz->coursemodule\">" .
format_string($offlinequiz->name, true) . '</a>';
// Close date.
if ($offlinequiz->timeclose) {
$data[] = userdate($offlinequiz->timeclose);
} else if ($showclosingheader) {
$data[] = '';
}
if ($showing == 'stats') {
// The $offlinequiz objects returned by get_all_instances_in_course have the necessary $cm
// fields set to make the following call work.
$data[] = offlinequiz_attempt_summary_link_to_reports($offlinequiz, $cm, $context);
} else if ($showing == 'grades') {
// Grade and feedback.
list($someoptions, $alloptions) = offlinequiz_get_combined_reviewoptions($offlinequiz);
$grade = '';
$feedback = '';
if ($offlinequiz->grade && array_key_exists($offlinequiz->id, $grades)) {
if ($alloptions->marks >= question_display_options::MARK_AND_MAX) {
$a = new stdClass();
$a->grade = offlinequiz_format_grade($offlinequiz, $grades[$offlinequiz->id]);
$a->maxgrade = offlinequiz_format_grade($offlinequiz, $offlinequiz->grade);
$grade = get_string('outofshort', 'offlinequiz', $a);
}
}
$data[] = $grade;
if ($showfeedback) {
$data[] = $feedback;
}
}
$table->data[] = $data;
} // End of loop over offlinequiz instances.
// Display the table.
echo html_writer::table($table);
// Finish the page.
echo $OUTPUT->footer();