2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
21 * @subpackage completion
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die;
29 * This function extends the navigation with the report items
31 * @param navigation_node $navigation The navigation node to extend
32 * @param stdClass $course The course to object for the report
33 * @param stdClass $context The context of the course
35 function report_completion_extend_navigation_course($navigation, $course, $context) {
38 require_once($CFG->libdir
.'/completionlib.php');
40 if (has_capability('report/completion:view', $context)) {
41 $completion = new completion_info($course);
42 if ($completion->is_enabled() && $completion->has_criteria()) {
43 $url = new moodle_url('/report/completion/index.php', array('course'=>$course->id
));
44 $navigation->add(get_string('pluginname','report_completion'), $url, navigation_node
::TYPE_SETTING
, null, null, new pix_icon('i/report', ''));
50 * This function extends the course navigation with the report items
52 * @param navigation_node $navigation The navigation node to extend
53 * @param stdClass $user
54 * @param stdClass $course The course to object for the report
56 function report_completion_extend_navigation_user($navigation, $user, $course) {
58 return; //TODO: this plugin was not linked from navigation in 2.0, let's keep it that way for now --skodak
60 if (report_completion_can_access_user_report($user, $course)) {
61 $url = new moodle_url('/report/completion/user.php', array('id'=>$user->id
, 'course'=>$course->id
));
62 $navigation->add(get_string('coursecompletion'), $url);
67 * Is current user allowed to access this report
69 * @private defined in lib.php for performance reasons
71 * @param stdClass $user
72 * @param stdClass $course
75 function report_completion_can_access_user_report($user, $course) {
78 if (empty($CFG->enablecompletion
)) {
82 if ($course->id
!= SITEID
and !$course->enablecompletion
) {
86 $coursecontext = context_course
::instance($course->id
);
87 $personalcontext = context_user
::instance($user->id
);
89 if ($user->id
== $USER->id
) {
90 if ($course->showreports
and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
93 } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
94 if ($course->showreports
and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
100 // Check if $USER shares group with $user (in case separated groups are enabled and 'moodle/site:accessallgroups' is disabled).
101 if (!groups_user_groups_visible($course, $user->id
)) {
105 if (has_capability('report/completion:view', $coursecontext)) {
113 * Return a list of page types
114 * @param string $pagetype current page type
115 * @param stdClass $parentcontext Block's parent context
116 * @param stdClass $currentcontext Current context of block
119 function report_completion_page_type_list($pagetype, $parentcontext, $currentcontext) {
121 '*' => get_string('page-x', 'pagetype'),
122 'report-*' => get_string('page-report-x', 'pagetype'),
123 'report-completion-*' => get_string('page-report-completion-x', 'report_completion'),
124 'report-completion-index' => get_string('page-report-completion-index', 'report_completion'),
125 'report-completion-user' => get_string('page-report-completion-user', 'report_completion')