MDL-68261 report_configlog: Log changes from admin/cli/cfg.php
[moodle.git] / blocks / completionstatus / details.php
blob33bbe775f85f4ad741c371bf6f6d94b56ef96e70
1 <?php
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.
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/>.
17 /**
18 * Block for displaying logged in user's course completion status
20 * @package block_completionstatus
21 * @copyright 2009-2012 Catalyst IT Ltd
22 * @author Aaron Barnes <aaronb@catalyst.net.nz>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once(__DIR__.'/../../config.php');
27 require_once("{$CFG->libdir}/completionlib.php");
29 // Load data.
30 $id = required_param('course', PARAM_INT);
31 $userid = optional_param('user', 0, PARAM_INT);
33 // Load course.
34 $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
36 // Load user.
37 if ($userid) {
38 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
39 } else {
40 $user = $USER;
43 // Check permissions.
44 require_login();
46 if (!completion_can_view_data($user->id, $course)) {
47 print_error('cannotviewreport');
50 // Load completion data.
51 $info = new completion_info($course);
53 $returnurl = new moodle_url('/course/view.php', array('id' => $id));
55 // Don't display if completion isn't enabled.
56 if (!$info->is_enabled()) {
57 print_error('completionnotenabled', 'completion', $returnurl);
60 // Check this user is enroled.
61 if (!$info->is_tracked_user($user->id)) {
62 if ($USER->id == $user->id) {
63 print_error('notenroled', 'completion', $returnurl);
64 } else {
65 print_error('usernotenroled', 'completion', $returnurl);
69 // Display page.
71 $PAGE->set_context(context_course::instance($course->id));
73 // Print header.
74 $page = get_string('completionprogressdetails', 'block_completionstatus');
75 $title = format_string($course->fullname) . ': ' . $page;
77 $PAGE->navbar->add($page);
78 $PAGE->set_pagelayout('report');
79 $PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
80 $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
81 $PAGE->set_heading($title);
82 echo $OUTPUT->header();
85 // Display completion status.
86 echo html_writer::start_tag('table', array('class' => 'generalbox boxaligncenter'));
87 echo html_writer::start_tag('tbody');
89 // If not display logged in user, show user name.
90 if ($USER->id != $user->id) {
91 echo html_writer::start_tag('tr');
92 echo html_writer::start_tag('td', array('colspan' => '2'));
93 echo html_writer::tag('b', get_string('showinguser', 'completion') . ' ');
94 $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
95 echo html_writer::link($url, fullname($user));
96 echo html_writer::end_tag('td');
97 echo html_writer::end_tag('tr');
100 echo html_writer::start_tag('tr');
101 echo html_writer::start_tag('td', array('colspan' => '2'));
102 echo html_writer::tag('b', get_string('status') . ' ');
104 // Is course complete?
105 $coursecomplete = $info->is_course_complete($user->id);
107 // Has this user completed any criteria?
108 $criteriacomplete = $info->count_course_user_data($user->id);
110 // Load course completion.
111 $params = array(
112 'userid' => $user->id,
113 'course' => $course->id,
115 $ccompletion = new completion_completion($params);
117 if ($coursecomplete) {
118 echo get_string('complete');
119 } else if (!$criteriacomplete && !$ccompletion->timestarted) {
120 echo html_writer::tag('i', get_string('notyetstarted', 'completion'));
121 } else {
122 echo html_writer::tag('i', get_string('inprogress', 'completion'));
125 echo html_writer::end_tag('td');
126 echo html_writer::end_tag('tr');
128 // Load criteria to display.
129 $completions = $info->get_completions($user->id);
131 // Check if this course has any criteria.
132 if (empty($completions)) {
133 echo html_writer::start_tag('tr');
134 echo html_writer::start_tag('td', array('colspan' => '2'));
135 echo html_writer::start_tag('br');
136 echo $OUTPUT->box(get_string('nocriteriaset', 'completion'), 'noticebox');
137 echo html_writer::end_tag('td');
138 echo html_writer::end_tag('tr');
139 echo html_writer::end_tag('tbody');
140 echo html_writer::end_tag('table');
141 } else {
142 echo html_writer::start_tag('tr');
143 echo html_writer::start_tag('td', array('colspan' => '2'));
144 echo html_writer::tag('b', get_string('required') . ' ');
146 // Get overall aggregation method.
147 $overall = $info->get_aggregation_method();
149 if ($overall == COMPLETION_AGGREGATION_ALL) {
150 echo get_string('criteriarequiredall', 'completion');
151 } else {
152 echo get_string('criteriarequiredany', 'completion');
155 echo html_writer::end_tag('td');
156 echo html_writer::end_tag('tr');
157 echo html_writer::end_tag('tbody');
158 echo html_writer::end_tag('table');
160 // Generate markup for criteria statuses.
161 echo html_writer::start_tag('table',
162 array('class' => 'generalbox logtable boxaligncenter', 'id' => 'criteriastatus', 'width' => '100%'));
163 echo html_writer::start_tag('tbody');
164 echo html_writer::start_tag('tr', array('class' => 'ccheader'));
165 echo html_writer::tag('th', get_string('criteriagroup', 'block_completionstatus'), array('class' => 'c0 header', 'scope' => 'col'));
166 echo html_writer::tag('th', get_string('criteria', 'completion'), array('class' => 'c1 header', 'scope' => 'col'));
167 echo html_writer::tag('th', get_string('requirement', 'block_completionstatus'), array('class' => 'c2 header', 'scope' => 'col'));
168 echo html_writer::tag('th', get_string('status'), array('class' => 'c3 header', 'scope' => 'col'));
169 echo html_writer::tag('th', get_string('complete'), array('class' => 'c4 header', 'scope' => 'col'));
170 echo html_writer::tag('th', get_string('completiondate', 'report_completion'), array('class' => 'c5 header', 'scope' => 'col'));
171 echo html_writer::end_tag('tr');
173 // Save row data.
174 $rows = array();
176 // Loop through course criteria.
177 foreach ($completions as $completion) {
178 $criteria = $completion->get_criteria();
180 $row = array();
181 $row['type'] = $criteria->criteriatype;
182 $row['title'] = $criteria->get_title();
183 $row['status'] = $completion->get_status();
184 $row['complete'] = $completion->is_complete();
185 $row['timecompleted'] = $completion->timecompleted;
186 $row['details'] = $criteria->get_details($completion);
187 $rows[] = $row;
190 // Print table.
191 $last_type = '';
192 $agg_type = false;
193 $oddeven = 0;
195 foreach ($rows as $row) {
197 echo html_writer::start_tag('tr', array('class' => 'r' . $oddeven));
198 // Criteria group.
199 echo html_writer::start_tag('td', array('class' => 'cell c0'));
200 if ($last_type !== $row['details']['type']) {
201 $last_type = $row['details']['type'];
202 echo $last_type;
204 // Reset agg type.
205 $agg_type = true;
206 } else {
207 // Display aggregation type.
208 if ($agg_type) {
209 $agg = $info->get_aggregation_method($row['type']);
210 echo '('. html_writer::start_tag('i');
211 if ($agg == COMPLETION_AGGREGATION_ALL) {
212 echo core_text::strtolower(get_string('all', 'completion'));
213 } else {
214 echo core_text::strtolower(get_string('any', 'completion'));
217 echo ' ' . html_writer::end_tag('i') .core_text::strtolower(get_string('required')).')';
218 $agg_type = false;
221 echo html_writer::end_tag('td');
223 // Criteria title.
224 echo html_writer::start_tag('td', array('class' => 'cell c1'));
225 echo $row['details']['criteria'];
226 echo html_writer::end_tag('td');
228 // Requirement.
229 echo html_writer::start_tag('td', array('class' => 'cell c2'));
230 echo $row['details']['requirement'];
231 echo html_writer::end_tag('td');
233 // Status.
234 echo html_writer::start_tag('td', array('class' => 'cell c3'));
235 echo $row['details']['status'];
236 echo html_writer::end_tag('td');
238 // Is complete.
239 echo html_writer::start_tag('td', array('class' => 'cell c4'));
240 echo $row['complete'] ? get_string('yes') : get_string('no');
241 echo html_writer::end_tag('td');
243 // Completion data.
244 echo html_writer::start_tag('td', array('class' => 'cell c5'));
245 if ($row['timecompleted']) {
246 echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig'));
247 } else {
248 echo '-';
250 echo html_writer::end_tag('td');
251 echo html_writer::end_tag('tr');
252 // For row striping.
253 $oddeven = $oddeven ? 0 : 1;
256 echo html_writer::end_tag('tbody');
257 echo html_writer::end_tag('table');
259 $courseurl = new moodle_url("/course/view.php", array('id' => $course->id));
260 echo html_writer::start_tag('div', array('class' => 'buttons'));
261 echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get');
262 echo html_writer::end_tag('div');
263 echo $OUTPUT->footer();