Merge branch 'MDL-62962-master' of git://github.com/junpataleta/moodle
[moodle.git] / report / outline / lib.php
blob7e4cd42df3e1ea2a57b0ad6e4c5744f9041a4101
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * This file contains public API of outline report
20 * @package report
21 * @subpackage outline
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die;
28 /**
29 * This function extends the course 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_outline_extend_navigation_course($navigation, $course, $context) {
36 if (has_capability('report/outline:view', $context)) {
37 $url = new moodle_url('/report/outline/index.php', array('id'=>$course->id));
38 $navigation->add(get_string('pluginname', 'report_outline'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
42 /**
43 * This function extends the course navigation with the report items
45 * @param navigation_node $navigation The navigation node to extend
46 * @param stdClass $user
47 * @param stdClass $course The course to object for the report
49 function report_outline_extend_navigation_user($navigation, $user, $course) {
50 if (report_outline_can_access_user_report($user, $course)) {
51 $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'outline'));
52 $navigation->add(get_string('outlinereport'), $url);
53 $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'complete'));
54 $navigation->add(get_string('completereport'), $url);
58 /**
59 * Is current user allowed to access this report
61 * @private defined in lib.php for performance reasons
63 * @param stdClass $user
64 * @param stdClass $course
65 * @return bool
67 function report_outline_can_access_user_report($user, $course) {
68 global $USER;
70 $coursecontext = context_course::instance($course->id);
71 $personalcontext = context_user::instance($user->id);
73 if ($user->id == $USER->id) {
74 if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
75 return true;
77 } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
78 if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
79 return true;
84 // Check if $USER shares group with $user (in case separated groups are enabled and 'moodle/site:accessallgroups' is disabled).
85 if (!groups_user_groups_visible($course, $user->id)) {
86 return false;
89 if (has_capability('report/outline:viewuserreport', $coursecontext)) {
90 return true;
93 return false;
96 /**
97 * Return a list of page types
98 * @param string $pagetype current page type
99 * @param stdClass $parentcontext Block's parent context
100 * @param stdClass $currentcontext Current context of block
101 * @return array
103 function report_outline_page_type_list($pagetype, $parentcontext, $currentcontext) {
104 $array = array(
105 '*' => get_string('page-x', 'pagetype'),
106 'report-*' => get_string('page-report-x', 'pagetype'),
107 'report-outline-*' => get_string('page-report-outline-x', 'report_outline'),
108 'report-outline-index' => get_string('page-report-outline-index', 'report_outline'),
109 'report-outline-user' => get_string('page-report-outline-user', 'report_outline')
111 return $array;
115 * Callback to verify if the given instance of store is supported by this report or not.
117 * @param string $instance store instance.
119 * @return bool returns true if the store is supported by the report, false otherwise.
121 function report_outline_supports_logstore($instance) {
122 if ($instance instanceof \core\log\sql_internal_table_reader || $instance instanceof \logstore_legacy\log\store) {
123 return true;
125 return false;
129 * Add nodes to myprofile page.
131 * @param \core_user\output\myprofile\tree $tree Tree object
132 * @param stdClass $user user object
133 * @param bool $iscurrentuser
134 * @param stdClass $course Course object
136 * @return bool
138 function report_outline_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
139 if (empty($course)) {
140 // We want to display these reports under the site context.
141 $course = get_fast_modinfo(SITEID)->get_course();
143 if (report_outline_can_access_user_report($user, $course)) {
144 $url = new moodle_url('/report/outline/user.php',
145 array('id' => $user->id, 'course' => $course->id, 'mode' => 'outline'));
146 $node = new core_user\output\myprofile\node('reports', 'outline', get_string('outlinereport'), null, $url);
147 $tree->add_node($node);
148 $url = new moodle_url('/report/outline/user.php',
149 array('id' => $user->id, 'course' => $course->id, 'mode' => 'complete'));
150 $node = new core_user\output\myprofile\node('reports', 'complete', get_string('completereport'), null, $url);
151 $tree->add_node($node);