. /** * Display user completion report * * @package report * @subpackage completion * @copyright 2009 Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require('../../config.php'); require_once($CFG->dirroot.'/report/completion/lib.php'); require_once($CFG->libdir.'/completionlib.php'); $userid = required_param('id', PARAM_INT); $courseid = required_param('course', PARAM_INT); $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); $coursecontext = context_course::instance($course->id); $personalcontext = context_user::instance($user->id); if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) { //TODO: do not require parents to be enrolled in courses - this is a hack! require_login(); $PAGE->set_course($course); } else { require_login($course); } if (!report_completion_can_access_user_report($user, $course, true)) { // this should never happen error('Can not access user completion report'); } add_to_log($course->id, 'course', 'report completion', "report/completion/user.php?id=$user->id&course=$course->id", $course->id); $stractivityreport = get_string('activityreport'); $PAGE->set_pagelayout('admin'); $PAGE->set_url('/report/completion/user.php', array('id'=>$user->id, 'course'=>$course->id)); $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. $PAGE->set_title("$course->shortname: $stractivityreport"); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); // Display course completion user report // Grab all courses the user is enrolled in and their completion status $sql = " SELECT DISTINCT c.id AS id FROM {course} c INNER JOIN {context} con ON con.instanceid = c.id INNER JOIN {role_assignments} ra ON ra.contextid = con.id INNER JOIN {enrol} e ON c.id = e.courseid INNER JOIN {user_enrolments} ue ON e.id = ue.enrolid AND ra.userid = ue.userid AND ra.userid = {$user->id} "; // Get roles that are tracked by course completion if ($roles = $CFG->gradebookroles) { $sql .= ' AND ra.roleid IN ('.$roles.') '; } $sql .= ' WHERE con.contextlevel = '.CONTEXT_COURSE.' AND c.enablecompletion = 1 '; // If we are looking at a specific course if ($course->id != 1) { $sql .= ' AND c.id = '.(int)$course->id.' '; } // Check if result is empty $rs = $DB->get_recordset_sql($sql); if (!$rs->valid()) { if ($course->id != 1) { $error = get_string('nocompletions', 'report_completion'); // TODO: missing string } else { $error = get_string('nocompletioncoursesenroled', 'report_completion'); // TODO: missing string } echo $OUTPUT->notification($error); $rs->close(); // not going to loop (but break), close rs echo $OUTPUT->footer(); die(); } // Categorize courses by their status $courses = array( 'inprogress' => array(), 'complete' => array(), 'unstarted' => array() ); // Sort courses by the user's status in each foreach ($rs as $course_completion) { $c_info = new completion_info((object)$course_completion); // Is course complete? $coursecomplete = $c_info->is_course_complete($user->id); // Has this user completed any criteria? $criteriacomplete = $c_info->count_course_user_data($user->id); if ($coursecomplete) { $courses['complete'][] = $c_info; } else if ($criteriacomplete) { $courses['inprogress'][] = $c_info; } else { $courses['unstarted'][] = $c_info; } } $rs->close(); // after loop, close rs // Loop through course status groups foreach ($courses as $type => $infos) { // If there are courses with this status if (!empty($infos)) { echo '
'.get_string('course').' | '; echo ''.get_string('requiredcriteria', 'completion').' | '; echo ''.get_string('status').' | '; echo ''.get_string('info').' | '; if ($type === 'complete') { echo ''.get_string('completiondate', 'report_completion').' | '; } echo '
---|---|---|---|---|
'.$course_name.' | '; } else { echo '||||
'; } echo ' | '; echo $row['title']; echo ' | '; switch ($row['status']) { case 'Yes': echo get_string('complete'); break; case 'No': echo get_string('incomplete', 'report_completion'); break; default: echo $row['status']; } // Display link on first row echo ' | '; if ($first_row) { echo ''.get_string('detailedview', 'report_completion').''; } echo ' | '; // Display completion date for completed courses on first row if ($type === 'complete' && $first_row) { $params = array( 'userid' => $user->id, 'course' => $c_course->id ); $ccompletion = new completion_completion($params); echo ''.userdate($ccompletion->timecompleted, '%e %B %G').' | '; } $first_row = false; echo '