2008-07-28 12:31:29 +00:00
|
|
|
<?php
|
2011-11-02 11:24:44 +01:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activity progress reports
|
|
|
|
*
|
|
|
|
* @package report
|
|
|
|
* @subpackage progress
|
|
|
|
* @copyright 2008 Sam Marshall
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2021-02-22 09:32:12 +05:30
|
|
|
use core\report_helper;
|
|
|
|
use \report_progress\local\helper;
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
require('../../config.php');
|
2009-05-08 09:00:41 +00:00
|
|
|
require_once($CFG->libdir . '/completionlib.php');
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Get course
|
2009-09-21 07:22:57 +00:00
|
|
|
$id = required_param('course',PARAM_INT);
|
2011-11-02 11:24:44 +01:00
|
|
|
$course = $DB->get_record('course',array('id'=>$id));
|
|
|
|
if (!$course) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcourseid');
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
2011-04-13 17:24:56 +01:00
|
|
|
$context = context_course::instance($course->id);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Sort (default lastname, optionally firstname)
|
2010-08-12 03:40:35 +00:00
|
|
|
$sort = optional_param('sort','',PARAM_ALPHA);
|
|
|
|
$firstnamesort = $sort == 'firstname';
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// CSV format
|
2010-08-12 03:40:35 +00:00
|
|
|
$format = optional_param('format','',PARAM_ALPHA);
|
|
|
|
$excel = $format == 'excelcsv';
|
|
|
|
$csv = $format == 'csv' || $excel;
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2021-04-02 12:06:18 +07:00
|
|
|
// Paging, sorting and filtering.
|
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
2014-11-18 14:01:27 +02:00
|
|
|
$sifirst = optional_param('sifirst', 'all', PARAM_NOTAGS);
|
|
|
|
$silast = optional_param('silast', 'all', PARAM_NOTAGS);
|
2021-04-02 12:06:18 +07:00
|
|
|
$groupid = optional_param('group', 0, PARAM_INT);
|
|
|
|
$activityinclude = optional_param('activityinclude', 'all', PARAM_TEXT);
|
|
|
|
$activityorder = optional_param('activityorder', 'orderincourse', PARAM_TEXT);
|
2022-12-12 21:12:02 +01:00
|
|
|
$activitysection = optional_param('activitysection', -1, PARAM_INT);
|
2008-10-24 16:20:37 +00:00
|
|
|
|
2011-04-13 17:24:56 +01:00
|
|
|
// Whether to show extra user identity information
|
2021-05-11 16:14:48 +01:00
|
|
|
$userfields = \core_user\fields::for_identity($context);
|
|
|
|
$extrafields = $userfields->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
|
2011-04-13 17:24:56 +01:00
|
|
|
$leftcols = 1 + count($extrafields);
|
2008-07-29 10:37:46 +00:00
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
function csv_quote($value) {
|
2008-07-28 17:11:51 +00:00
|
|
|
global $excel;
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($excel) {
|
2013-08-06 20:58:28 +02:00
|
|
|
return core_text::convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE');
|
2008-07-28 17:11:51 +00:00
|
|
|
} else {
|
|
|
|
return '"'.str_replace('"',"'",$value).'"';
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 11:19:41 +01:00
|
|
|
$url = new moodle_url('/report/progress/index.php', array('course'=>$id));
|
2024-02-12 14:12:45 +05:30
|
|
|
$PAGE->navigation->override_active_url($url);
|
2009-09-21 07:22:57 +00:00
|
|
|
if ($sort !== '') {
|
|
|
|
$url->param('sort', $sort);
|
|
|
|
}
|
|
|
|
if ($format !== '') {
|
|
|
|
$url->param('format', $format);
|
|
|
|
}
|
2021-04-02 12:06:18 +07:00
|
|
|
if ($page !== 0) {
|
|
|
|
$url->param('page', $page);
|
2009-09-21 07:22:57 +00:00
|
|
|
}
|
2017-02-17 14:48:02 +00:00
|
|
|
if ($sifirst !== 'all') {
|
|
|
|
$url->param('sifirst', $sifirst);
|
|
|
|
}
|
|
|
|
if ($silast !== 'all') {
|
|
|
|
$url->param('silast', $silast);
|
|
|
|
}
|
2021-04-02 12:06:18 +07:00
|
|
|
if ($groupid !== 0) {
|
|
|
|
$url->param('group', $groupid);
|
|
|
|
}
|
|
|
|
if ($activityinclude !== '') {
|
|
|
|
$url->param('activityinclude', $activityinclude);
|
|
|
|
}
|
|
|
|
if ($activityorder !== '') {
|
|
|
|
$url->param('activityorder', $activityorder);
|
|
|
|
}
|
2022-12-12 21:12:02 +01:00
|
|
|
if ($activitysection !== '') {
|
|
|
|
$url->param('activitysection', $activitysection);
|
|
|
|
}
|
2021-04-02 12:06:18 +07:00
|
|
|
|
2009-09-21 07:22:57 +00:00
|
|
|
$PAGE->set_url($url);
|
2010-12-02 07:31:48 +00:00
|
|
|
$PAGE->set_pagelayout('report');
|
2009-09-21 07:22:57 +00:00
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
require_login($course);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Check basic permission
|
2011-11-02 11:19:41 +01:00
|
|
|
require_capability('report/progress:view',$context);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Get group mode
|
2011-11-02 11:24:44 +01:00
|
|
|
$group = groups_get_course_group($course,true); // Supposed to verify group
|
|
|
|
if ($group===0 && $course->groupmode==SEPARATEGROUPS) {
|
2008-07-28 12:31:29 +00:00
|
|
|
require_capability('moodle/site:accessallgroups',$context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get data on activities and progress of all users, and give error if we've
|
2021-04-02 12:06:18 +07:00
|
|
|
// nothing to display (no users or no activities).
|
2011-11-02 11:24:44 +01:00
|
|
|
$completion = new completion_info($course);
|
2022-12-12 21:12:02 +01:00
|
|
|
list($activitytypes, $activities) = helper::get_activities_to_show($completion, $activityinclude, $activityorder, $activitysection);
|
2021-04-02 12:06:18 +07:00
|
|
|
$output = $PAGE->get_renderer('report_progress');
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2016-12-12 12:17:59 +11:00
|
|
|
if ($sifirst !== 'all') {
|
|
|
|
set_user_preference('ifirst', $sifirst);
|
|
|
|
}
|
|
|
|
if ($silast !== 'all') {
|
|
|
|
set_user_preference('ilast', $silast);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($USER->preference['ifirst'])) {
|
|
|
|
$sifirst = $USER->preference['ifirst'];
|
|
|
|
} else {
|
|
|
|
$sifirst = 'all';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($USER->preference['ilast'])) {
|
|
|
|
$silast = $USER->preference['ilast'];
|
|
|
|
} else {
|
|
|
|
$silast = 'all';
|
|
|
|
}
|
|
|
|
|
2010-08-12 03:40:35 +00:00
|
|
|
// Generate where clause
|
|
|
|
$where = array();
|
2010-09-08 02:32:43 +00:00
|
|
|
$where_params = array();
|
2010-08-12 03:40:35 +00:00
|
|
|
|
|
|
|
if ($sifirst !== 'all') {
|
2018-11-29 13:45:38 +08:00
|
|
|
$where[] = $DB->sql_like('u.firstname', ':sifirst', false, false);
|
2010-09-08 02:32:43 +00:00
|
|
|
$where_params['sifirst'] = $sifirst.'%';
|
2010-08-12 03:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($silast !== 'all') {
|
2018-11-29 13:45:38 +08:00
|
|
|
$where[] = $DB->sql_like('u.lastname', ':silast', false, false);
|
2010-09-08 02:32:43 +00:00
|
|
|
$where_params['silast'] = $silast.'%';
|
2010-08-12 03:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get user match count
|
2010-09-08 02:32:43 +00:00
|
|
|
$total = $completion->get_num_tracked_users(implode(' AND ', $where), $where_params, $group);
|
2010-08-12 03:40:35 +00:00
|
|
|
|
|
|
|
// Total user count
|
2010-09-08 02:32:43 +00:00
|
|
|
$grandtotal = $completion->get_num_tracked_users('', array(), $group);
|
2010-08-12 03:40:35 +00:00
|
|
|
|
|
|
|
// Get user data
|
|
|
|
$progress = array();
|
|
|
|
|
|
|
|
if ($total) {
|
|
|
|
$progress = $completion->get_progress_all(
|
|
|
|
implode(' AND ', $where),
|
2010-09-08 02:32:43 +00:00
|
|
|
$where_params,
|
2010-08-12 03:40:35 +00:00
|
|
|
$group,
|
2017-12-12 09:39:17 +08:00
|
|
|
$firstnamesort ? 'u.firstname ASC, u.lastname ASC' : 'u.lastname ASC, u.firstname ASC',
|
2021-04-02 12:06:18 +07:00
|
|
|
$csv ? 0 : helper::COMPLETION_REPORT_PAGE,
|
|
|
|
$csv ? 0 : $page * helper::COMPLETION_REPORT_PAGE,
|
2011-04-13 17:24:56 +01:00
|
|
|
$context
|
2010-08-12 03:40:35 +00:00
|
|
|
);
|
|
|
|
}
|
2008-07-28 17:11:51 +00:00
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are some users/actvs
|
2011-09-07 11:46:28 +12:00
|
|
|
|
|
|
|
$shortname = format_string($course->shortname, true, array('context' => $context));
|
2008-07-28 12:31:29 +00:00
|
|
|
header('Content-Disposition: attachment; filename=progress.'.
|
2013-08-06 20:58:28 +02:00
|
|
|
preg_replace('/[^a-z0-9-]/','_',core_text::strtolower(strip_tags($shortname))).'.csv');
|
2008-07-28 17:11:51 +00:00
|
|
|
// Unicode byte-order mark for Excel
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($excel) {
|
2008-07-28 17:11:51 +00:00
|
|
|
header('Content-Type: text/csv; charset=UTF-16LE');
|
|
|
|
print chr(0xFF).chr(0xFE);
|
|
|
|
$sep="\t".chr(0);
|
2008-11-18 08:13:26 +00:00
|
|
|
$line="\n".chr(0);
|
2008-07-28 17:11:51 +00:00
|
|
|
} else {
|
|
|
|
header('Content-Type: text/csv; charset=UTF-8');
|
|
|
|
$sep=",";
|
|
|
|
$line="\n";
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Navigation and header
|
|
|
|
$strreports = get_string("reports");
|
2010-10-18 10:15:37 +00:00
|
|
|
$strcompletion = get_string('activitycompletion', 'completion');
|
2009-09-03 08:47:24 +00:00
|
|
|
|
|
|
|
$PAGE->set_title($strcompletion);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
echo $OUTPUT->header();
|
2021-02-22 09:32:12 +05:30
|
|
|
|
|
|
|
// Print the selected dropdown.
|
|
|
|
$pluginname = get_string('pluginname', 'report_progress');
|
|
|
|
report_helper::print_report_selector($pluginname);
|
2017-09-29 09:43:43 +08:00
|
|
|
$PAGE->requires->js_call_amd('report_progress/completion_override', 'init', [fullname($USER)]);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2021-04-02 12:06:18 +07:00
|
|
|
// Handle groups (if enabled).
|
2022-02-04 12:48:28 +01:00
|
|
|
echo $output->render_groups_select($url, $course);
|
2021-04-02 12:06:18 +07:00
|
|
|
|
|
|
|
// Display include activity filter.
|
|
|
|
echo $output->render_include_activity_select($url, $activitytypes, $activityinclude);
|
|
|
|
|
|
|
|
// Display activity order options.
|
|
|
|
echo $output->render_activity_order_select($url, $activityorder);
|
|
|
|
|
2022-12-12 21:12:02 +01:00
|
|
|
// Display section selector.
|
|
|
|
$modinfo = get_fast_modinfo($course);
|
|
|
|
$sections = [];
|
|
|
|
$cmids = array_keys($completion->get_activities());
|
|
|
|
foreach ($modinfo->get_sections() as $sectionnum => $section) {
|
|
|
|
if (empty(array_intersect($section, $cmids))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$sectionname = get_section_name($course, $sectionnum);
|
|
|
|
if (empty($sectionname)) {
|
|
|
|
$sectionname = get_string('section') . ' ' . $sectionnum;
|
|
|
|
}
|
|
|
|
$sections[$sectionnum] = $sectionname;
|
|
|
|
}
|
|
|
|
echo $output->render_activity_section_select($url, $activitysection, $sections);
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if (count($activities)==0) {
|
2011-01-10 15:20:24 +00:00
|
|
|
echo $OUTPUT->container(get_string('err_noactivities', 'completion'), 'errorbox errorboxcontent');
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no users in this course what-so-ever
|
|
|
|
if (!$grandtotal) {
|
|
|
|
echo $OUTPUT->container(get_string('err_nousers', 'completion'), 'errorbox errorboxcontent');
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2010-08-12 03:40:35 +00:00
|
|
|
// Build link for paging
|
2011-11-02 11:19:41 +01:00
|
|
|
$link = $CFG->wwwroot.'/report/progress/?course='.$course->id;
|
2010-08-12 03:40:35 +00:00
|
|
|
if (strlen($sort)) {
|
|
|
|
$link .= '&sort='.$sort;
|
|
|
|
}
|
|
|
|
$link .= '&start=';
|
|
|
|
|
|
|
|
$pagingbar = '';
|
|
|
|
|
2016-12-12 12:17:59 +11:00
|
|
|
// Initials bar.
|
|
|
|
$prefixfirst = 'sifirst';
|
|
|
|
$prefixlast = 'silast';
|
2019-12-03 22:44:13 +00:00
|
|
|
|
|
|
|
// The URL used in the initials bar should reset the 'start' parameter.
|
2021-04-02 12:06:18 +07:00
|
|
|
$initialsbarurl = fullclone($url);
|
|
|
|
$initialsbarurl->remove_params('page');
|
2019-12-03 22:44:13 +00:00
|
|
|
|
2021-04-02 12:06:18 +07:00
|
|
|
$pagingbar .= $OUTPUT->initials_bar($sifirst, 'firstinitial mt-2', get_string('firstname'), $prefixfirst, $initialsbarurl);
|
2019-12-03 22:44:13 +00:00
|
|
|
$pagingbar .= $OUTPUT->initials_bar($silast, 'lastinitial', get_string('lastname'), $prefixlast, $initialsbarurl);
|
2021-04-02 12:06:18 +07:00
|
|
|
$pagingbar .= $OUTPUT->paging_bar($total, $page, helper::COMPLETION_REPORT_PAGE, $url);
|
2008-10-24 16:20:37 +00:00
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
// Okay, let's draw the table of progress info,
|
|
|
|
|
2008-11-18 08:13:26 +00:00
|
|
|
// Start of table
|
2011-11-02 11:24:44 +01:00
|
|
|
if (!$csv) {
|
2008-07-28 12:31:29 +00:00
|
|
|
print '<br class="clearer"/>'; // ugh
|
2010-08-12 03:40:35 +00:00
|
|
|
|
|
|
|
print $pagingbar;
|
|
|
|
|
|
|
|
if (!$total) {
|
2023-11-21 22:01:47 +01:00
|
|
|
echo $OUTPUT->notification(get_string('nothingtodisplay'), 'info', false);
|
2010-09-22 08:52:02 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-07-28 12:31:29 +00:00
|
|
|
exit;
|
|
|
|
}
|
2010-08-12 03:40:35 +00:00
|
|
|
|
2012-03-12 10:37:35 +00:00
|
|
|
print '<div id="completion-progress-wrapper" class="no-overflow">';
|
2023-11-08 15:40:08 +01:00
|
|
|
print '<table id="completion-progress" class="generaltable flexible boxaligncenter"><thead><tr style="vertical-align:top">';
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// User heading / sort option
|
|
|
|
print '<th scope="col" class="completion-sortchoice">';
|
2011-08-16 12:00:29 +09:30
|
|
|
|
2021-04-02 12:06:18 +07:00
|
|
|
$sorturl = fullclone($url);
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($firstnamesort) {
|
2021-04-02 12:06:18 +07:00
|
|
|
$sorturl->param('sort', 'lastname');
|
|
|
|
$sortlink = html_writer::link($sorturl, get_string('lastname'));
|
2008-11-18 08:13:26 +00:00
|
|
|
print
|
2021-04-02 12:06:18 +07:00
|
|
|
get_string('firstname') . " / $sortlink";
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2021-04-02 12:06:18 +07:00
|
|
|
$sorturl->param('sort', 'firstname');
|
|
|
|
$sortlink = html_writer::link($sorturl, get_string('firstname'));
|
|
|
|
print "$sortlink / " . get_string('lastname');
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
print '</th>';
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2011-04-13 17:24:56 +01:00
|
|
|
// Print user identity columns
|
|
|
|
foreach ($extrafields as $field) {
|
|
|
|
echo '<th scope="col" class="completion-identifyfield">' .
|
2021-03-15 15:36:32 +00:00
|
|
|
\core_user\fields::get_display_name($field) . '</th>';
|
2008-07-29 10:37:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-04-13 17:24:56 +01:00
|
|
|
foreach ($extrafields as $field) {
|
2021-03-15 15:36:32 +00:00
|
|
|
echo $sep . csv_quote(\core_user\fields::get_display_name($field));
|
2008-07-29 10:37:46 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Activities
|
2013-07-31 11:37:32 +10:00
|
|
|
$formattedactivities = array();
|
2008-07-28 12:31:29 +00:00
|
|
|
foreach($activities as $activity) {
|
2013-07-31 11:37:32 +10:00
|
|
|
$datepassed = $activity->completionexpected && $activity->completionexpected <= time();
|
|
|
|
$datepassedclass = $datepassed ? 'completion-expired' : '';
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($activity->completionexpected) {
|
2019-12-06 13:46:21 +11:00
|
|
|
if ($csv) {
|
|
|
|
$datetext = userdate($activity->completionexpected, "%F %T");
|
|
|
|
} else {
|
|
|
|
$datetext = userdate($activity->completionexpected, get_string('strftimedate', 'langconfig'));
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
$datetext='';
|
|
|
|
}
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2008-08-21 16:35:12 +00:00
|
|
|
// Some names (labels) come URL-encoded and can be very long, so shorten them
|
2015-03-12 19:44:39 +08:00
|
|
|
$displayname = format_string($activity->name, true, array('context' => $activity->context));
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2015-03-12 19:44:39 +08:00
|
|
|
print $sep.csv_quote($displayname).$sep.csv_quote($datetext);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2015-03-12 19:44:39 +08:00
|
|
|
$shortenedname = shorten_text($displayname);
|
2016-12-23 15:06:12 +00:00
|
|
|
print '<th scope="col" class="completion-header '.$datepassedclass.'">'.
|
2008-07-28 12:31:29 +00:00
|
|
|
'<a href="'.$CFG->wwwroot.'/mod/'.$activity->modname.
|
2015-03-12 19:44:39 +08:00
|
|
|
'/view.php?id='.$activity->id.'" title="' . s($displayname) . '">'.
|
2016-12-23 15:06:12 +00:00
|
|
|
'<div class="rotated-text-container"><span class="rotated-text">'.$shortenedname.'</span></div>'.
|
2017-01-19 16:20:27 +08:00
|
|
|
'<div class="modicon">'.
|
2022-03-18 14:00:53 +08:00
|
|
|
$OUTPUT->image_icon('monologo', get_string('modulename', $activity->modname), $activity->modname) .
|
2017-01-19 16:20:27 +08:00
|
|
|
'</div>'.
|
|
|
|
'</a>';
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($activity->completionexpected) {
|
2008-07-28 12:31:29 +00:00
|
|
|
print '<div class="completion-expected"><span>'.$datetext.'</span></div>';
|
|
|
|
}
|
|
|
|
print '</th>';
|
|
|
|
}
|
2013-07-31 11:37:32 +10:00
|
|
|
$formattedactivities[$activity->id] = (object)array(
|
|
|
|
'datepassedclass' => $datepassedclass,
|
|
|
|
'displayname' => $displayname,
|
|
|
|
);
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2008-07-28 17:11:51 +00:00
|
|
|
print $line;
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2013-04-10 11:50:56 +08:00
|
|
|
print '</tr></thead><tbody>';
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Row for each user
|
2010-08-12 03:40:35 +00:00
|
|
|
foreach($progress as $user) {
|
2008-07-28 12:31:29 +00:00
|
|
|
// User name
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2021-02-06 13:08:52 +01:00
|
|
|
print csv_quote(fullname($user, has_capability('moodle/site:viewfullnames', $context)));
|
2011-04-13 17:24:56 +01:00
|
|
|
foreach ($extrafields as $field) {
|
|
|
|
echo $sep . csv_quote($user->{$field});
|
2008-07-29 10:37:46 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2021-02-06 13:08:52 +01:00
|
|
|
print '<tr><th scope="row"><a href="' . $CFG->wwwroot . '/user/view.php?id=' .
|
|
|
|
$user->id . '&course=' . $course->id . '">' .
|
|
|
|
fullname($user, has_capability('moodle/site:viewfullnames', $context)) . '</a></th>';
|
2011-04-13 17:24:56 +01:00
|
|
|
foreach ($extrafields as $field) {
|
|
|
|
echo '<td>' . s($user->{$field}) . '</td>';
|
2008-07-29 10:37:46 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Progress for each activity
|
|
|
|
foreach($activities as $activity) {
|
|
|
|
|
|
|
|
// Get progress information and state
|
2017-04-03 10:08:10 +08:00
|
|
|
if (array_key_exists($activity->id, $user->progress)) {
|
|
|
|
$thisprogress = $user->progress[$activity->id];
|
|
|
|
$state = $thisprogress->completionstate;
|
2017-02-17 14:48:02 +00:00
|
|
|
$overrideby = $thisprogress->overrideby;
|
2017-04-03 10:08:10 +08:00
|
|
|
$date = userdate($thisprogress->timemodified);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2017-04-03 10:08:10 +08:00
|
|
|
$state = COMPLETION_INCOMPLETE;
|
2017-02-17 14:48:02 +00:00
|
|
|
$overrideby = 0;
|
2017-04-03 10:08:10 +08:00
|
|
|
$date = '';
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Work out how it corresponds to an icon
|
|
|
|
switch($state) {
|
2017-02-17 14:48:02 +00:00
|
|
|
case COMPLETION_INCOMPLETE :
|
|
|
|
$completiontype = 'n'.($overrideby ? '-override' : '');
|
|
|
|
break;
|
|
|
|
case COMPLETION_COMPLETE :
|
|
|
|
$completiontype = 'y'.($overrideby ? '-override' : '');
|
|
|
|
break;
|
|
|
|
case COMPLETION_COMPLETE_PASS :
|
|
|
|
$completiontype = 'pass';
|
|
|
|
break;
|
|
|
|
case COMPLETION_COMPLETE_FAIL :
|
|
|
|
$completiontype = 'fail';
|
|
|
|
break;
|
2008-11-18 08:13:26 +00:00
|
|
|
}
|
2017-09-29 09:43:43 +08:00
|
|
|
$completiontrackingstring = $activity->completion == COMPLETION_TRACKING_AUTOMATIC ? 'auto' : 'manual';
|
|
|
|
$completionicon = 'completion-' . $completiontrackingstring. '-' . $completiontype;
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2017-02-17 14:48:02 +00:00
|
|
|
if ($overrideby) {
|
2017-09-04 13:54:14 +08:00
|
|
|
$overridebyuser = \core_user::get_user($overrideby, '*', MUST_EXIST);
|
2017-02-17 14:48:02 +00:00
|
|
|
$describe = get_string('completion-' . $completiontype, 'completion', fullname($overridebyuser));
|
|
|
|
} else {
|
|
|
|
$describe = get_string('completion-' . $completiontype, 'completion');
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
$a=new StdClass;
|
|
|
|
$a->state=$describe;
|
|
|
|
$a->date=$date;
|
2021-02-06 13:08:52 +01:00
|
|
|
$a->user = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
2015-03-12 19:44:39 +08:00
|
|
|
$a->activity = $formattedactivities[$activity->id]->displayname;
|
2008-07-28 12:31:29 +00:00
|
|
|
$fulldescribe=get_string('progress-title','completion',$a);
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2019-12-06 13:46:21 +11:00
|
|
|
if ($date != '') {
|
|
|
|
$date = userdate($thisprogress->timemodified, "%F %T");
|
|
|
|
}
|
2008-07-28 17:11:51 +00:00
|
|
|
print $sep.csv_quote($describe).$sep.csv_quote($date);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
2017-04-03 10:08:10 +08:00
|
|
|
$celltext = $OUTPUT->pix_icon('i/' . $completionicon, s($fulldescribe));
|
2017-02-17 14:48:02 +00:00
|
|
|
if (has_capability('moodle/course:overridecompletion', $context) &&
|
|
|
|
$state != COMPLETION_COMPLETE_PASS && $state != COMPLETION_COMPLETE_FAIL) {
|
|
|
|
$newstate = ($state == COMPLETION_COMPLETE) ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
|
|
|
|
$changecompl = $user->id . '-' . $activity->id . '-' . $newstate;
|
2017-09-04 13:54:14 +08:00
|
|
|
$url = new moodle_url($PAGE->url, ['sesskey' => sesskey()]);
|
2017-06-02 15:03:48 +08:00
|
|
|
$celltext = html_writer::link($url, $celltext, array('class' => 'changecompl', 'data-changecompl' => $changecompl,
|
2017-09-29 09:43:43 +08:00
|
|
|
'data-activityname' => $a->activity,
|
|
|
|
'data-userfullname' => $a->user,
|
|
|
|
'data-completiontracking' => $completiontrackingstring,
|
2018-12-17 16:06:21 +08:00
|
|
|
'role' => 'button'));
|
2017-02-17 14:48:02 +00:00
|
|
|
}
|
2013-07-31 11:37:32 +10:00
|
|
|
print '<td class="completion-progresscell '.$formattedactivities[$activity->id]->datepassedclass.'">'.
|
2017-02-17 14:48:02 +00:00
|
|
|
$celltext . '</td>';
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2008-07-28 17:11:51 +00:00
|
|
|
print $line;
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 11:24:44 +01:00
|
|
|
if ($csv) {
|
2008-07-28 12:31:29 +00:00
|
|
|
exit;
|
|
|
|
}
|
2013-04-10 11:50:56 +08:00
|
|
|
print '</tbody></table>';
|
2012-03-12 10:37:35 +00:00
|
|
|
print '</div>';
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2021-04-02 12:06:18 +07:00
|
|
|
echo $output->render_download_buttons($url);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2009-08-06 14:10:33 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-04 08:11:02 +00:00
|
|
|
|