MDL-53936 reports: State default index page explicitly in pagination url
[moodle.git] / report / completion / index.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 * Course completion progress report
19 *
76460701
PS
20 * @package report
21 * @subpackage completion
22 * @copyright 2009 Catalyst IT Ltd
23 * @author Aaron Barnes <aaronb@catalyst.net.nz>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2be4d090 25 */
76460701 26
1fcf0ca8 27require_once(__DIR__.'/../../config.php');
e9d20bbc 28require_once("{$CFG->libdir}/completionlib.php");
2be4d090 29
2be4d090
MD
30/**
31 * Configuration
32 */
33define('COMPLETION_REPORT_PAGE', 25);
34define('COMPLETION_REPORT_COL_TITLES', true);
35
76460701 36/*
2be4d090
MD
37 * Setup page, check permissions
38 */
39
40// Get course
e67e026f
SH
41$courseid = required_param('course', PARAM_INT);
42$format = optional_param('format','',PARAM_ALPHA);
43$sort = optional_param('sort','',PARAM_ALPHA);
2be4d090
MD
44$edituser = optional_param('edituser', 0, PARAM_INT);
45
2be4d090 46
74df2951 47$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
24e14bc7 48$context = context_course::instance($course->id);
e67e026f 49
13fdaaac 50$url = new moodle_url('/report/completion/index.php', array('course'=>$course->id));
e67e026f 51$PAGE->set_url($url);
cf5a0dbd 52$PAGE->set_pagelayout('report');
e67e026f
SH
53
54$firstnamesort = ($sort == 'firstname');
55$excel = ($format == 'excelcsv');
56$csv = ($format == 'csv' || $excel);
2be4d090 57
e9d20bbc
AB
58// Load CSV library
59if ($csv) {
60 require_once("{$CFG->libdir}/csvlib.class.php");
61}
62
24a3b341
AB
63// Paging
64$start = optional_param('start', 0, PARAM_INT);
573558af
AL
65$sifirst = optional_param('sifirst', 'all', PARAM_NOTAGS);
66$silast = optional_param('silast', 'all', PARAM_NOTAGS);
2be4d090 67
24e14bc7 68// Whether to show extra user identity information
69$extrafields = get_extra_user_fields($context);
70$leftcols = 1 + count($extrafields);
2be4d090 71
2be4d090
MD
72// Check permissions
73require_login($course);
74
13fdaaac 75require_capability('report/completion:view', $context);
2be4d090
MD
76
77// Get group mode
78$group = groups_get_course_group($course, true); // Supposed to verify group
76460701 79if ($group === 0 && $course->groupmode == SEPARATEGROUPS) {
2be4d090
MD
80 require_capability('moodle/site:accessallgroups',$context);
81}
82
2be4d090
MD
83/**
84 * Load data
85 */
86
ccb8d546
ARN
87// Retrieve course_module data for all modules in the course
88$modinfo = get_fast_modinfo($course);
89
2be4d090
MD
90// Get criteria for course
91$completion = new completion_info($course);
92
93if (!$completion->has_criteria()) {
03f3f718 94 print_error('nocriteriaset', 'completion', $CFG->wwwroot.'/course/report.php?id='.$course->id);
2be4d090
MD
95}
96
97// Get criteria and put in correct order
98$criteria = array();
99
100foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE) as $criterion) {
101 $criteria[] = $criterion;
102}
103
104foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY) as $criterion) {
105 $criteria[] = $criterion;
106}
107
108foreach ($completion->get_criteria() as $criterion) {
109 if (!in_array($criterion->criteriatype, array(
110 COMPLETION_CRITERIA_TYPE_COURSE, COMPLETION_CRITERIA_TYPE_ACTIVITY))) {
111 $criteria[] = $criterion;
112 }
113}
114
115// Can logged in user mark users as complete?
116// (if the logged in user has a role defined in the role criteria)
117$allow_marking = false;
118$allow_marking_criteria = null;
119
120if (!$csv) {
121 // Get role criteria
122 $rcriteria = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
123
124 if (!empty($rcriteria)) {
125
126 foreach ($rcriteria as $rcriterion) {
127 $users = get_role_users($rcriterion->role, $context, true);
128
129 // If logged in user has this role, allow marking complete
130 if ($users && in_array($USER->id, array_keys($users))) {
131 $allow_marking = true;
132 $allow_marking_criteria = $rcriterion->id;
133 break;
134 }
135 }
136 }
137}
138
76460701 139/*
2be4d090
MD
140 * Setup page header
141 */
142if ($csv) {
e9d20bbc 143
8ebbb06a 144 $shortname = format_string($course->shortname, true, array('context' => $context));
2f1e464a 145 $shortname = preg_replace('/[^a-z0-9-]/', '_',core_text::strtolower(strip_tags($shortname)));
e9d20bbc
AB
146
147 $export = new csv_export_writer();
148 $export->set_filename('completion-'.$shortname);
2be4d090
MD
149
150} else {
151 // Navigation and header
cfc33925 152 $strcompletion = get_string('coursecompletion');
2be4d090
MD
153
154 $PAGE->set_title($strcompletion);
155 $PAGE->set_heading($course->fullname);
24a3b341 156
2be4d090
MD
157 echo $OUTPUT->header();
158
2be4d090 159 // Handle groups (if enabled)
30375ee9 160 groups_print_course_menu($course, $CFG->wwwroot.'/report/completion/index.php?course='.$course->id);
2be4d090
MD
161}
162
8b844f70
IT
163if ($sifirst !== 'all') {
164 set_user_preference('ifirst', $sifirst);
165}
166if ($silast !== 'all') {
167 set_user_preference('ilast', $silast);
168}
169
170if (!empty($USER->preference['ifirst'])) {
171 $sifirst = $USER->preference['ifirst'];
172} else {
173 $sifirst = 'all';
174}
175
176if (!empty($USER->preference['ilast'])) {
177 $silast = $USER->preference['ilast'];
178} else {
179 $silast = 'all';
180}
181
24a3b341
AB
182// Generate where clause
183$where = array();
5642a8e5 184$where_params = array();
24a3b341
AB
185
186if ($sifirst !== 'all') {
5642a8e5
AB
187 $where[] = $DB->sql_like('u.firstname', ':sifirst', false);
188 $where_params['sifirst'] = $sifirst.'%';
24a3b341
AB
189}
190
191if ($silast !== 'all') {
5642a8e5
AB
192 $where[] = $DB->sql_like('u.lastname', ':silast', false);
193 $where_params['silast'] = $silast.'%';
24a3b341
AB
194}
195
196// Get user match count
5642a8e5 197$total = $completion->get_num_tracked_users(implode(' AND ', $where), $where_params, $group);
24a3b341
AB
198
199// Total user count
5642a8e5 200$grandtotal = $completion->get_num_tracked_users('', array(), $group);
24a3b341
AB
201
202// If no users in this course what-so-ever
203if (!$grandtotal) {
204 echo $OUTPUT->container(get_string('err_nousers', 'completion'), 'errorbox errorboxcontent');
205 echo $OUTPUT->footer();
206 exit;
207}
208
209// Get user data
210$progress = array();
211
212if ($total) {
213 $progress = $completion->get_progress_all(
214 implode(' AND ', $where),
5642a8e5 215 $where_params,
24a3b341
AB
216 $group,
217 $firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
218 $csv ? 0 : COMPLETION_REPORT_PAGE,
24e14bc7 219 $csv ? 0 : $start,
220 $context
24a3b341
AB
221 );
222}
223
24a3b341 224// Build link for paging
30375ee9 225$link = $CFG->wwwroot.'/report/completion/index.php?course='.$course->id;
24a3b341
AB
226if (strlen($sort)) {
227 $link .= '&amp;sort='.$sort;
228}
229$link .= '&amp;start=';
230
24a3b341 231$pagingbar = '';
24a3b341 232
8b844f70
IT
233// Initials bar.
234$prefixfirst = 'sifirst';
235$prefixlast = 'silast';
236$pagingbar .= $OUTPUT->initials_bar($sifirst, 'firstinitial', get_string('firstname'), $prefixfirst, $url);
237$pagingbar .= $OUTPUT->initials_bar($silast, 'lastinitial', get_string('lastname'), $prefixlast, $url);
2be4d090 238
24a3b341 239// Do we need a paging bar?
76460701 240if ($total > COMPLETION_REPORT_PAGE) {
24a3b341
AB
241
242 // Paging bar
243 $pagingbar .= '<div class="paging">';
244 $pagingbar .= get_string('page').': ';
245
1f186372 246 $sistrings = array();
7229f239
SH
247 if ($sifirst != 'all') {
248 $sistrings[] = "sifirst={$sifirst}";
249 }
250 if ($silast != 'all') {
251 $sistrings[] = "silast={$silast}";
252 }
253 $sistring = !empty($sistrings) ? '&amp;'.implode('&amp;', $sistrings) : '';
1f186372 254
24a3b341
AB
255 // Display previous link
256 if ($start > 0) {
257 $pstart = max($start - COMPLETION_REPORT_PAGE, 0);
1f186372 258 $pagingbar .= "(<a class=\"previous\" href=\"{$link}{$pstart}{$sistring}\">".get_string('previous').'</a>)&nbsp;';
2be4d090
MD
259 }
260
24a3b341
AB
261 // Create page links
262 $curstart = 0;
263 $curpage = 0;
264 while ($curstart < $total) {
265 $curpage++;
266
267 if ($curstart == $start) {
268 $pagingbar .= '&nbsp;'.$curpage.'&nbsp;';
269 }
270 else {
1f186372 271 $pagingbar .= "&nbsp;<a href=\"{$link}{$curstart}{$sistring}\">$curpage</a>&nbsp;";
24a3b341
AB
272 }
273
274 $curstart += COMPLETION_REPORT_PAGE;
275 }
276
277 // Display next link
278 $nstart = $start + COMPLETION_REPORT_PAGE;
279 if ($nstart < $total) {
1f186372 280 $pagingbar .= "&nbsp;(<a class=\"next\" href=\"{$link}{$nstart}{$sistring}\">".get_string('next').'</a>)';
24a3b341
AB
281 }
282
283 $pagingbar .= '</div>';
2be4d090
MD
284}
285
76460701 286/*
2be4d090
MD
287 * Draw table header
288 */
289
290// Start of table
76460701 291if (!$csv) {
2be4d090
MD
292 print '<br class="clearer"/>'; // ugh
293
24a3b341
AB
294 $total_header = ($total == $grandtotal) ? $total : "{$total}/{$grandtotal}";
295 echo $OUTPUT->heading(get_string('allparticipants').": {$total_header}", 3);
296
297 print $pagingbar;
298
299 if (!$total) {
300 echo $OUTPUT->heading(get_string('nothingtodisplay'), 2);
301 echo $OUTPUT->footer();
2be4d090
MD
302 exit;
303 }
304
270b2e44
SL
305 print '<table id="completion-progress" class="table table-bordered generaltable flexible boxaligncenter
306 completionreport" style="text-align: left" cellpadding="5" border="1">';
2be4d090
MD
307
308 // Print criteria group names
fea8be42 309 print PHP_EOL.'<thead><tr style="vertical-align: top">';
24e14bc7 310 echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
311 get_string('criteriagroup', 'completion') . '</th>';
2be4d090
MD
312
313 $current_group = false;
314 $col_count = 0;
315 for ($i = 0; $i <= count($criteria); $i++) {
316
317 if (isset($criteria[$i])) {
318 $criterion = $criteria[$i];
319
320 if ($current_group && $criterion->criteriatype === $current_group->criteriatype) {
321 ++$col_count;
322 continue;
323 }
324 }
325
326 // Print header cell
327 if ($col_count) {
328 print '<th scope="col" colspan="'.$col_count.'" class="colheader criteriagroup">'.$current_group->get_type_title().'</th>';
329 }
330
331 if (isset($criteria[$i])) {
332 // Move to next criteria type
333 $current_group = $criterion;
334 $col_count = 1;
335 }
336 }
337
338 // Overall course completion status
339 print '<th style="text-align: center;">'.get_string('course').'</th>';
340
341 print '</tr>';
342
343 // Print aggregation methods
344 print PHP_EOL.'<tr style="vertical-align: top">';
24e14bc7 345 echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
346 get_string('aggregationmethod', 'completion').'</th>';
2be4d090
MD
347
348 $current_group = false;
349 $col_count = 0;
350 for ($i = 0; $i <= count($criteria); $i++) {
351
352 if (isset($criteria[$i])) {
353 $criterion = $criteria[$i];
354
355 if ($current_group && $criterion->criteriatype === $current_group->criteriatype) {
356 ++$col_count;
357 continue;
358 }
359 }
360
361 // Print header cell
362 if ($col_count) {
363 $has_agg = array(
364 COMPLETION_CRITERIA_TYPE_COURSE,
365 COMPLETION_CRITERIA_TYPE_ACTIVITY,
366 COMPLETION_CRITERIA_TYPE_ROLE,
367 );
368
369 if (in_array($current_group->criteriatype, $has_agg)) {
370 // Try load a aggregation method
371 $method = $completion->get_aggregation_method($current_group->criteriatype);
372
5227344a 373 $method = $method == 1 ? get_string('all') : get_string('any');
2be4d090
MD
374
375 } else {
376 $method = '-';
377 }
378
379 print '<th scope="col" colspan="'.$col_count.'" class="colheader aggheader">'.$method.'</th>';
380 }
381
382 if (isset($criteria[$i])) {
383 // Move to next criteria type
384 $current_group = $criterion;
385 $col_count = 1;
386 }
387 }
388
389 // Overall course aggregation method
390 print '<th scope="col" class="colheader aggheader aggcriteriacourse">';
391
392 // Get course aggregation
393 $method = $completion->get_aggregation_method();
394
5227344a 395 print $method == 1 ? get_string('all') : get_string('any');
2be4d090
MD
396 print '</th>';
397
398 print '</tr>';
399
2be4d090
MD
400 // Print criteria titles
401 if (COMPLETION_REPORT_COL_TITLES) {
402
403 print PHP_EOL.'<tr>';
24e14bc7 404 echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
405 get_string('criteria', 'completion') . '</th>';
2be4d090
MD
406
407 foreach ($criteria as $criterion) {
408 // Get criteria details
409 $details = $criterion->get_title_detailed();
410 print '<th scope="col" class="colheader criterianame">';
c73e3ef1 411 print '<div class="rotated-text-container"><span class="rotated-text">'.$details.'</span></div>';
2be4d090
MD
412 print '</th>';
413 }
414
415 // Overall course completion status
416 print '<th scope="col" class="colheader criterianame">';
c73e3ef1 417 print '<div class="rotated-text-container"><span class="rotated-text">'.get_string('coursecomplete', 'completion').'</span></div>';
2be4d090
MD
418 print '</th></tr>';
419 }
420
421 // Print user heading and icons
422 print '<tr>';
423
424 // User heading / sort option
425 print '<th scope="col" class="completion-sortchoice" style="clear: both;">';
1f186372
TL
426
427 $sistring = "&amp;silast={$silast}&amp;sifirst={$sifirst}";
428
76460701 429 if ($firstnamesort) {
2be4d090 430 print
30375ee9 431 get_string('firstname')." / <a href=\"./index.php?course={$course->id}{$sistring}\">".
2be4d090
MD
432 get_string('lastname').'</a>';
433 } else {
30375ee9 434 print "<a href=\"./index.php?course={$course->id}&amp;sort=firstname{$sistring}\">".
2be4d090
MD
435 get_string('firstname').'</a> / '.
436 get_string('lastname');
437 }
438 print '</th>';
439
24e14bc7 440 // Print user identity columns
441 foreach ($extrafields as $field) {
442 echo '<th scope="col" class="completion-identifyfield">' .
443 get_user_field_name($field) . '</th>';
2be4d090
MD
444 }
445
446 ///
447 /// Print criteria icons
448 ///
449 foreach ($criteria as $criterion) {
450
451 // Generate icon details
2be4d090 452 $iconlink = '';
2be4d090 453 $iconalt = ''; // Required
7062e7c6 454 $iconattributes = array('class' => 'icon');
2be4d090
MD
455 switch ($criterion->criteriatype) {
456
457 case COMPLETION_CRITERIA_TYPE_ACTIVITY:
e9d20bbc 458
2be4d090 459 // Display icon
2e98a747 460 $iconlink = $CFG->wwwroot.'/mod/'.$criterion->module.'/view.php?id='.$criterion->moduleinstance;
7062e7c6 461 $iconattributes['title'] = $modinfo->cms[$criterion->moduleinstance]->get_formatted_name();
2be4d090
MD
462 $iconalt = get_string('modulename', $criterion->module);
463 break;
464
465 case COMPLETION_CRITERIA_TYPE_COURSE:
466 // Load course
ffe50258 467 $crs = $DB->get_record('course', array('id' => $criterion->courseinstance));
2be4d090
MD
468
469 // Display icon
470 $iconlink = $CFG->wwwroot.'/course/view.php?id='.$criterion->courseinstance;
7062e7c6 471 $iconattributes['title'] = format_string($crs->fullname, true, array('context' => context_course::instance($crs->id, MUST_EXIST)));
21c08c63 472 $iconalt = format_string($crs->shortname, true, array('context' => context_course::instance($crs->id)));
2be4d090
MD
473 break;
474
475 case COMPLETION_CRITERIA_TYPE_ROLE:
476 // Load role
477 $role = $DB->get_record('role', array('id' => $criterion->role));
478
479 // Display icon
480 $iconalt = $role->name;
481 break;
482 }
483
7062e7c6
CB
484 // Create icon alt if not supplied
485 if (!$iconalt) {
486 $iconalt = $criterion->get_title();
487 }
488
2be4d090
MD
489 // Print icon and cell
490 print '<th class="criteriaicon">';
491
7062e7c6
CB
492 print ($iconlink ? '<a href="'.$iconlink.'" title="'.$iconattributes['title'].'">' : '');
493 print $OUTPUT->render($criterion->get_icon($iconalt, $iconattributes));
2be4d090
MD
494 print ($iconlink ? '</a>' : '');
495
496 print '</th>';
497 }
498
499 // Overall course completion status
500 print '<th class="criteriaicon">';
663640f5 501 print $OUTPUT->pix_icon('i/course', get_string('coursecomplete', 'completion'));
2be4d090
MD
502 print '</th>';
503
fea8be42 504 print '</tr></thead>';
2be4d090 505
fea8be42 506 echo '<tbody>';
2be4d090 507} else {
e9d20bbc
AB
508 // The CSV headers
509 $row = array();
2be4d090 510
e9d20bbc
AB
511 $row[] = get_string('id', 'report_completion');
512 $row[] = get_string('name', 'report_completion');
513 foreach ($extrafields as $field) {
514 $row[] = get_user_field_name($field);
515 }
516
517 // Add activity headers
518 foreach ($criteria as $criterion) {
519
520 // Handle activity completion differently
521 if ($criterion->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
522
523 // Load activity
524 $mod = $criterion->get_mod_instance();
bdbe385c
MG
525 $row[] = $formattedname = format_string($mod->name, true,
526 array('context' => context_module::instance($criterion->moduleinstance)));
527 $row[] = $formattedname . ' - ' . get_string('completiondate', 'report_completion');
e9d20bbc
AB
528 }
529 else {
530 // Handle all other criteria
531 $row[] = strip_tags($criterion->get_title_detailed());
532 }
533 }
534
535 $row[] = get_string('coursecomplete', 'completion');
536
537 $export->add_data($row);
538}
2be4d090
MD
539
540///
541/// Display a row for each user
542///
24a3b341 543foreach ($progress as $user) {
2be4d090
MD
544
545 // User name
76460701 546 if ($csv) {
e9d20bbc
AB
547 $row = array();
548 $row[] = $user->id;
549 $row[] = fullname($user);
24e14bc7 550 foreach ($extrafields as $field) {
e9d20bbc 551 $row[] = $user->{$field};
2be4d090
MD
552 }
553 } else {
554 print PHP_EOL.'<tr id="user-'.$user->id.'">';
555
5bb05a46
AB
556 if (completion_can_view_data($user->id, $course)) {
557 $userurl = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
558 } else {
559 $userurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
560 }
561
e9d20bbc 562 print '<th scope="row"><a href="'.$userurl->out().'">'.fullname($user).'</a></th>';
24e14bc7 563 foreach ($extrafields as $field) {
e9d20bbc 564 echo '<td>'.s($user->{$field}).'</td>';
2be4d090
MD
565 }
566 }
567
568 // Progress for each course completion criteria
569 foreach ($criteria as $criterion) {
570
e9d20bbc
AB
571 $criteria_completion = $completion->get_user_completion($user->id, $criterion);
572 $is_complete = $criteria_completion->is_complete();
573
2be4d090
MD
574 // Handle activity completion differently
575 if ($criterion->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
576
577 // Load activity
ccb8d546 578 $activity = $modinfo->cms[$criterion->moduleinstance];
2be4d090
MD
579
580 // Get progress information and state
f0d64796
MG
581 if (array_key_exists($activity->id, $user->progress)) {
582 $state = $user->progress[$activity->id]->completionstate;
583 } else if ($is_complete) {
584 $state = COMPLETION_COMPLETE;
585 } else {
586 $state = COMPLETION_INCOMPLETE;
587 }
e9d20bbc
AB
588 if ($is_complete) {
589 $date = userdate($criteria_completion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
2be4d090 590 } else {
e9d20bbc 591 $date = '';
2be4d090
MD
592 }
593
2be4d090
MD
594 // Work out how it corresponds to an icon
595 switch($state) {
e9d20bbc
AB
596 case COMPLETION_INCOMPLETE : $completiontype = 'n'; break;
597 case COMPLETION_COMPLETE : $completiontype = 'y'; break;
598 case COMPLETION_COMPLETE_PASS : $completiontype = 'pass'; break;
599 case COMPLETION_COMPLETE_FAIL : $completiontype = 'fail'; break;
2be4d090
MD
600 }
601
e9d20bbc
AB
602 $auto = $activity->completion == COMPLETION_TRACKING_AUTOMATIC;
603 $completionicon = 'completion-'.($auto ? 'auto' : 'manual').'-'.$completiontype;
2be4d090 604
e9d20bbc
AB
605 $describe = get_string('completion-'.$completiontype, 'completion');
606 $a = new StdClass();
607 $a->state = $describe;
608 $a->date = $date;
609 $a->user = fullname($user);
bdbe385c 610 $a->activity = $activity->get_formatted_name();
e9d20bbc 611 $fulldescribe = get_string('progress-title', 'completion', $a);
2be4d090 612
76460701 613 if ($csv) {
e9d20bbc
AB
614 $row[] = $describe;
615 $row[] = $date;
2be4d090
MD
616 } else {
617 print '<td class="completion-progresscell">';
618
663640f5 619 print $OUTPUT->pix_icon('i/' . $completionicon, $fulldescribe);
2be4d090
MD
620
621 print '</td>';
622 }
623
624 continue;
625 }
626
627 // Handle all other criteria
2be4d090
MD
628 $completiontype = $is_complete ? 'y' : 'n';
629 $completionicon = 'completion-auto-'.$completiontype;
630
e9d20bbc 631 $describe = get_string('completion-'.$completiontype, 'completion');
2be4d090 632
fbaea88f 633 $a = new stdClass();
2be4d090 634 $a->state = $describe;
e9d20bbc
AB
635
636 if ($is_complete) {
637 $a->date = userdate($criteria_completion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
638 } else {
639 $a->date = '';
640 }
641
2be4d090
MD
642 $a->user = fullname($user);
643 $a->activity = strip_tags($criterion->get_title());
644 $fulldescribe = get_string('progress-title', 'completion', $a);
645
646 if ($csv) {
e9d20bbc 647 $row[] = $a->date;
2be4d090
MD
648 } else {
649
e9d20bbc 650 print '<td class="completion-progresscell">';
2be4d090 651
e9d20bbc
AB
652 if ($allow_marking_criteria === $criterion->id) {
653 $describe = get_string('completion-'.$completiontype, 'completion');
654
655 $toggleurl = new moodle_url(
656 '/course/togglecompletion.php',
657 array(
658 'user' => $user->id,
659 'course' => $course->id,
660 'rolec' => $allow_marking_criteria,
661 'sesskey' => sesskey()
662 )
663 );
664
bdbe385c 665 print '<a href="'.$toggleurl->out().'" title="'.s(get_string('clicktomarkusercomplete', 'report_completion')).'">' .
663640f5 666 $OUTPUT->pix_icon('i/completion-manual-' . ($is_complete ? 'y' : 'n'), $describe) . '</a></td>';
2be4d090 667 } else {
663640f5 668 print $OUTPUT->pix_icon('i/' . $completionicon, $fulldescribe) . '</td>';
2be4d090 669 }
e9d20bbc
AB
670
671 print '</td>';
2be4d090
MD
672 }
673 }
674
675 // Handle overall course completion
676
677 // Load course completion
678 $params = array(
679 'userid' => $user->id,
680 'course' => $course->id
681 );
682
683 $ccompletion = new completion_completion($params);
684 $completiontype = $ccompletion->is_complete() ? 'y' : 'n';
685
e9d20bbc 686 $describe = get_string('completion-'.$completiontype, 'completion');
2be4d090
MD
687
688 $a = new StdClass;
e9d20bbc
AB
689
690 if ($ccompletion->is_complete()) {
691 $a->date = userdate($ccompletion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
692 } else {
693 $a->date = '';
694 }
695
2be4d090 696 $a->state = $describe;
2be4d090
MD
697 $a->user = fullname($user);
698 $a->activity = strip_tags(get_string('coursecomplete', 'completion'));
699 $fulldescribe = get_string('progress-title', 'completion', $a);
700
701 if ($csv) {
e9d20bbc 702 $row[] = $a->date;
2be4d090
MD
703 } else {
704
705 print '<td class="completion-progresscell">';
706
707 // Display course completion status icon
663640f5 708 print $OUTPUT->pix_icon('i/completion-auto-' . $completiontype, $fulldescribe);
2be4d090
MD
709
710 print '</td>';
711 }
712
76460701 713 if ($csv) {
e9d20bbc 714 $export->add_data($row);
2be4d090
MD
715 } else {
716 print '</tr>';
717 }
718}
719
76460701 720if ($csv) {
e9d20bbc 721 $export->download_file();
fea8be42
JM
722} else {
723 echo '</tbody>';
2be4d090 724}
e9d20bbc 725
2be4d090
MD
726print '</table>';
727print $pagingbar;
728
e9d20bbc
AB
729$csvurl = new moodle_url('/report/completion/index.php', array('course' => $course->id, 'format' => 'csv'));
730$excelurl = new moodle_url('/report/completion/index.php', array('course' => $course->id, 'format' => 'excelcsv'));
731
732print '<ul class="export-actions">';
733print '<li><a href="'.$csvurl->out().'">'.get_string('csvdownload','completion').'</a></li>';
734print '<li><a href="'.$excelurl->out().'">'.get_string('excelcsvdownload','completion').'</a></li>';
735print '</ul>';
2be4d090
MD
736
737echo $OUTPUT->footer($course);
df132336
AA
738
739// Trigger a report viewed event.
740$event = \report_completion\event\report_viewed::create(array('context' => $context));
741$event->trigger();