forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
details.php
263 lines (219 loc) · 9.33 KB
/
details.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
// This file is part of 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/>.
/**
* Block for displaying logged in user's course completion status
*
* @package block_completionstatus
* @copyright 2009-2012 Catalyst IT Ltd
* @author Aaron Barnes <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__).'/../../config.php');
require_once("{$CFG->libdir}/completionlib.php");
// Load data.
$id = required_param('course', PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);
// Load course.
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
// Load user.
if ($userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else {
$user = $USER;
}
// Check permissions.
require_login();
if (!completion_can_view_data($user->id, $course)) {
print_error('cannotviewreport');
}
// Load completion data.
$info = new completion_info($course);
$returnurl = new moodle_url('/course/view.php', array('id' => $id));
// Don't display if completion isn't enabled.
if (!$info->is_enabled()) {
print_error('completionnotenabled', 'completion', $returnurl);
}
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
print_error('notenroled', 'completion', $returnurl);
} else {
print_error('usernotenroled', 'completion', $returnurl);
}
}
// Display page.
$PAGE->set_context(context_course::instance($course->id));
// Print header.
$page = get_string('completionprogressdetails', 'block_completionstatus');
$title = format_string($course->fullname) . ': ' . $page;
$PAGE->navbar->add($page);
$PAGE->set_pagelayout('report');
$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($title);
echo $OUTPUT->header();
// Display completion status.
echo html_writer::start_tag('table', array('class' => 'generalbox boxaligncenter'));
echo html_writer::start_tag('tbody');
// If not display logged in user, show user name.
if ($USER->id != $user->id) {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('showinguser', 'completion'));
$url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
echo html_writer::link($url, fullname($user));
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
}
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('status'));
// Is course complete?
$coursecomplete = $info->is_course_complete($user->id);
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($user->id);
// Load course completion.
$params = array(
'userid' => $user->id,
'course' => $course->id,
);
$ccompletion = new completion_completion($params);
if ($coursecomplete) {
echo get_string('complete');
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
echo html_writer::tag('i', get_string('notyetstarted', 'completion'));
} else {
echo html_writer::tag('i', get_string('inprogress', 'completion'));
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// Load criteria to display.
$completions = $info->get_completions($user->id);
// Check if this course has any criteria.
if (empty($completions)) {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::start_tag('br');
echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox');
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
} else {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('required'));
// Get overall aggregation method.
$overall = $info->get_aggregation_method();
if ($overall == COMPLETION_AGGREGATION_ALL) {
echo get_string('criteriarequiredall', 'completion');
} else {
echo get_string('criteriarequiredany', 'completion');
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
// Generate markup for criteria statuses.
echo html_writer::start_tag('table',
array('class' => 'generalbox logtable boxaligncenter', 'id' => 'criteriastatus', 'width' => '100%'));
echo html_writer::start_tag('tbody');
echo html_writer::start_tag('tr', array('class' => 'ccheader'));
echo html_writer::tag('th', get_string('criteriagroup', 'block_completionstatus'), array('class' => 'c0 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('criteria', 'completion'), array('class' => 'c1 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('requirement', 'block_completionstatus'), array('class' => 'c2 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('status'), array('class' => 'c3 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('complete'), array('class' => 'c4 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('completiondate', 'report_completion'), array('class' => 'c5 header', 'scope' => 'col'));
echo html_writer::end_tag('tr');
// Save row data.
$rows = array();
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$row = array();
$row['type'] = $criteria->criteriatype;
$row['title'] = $criteria->get_title();
$row['status'] = $completion->get_status();
$row['complete'] = $completion->is_complete();
$row['timecompleted'] = $completion->timecompleted;
$row['details'] = $criteria->get_details($completion);
$rows[] = $row;
}
// Print table.
$last_type = '';
$agg_type = false;
$oddeven = 0;
foreach ($rows as $row) {
echo html_writer::start_tag('tr', array('class' => 'r' . $oddeven));
// Criteria group.
echo html_writer::start_tag('td', array('class' => 'cell c0'));
if ($last_type !== $row['details']['type']) {
$last_type = $row['details']['type'];
echo $last_type;
// Reset agg type.
$agg_type = true;
} else {
// Display aggregation type.
if ($agg_type) {
$agg = $info->get_aggregation_method($row['type']);
echo '('. html_writer::start_tag('i');
if ($agg == COMPLETION_AGGREGATION_ALL) {
echo core_text::strtolower(get_string('all', 'completion'));
} else {
echo core_text::strtolower(get_string('any', 'completion'));
}
echo html_writer::end_tag('i') .core_text::strtolower(get_string('required')).')';
$agg_type = false;
}
}
echo html_writer::end_tag('td');
// Criteria title.
echo html_writer::start_tag('td', array('class' => 'cell c1'));
echo $row['details']['criteria'];
echo html_writer::end_tag('td');
// Requirement.
echo html_writer::start_tag('td', array('class' => 'cell c2'));
echo $row['details']['requirement'];
echo html_writer::end_tag('td');
// Status.
echo html_writer::start_tag('td', array('class' => 'cell c3'));
echo $row['details']['status'];
echo html_writer::end_tag('td');
// Is complete.
echo html_writer::start_tag('td', array('class' => 'cell c4'));
echo $row['complete'] ? get_string('yes') : get_string('no');
echo html_writer::end_tag('td');
// Completion data.
echo html_writer::start_tag('td', array('class' => 'cell c5'));
if ($row['timecompleted']) {
echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig'));
} else {
echo '-';
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// For row striping.
$oddeven = $oddeven ? 0 : 1;
}
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
}
$courseurl = new moodle_url("/course/view.php", array('id' => $course->id));
echo html_writer::start_tag('div', array('class' => 'buttons'));
echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get');
echo html_writer::end_tag('div');
echo $OUTPUT->footer();