/** * This function extends the navigation with the report items * * @param navigation_node $navigation The navigation node to extend * @param stdClass $course The course to object for the report * @param stdClass $context The context of the course */ function completion_report_extend_navigation($navigation, $course, $context) { global $CFG, $OUTPUT; if (has_capability('coursereport/completion:view', $context)) { $completion = new completion_info($course); if ($completion->is_enabled() && $completion->has_criteria()) { $url = new moodle_url('/course/report/completion/index.php', array('course' => $course->id)); $navigation->add(get_string('pluginname', 'coursereport_completion'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); } } }
// Check permissions require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('coursereport/completion:view', $context); // Get group mode $group = groups_get_course_group($course, true); // Supposed to verify group if ($group === 0 && $course->groupmode == SEPARATEGROUPS) { require_capability('moodle/site:accessallgroups', $context); } /** * Load data */ // Get criteria for course $completion = new completion_info($course); if (!$completion->has_criteria()) { print_error('err_nocriteria', 'completion', $CFG->wwwroot . '/course/report.php?id=' . $course->id); } // Get criteria and put in correct order $criteria = array(); foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE) as $criterion) { $criteria[] = $criterion; } foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY) as $criterion) { $criteria[] = $criterion; } foreach ($completion->get_criteria() as $criterion) { if (!in_array($criterion->criteriatype, array(COMPLETION_CRITERIA_TYPE_COURSE, COMPLETION_CRITERIA_TYPE_ACTIVITY))) { $criteria[] = $criterion; } }
<?php if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); // It must be included from a Moodle page } require_once $CFG->libdir . '/completionlib.php'; if (has_capability('coursereport/completion:view', $context)) { $completion = new completion_info($course); if ($completion->is_enabled() && $completion->has_criteria()) { echo '<p>'; echo '<a href="' . $CFG->wwwroot . '/course/report/completion/index.php?coursetest=' . $course->id . '">' . get_string('coursecompletion') . '</a>'; echo '</p>'; } }