MDL-37537 completion: Fix incorrect lang string reference in block
[moodle.git] / blocks / completionstatus / details.php
CommitLineData
2be4d090 1<?php
2be4d090
MD
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
2be4d090
MD
17/**
18 * Block for displayed logged in user's course completion status
19 *
ffd8bb20
PS
20 * @package block
21 * @subpackage completion
2ea5b0bb 22 * @copyright 2009-2012 Catalyst IT Ltd
ffd8bb20
PS
23 * @author Aaron Barnes <aaronb@catalyst.net.nz>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2be4d090 25 */
ffd8bb20 26
2ea5b0bb
AB
27require_once(dirname(__FILE__).'/../../config.php');
28require_once("{$CFG->libdir}/completionlib.php");
2be4d090
MD
29
30
31///
32/// Load data
33///
34$id = required_param('course', PARAM_INT);
2be4d090
MD
35$userid = optional_param('user', 0, PARAM_INT);
36
37// Load course
2ea5b0bb 38$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
2be4d090
MD
39
40// Load user
41if ($userid) {
a49cef3e 42 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
2be4d090 43} else {
a49cef3e 44 $user = $USER;
2be4d090
MD
45}
46
47
48// Check permissions
5bb05a46 49require_login();
2be4d090 50
5bb05a46 51if (!completion_can_view_data($user->id, $course)) {
a49cef3e 52 print_error('cannotviewreport');
2be4d090
MD
53}
54
55
0e5e1daa
AB
56// Load completion data
57$info = new completion_info($course);
58
2ea5b0bb 59$returnurl = new moodle_url('/course/view.php', array('id' => $id));
0e5e1daa 60
2be4d090 61// Don't display if completion isn't enabled!
0e5e1daa
AB
62if (!$info->is_enabled()) {
63 print_error('completionnotenabled', 'completion', $returnurl);
2be4d090
MD
64}
65
2be4d090 66// Check this user is enroled
24a3b341 67if (!$info->is_tracked_user($user->id)) {
0e5e1daa
AB
68 if ($USER->id == $user->id) {
69 print_error('notenroled', 'completion', $returnurl);
70 } else {
71 print_error('usernotenroled', 'completion', $returnurl);
72 }
2be4d090
MD
73}
74
75
76///
77/// Display page
78///
2ea5b0bb 79$PAGE->set_context(context_course::instance($course->id));
2be4d090
MD
80
81// Print header
82$page = get_string('completionprogressdetails', 'block_completionstatus');
83$title = format_string($course->fullname) . ': ' . $page;
84
a49cef3e
SH
85$PAGE->navbar->add($page);
86$PAGE->set_pagelayout('standard');
2ea5b0bb 87$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
2be4d090
MD
88$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
89$PAGE->set_heading($title);
90echo $OUTPUT->header();
91
92
93// Display completion status
42d733dc 94echo '<table class="generaltable boxaligncenter"><tbody>';
2be4d090
MD
95
96// If not display logged in user, show user name
97if ($USER->id != $user->id) {
98 echo '<tr><td colspan="2"><b>'.get_string('showinguser', 'completion').'</b>: ';
99 echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a>';
100 echo '</td></tr>';
101}
102
103echo '<tr><td colspan="2"><b>'.get_string('status').':</b> ';
104
105// Is course complete?
106$coursecomplete = $info->is_course_complete($user->id);
107
108// Has this user completed any criteria?
109$criteriacomplete = $info->count_course_user_data($user->id);
110
2ea5b0bb
AB
111// Load course completion
112$params = array(
113 'userid' => $user->id,
114 'course' => $course->id,
115);
116$ccompletion = new completion_completion($params);
117
2be4d090
MD
118if ($coursecomplete) {
119 echo get_string('complete');
2ea5b0bb 120} else if (!$criteriacomplete && !$ccompletion->timestarted) {
2be4d090
MD
121 echo '<i>'.get_string('notyetstarted', 'completion').'</i>';
122} else {
123 echo '<i>'.get_string('inprogress','completion').'</i>';
124}
125
126echo '</td></tr>';
2be4d090 127
2ea5b0bb
AB
128// Load criteria to display
129$completions = $info->get_completions($user->id);
2be4d090 130
2ea5b0bb
AB
131// Check if this course has any criteria
132if (empty($completions)) {
133 echo '<tr><td colspan="2"><br />';
134 echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox');
135 echo '</td></tr></tbody></table>';
2be4d090 136} else {
2ea5b0bb 137 echo '<tr><td colspan="2"><b>'.get_string('required').':</b> ';
2be4d090 138
2ea5b0bb
AB
139 // Get overall aggregation method
140 $overall = $info->get_aggregation_method();
2be4d090 141
2ea5b0bb
AB
142 if ($overall == COMPLETION_AGGREGATION_ALL) {
143 echo get_string('criteriarequiredall', 'completion');
144 } else {
145 echo get_string('criteriarequiredany', 'completion');
146 }
147
148 echo '</td></tr></tbody></table>';
149
150 // Generate markup for criteria statuses
42d733dc 151 echo '<table class="generaltable logtable boxaligncenter" id="criteriastatus" width="100%"><tbody>';
2ea5b0bb
AB
152 echo '<tr class="ccheader">';
153 echo '<th class="c0 header" scope="col">'.get_string('criteriagroup', 'block_completionstatus').'</th>';
154 echo '<th class="c1 header" scope="col">'.get_string('criteria', 'completion').'</th>';
155 echo '<th class="c2 header" scope="col">'.get_string('requirement', 'block_completionstatus').'</th>';
156 echo '<th class="c3 header" scope="col">'.get_string('status').'</th>';
157 echo '<th class="c4 header" scope="col">'.get_string('complete').'</th>';
158 echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'report_completion').'</th>';
159 echo '</tr>';
2be4d090 160
2ea5b0bb
AB
161 // Save row data
162 $rows = array();
163
164 // Loop through course criteria
165 foreach ($completions as $completion) {
166 $criteria = $completion->get_criteria();
167
168 $row = array();
169 $row['type'] = $criteria->criteriatype;
170 $row['title'] = $criteria->get_title();
171 $row['status'] = $completion->get_status();
172 $row['complete'] = $completion->is_complete();
173 $row['timecompleted'] = $completion->timecompleted;
174 $row['details'] = $criteria->get_details($completion);
175 $rows[] = $row;
176 }
2be4d090 177
2ea5b0bb
AB
178 // Print table
179 $last_type = '';
180 $agg_type = false;
181 $oddeven = 0;
2be4d090 182
2ea5b0bb 183 foreach ($rows as $row) {
2be4d090 184
2ea5b0bb 185 echo '<tr class="r' . $oddeven . '">';
2be4d090 186
2ea5b0bb
AB
187 // Criteria group
188 echo '<td class="cell c0">';
189 if ($last_type !== $row['details']['type']) {
190 $last_type = $row['details']['type'];
191 echo $last_type;
192
193 // Reset agg type
194 $agg_type = true;
195 } else {
196 // Display aggregation type
197 if ($agg_type) {
198 $agg = $info->get_aggregation_method($row['type']);
2be4d090 199
2ea5b0bb
AB
200 echo '(<i>';
201
202 if ($agg == COMPLETION_AGGREGATION_ALL) {
15b97a9f 203 echo strtolower(get_string('all', 'completion'));
2ea5b0bb 204 } else {
15b97a9f 205 echo strtolower(get_string('any', 'completion'));
2ea5b0bb
AB
206 }
207
208 echo '</i> '.strtolower(get_string('required')).')';
209 $agg_type = false;
210 }
2be4d090 211 }
2ea5b0bb
AB
212 echo '</td>';
213
214 // Criteria title
215 echo '<td class="cell c1">';
216 echo $row['details']['criteria'];
217 echo '</td>';
218
219 // Requirement
220 echo '<td class="cell c2">';
221 echo $row['details']['requirement'];
222 echo '</td>';
223
224 // Status
225 echo '<td class="cell c3">';
226 echo $row['details']['status'];
227 echo '</td>';
228
229 // Is complete
230 echo '<td class="cell c4">';
231 echo $row['complete'] ? get_string('yes') : get_string('no');
232 echo '</td>';
233
234 // Completion data
235 echo '<td class="cell c5">';
236 if ($row['timecompleted']) {
237 echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig'));
238 } else {
239 echo '-';
240 }
241 echo '</td>';
242 echo '</tr>';
243 // for row striping
244 $oddeven = $oddeven ? 0 : 1;
2be4d090 245 }
2ea5b0bb
AB
246
247 echo '</tbody></table>';
2be4d090
MD
248}
249
2ea5b0bb
AB
250echo '<div class="buttons">';
251$courseurl = new moodle_url("/course/view.php", array('id' => $course->id));
252echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get');
253echo '</div>';
2be4d090
MD
254
255echo $OUTPUT->footer();