. /** * Block for displayed logged in user's course completion status * * @package block * @subpackage completion * @copyright 2009-2012 Catalyst IT Ltd * @author Aaron Barnes * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once(dirname(__FILE__).'/../../config.php'); require_once("{$CFG->libdir}/completionlib.php"); /// /// Load data /// $id = required_param('course', PARAM_INT); $userid = optional_param('user', 0, PARAM_INT); // Load course $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); // Load user if ($userid) { $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); } else { $user = $USER; } // Check permissions require_login($course); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $personalcontext = get_context_instance(CONTEXT_USER, $user->id); $can_view = false; // Can view own report if ($USER->id == $user->id) { $can_view = true; } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) { $can_view = true; } else if (has_capability('report/completion:view', $coursecontext)) { $can_view = true; } else if (has_capability('report/completion:view', $personalcontext)) { $can_view = true; } if (!$can_view) { print_error('cannotviewreport'); } // Load completion data $info = new completion_info($course); $returnurl = new moodle_url('/course/view.php', array('id' => $id)); // Don't display if completion isn't enabled! if (!$info->is_enabled()) { print_error('completionnotenabled', 'completion', $returnurl); } // Check this user is enroled if (!$info->is_tracked_user($user->id)) { if ($USER->id == $user->id) { print_error('notenroled', 'completion', $returnurl); } else { print_error('usernotenroled', 'completion', $returnurl); } } /// /// Display page /// $PAGE->set_context(context_course::instance($course->id)); // Print header $page = get_string('completionprogressdetails', 'block_completionstatus'); $title = format_string($course->fullname) . ': ' . $page; $PAGE->navbar->add($page); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id)); $PAGE->set_title(get_string('course') . ': ' . $course->fullname); $PAGE->set_heading($title); echo $OUTPUT->header(); // Display completion status echo ''; // If not display logged in user, show user name if ($USER->id != $user->id) { echo ''; } echo ''; // Load criteria to display $completions = $info->get_completions($user->id); // Check if this course has any criteria if (empty($completions)) { echo '
'.get_string('showinguser', 'completion').': '; echo ''.fullname($user).''; echo '
'.get_string('status').': '; // Is course complete? $coursecomplete = $info->is_course_complete($user->id); // Has this user completed any criteria? $criteriacomplete = $info->count_course_user_data($user->id); // Load course completion $params = array( 'userid' => $user->id, 'course' => $course->id, ); $ccompletion = new completion_completion($params); if ($coursecomplete) { echo get_string('complete'); } else if (!$criteriacomplete && !$ccompletion->timestarted) { echo ''.get_string('notyetstarted', 'completion').''; } else { echo ''.get_string('inprogress','completion').''; } echo '

'; echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox'); echo '
'; } else { echo ''.get_string('required').': '; // Get overall aggregation method $overall = $info->get_aggregation_method(); if ($overall == COMPLETION_AGGREGATION_ALL) { echo get_string('criteriarequiredall', 'completion'); } else { echo get_string('criteriarequiredany', 'completion'); } echo ''; // Generate markup for criteria statuses echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; // Save row data $rows = array(); // Loop through course criteria foreach ($completions as $completion) { $criteria = $completion->get_criteria(); $row = array(); $row['type'] = $criteria->criteriatype; $row['title'] = $criteria->get_title(); $row['status'] = $completion->get_status(); $row['complete'] = $completion->is_complete(); $row['timecompleted'] = $completion->timecompleted; $row['details'] = $criteria->get_details($completion); $rows[] = $row; } // Print table $last_type = ''; $agg_type = false; $oddeven = 0; foreach ($rows as $row) { echo ''; // Criteria group echo ''; // Criteria title echo ''; // Requirement echo ''; // Status echo ''; // Is complete echo ''; // Completion data echo ''; echo ''; // for row striping $oddeven = $oddeven ? 0 : 1; } echo '
'.get_string('criteriagroup', 'block_completionstatus').''.get_string('criteria', 'completion').''.get_string('requirement', 'block_completionstatus').''.get_string('status').''.get_string('complete').''.get_string('completiondate', 'report_completion').'
'; if ($last_type !== $row['details']['type']) { $last_type = $row['details']['type']; echo $last_type; // Reset agg type $agg_type = true; } else { // Display aggregation type if ($agg_type) { $agg = $info->get_aggregation_method($row['type']); echo '('; if ($agg == COMPLETION_AGGREGATION_ALL) { echo strtolower(get_string('aggregateall', 'completion')); } else { echo strtolower(get_string('aggregateany', 'completion')); } echo ' '.strtolower(get_string('required')).')'; $agg_type = false; } } echo ''; echo $row['details']['criteria']; echo ''; echo $row['details']['requirement']; echo ''; echo $row['details']['status']; echo ''; echo $row['complete'] ? get_string('yes') : get_string('no'); echo ''; if ($row['timecompleted']) { echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig')); } else { echo '-'; } echo '
'; } echo '
'; $courseurl = new moodle_url("/course/view.php", array('id' => $course->id)); echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get'); echo '
'; echo $OUTPUT->footer();