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/>.
18 * This file contains public API of outline report
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 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', ''));
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);
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
67 function report_outline_can_access_user_report($user, $course) {
70 $coursecontext = context_course
::instance($course->id
);
71 $personalcontext = context_user
::instance($user->id
);
73 if (has_capability('report/outline:view', $coursecontext)) {
77 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
78 if ($course->showreports
and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
82 } else if ($user->id
== $USER->id
) {
83 if ($course->showreports
and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
92 * Return a list of page types
93 * @param string $pagetype current page type
94 * @param stdClass $parentcontext Block's parent context
95 * @param stdClass $currentcontext Current context of block
98 function report_outline_page_type_list($pagetype, $parentcontext, $currentcontext) {
100 '*' => get_string('page-x', 'pagetype'),
101 'report-*' => get_string('page-report-x', 'pagetype'),
102 'report-outline-*' => get_string('page-report-outline-x', 'report_outline'),
103 'report-outline-index' => get_string('page-report-outline-index', 'report_outline'),
104 'report-outline-user' => get_string('page-report-outline-user', 'report_outline')
110 * Callback to verify if the given instance of store is supported by this report or not.
112 * @param string $instance store instance.
114 * @return bool returns true if the store is supported by the report, false otherwise.
116 function report_outline_supports_logstore($instance) {
117 if ($instance instanceof \core\log\sql_internal_table_reader ||
$instance instanceof \logstore_legacy\log\store
) {
124 * Add nodes to myprofile page.
126 * @param \core_user\output\myprofile\tree $tree Tree object
127 * @param stdClass $user user object
128 * @param bool $iscurrentuser
129 * @param stdClass $course Course object
133 function report_outline_myprofile_navigation(core_user\output\myprofile\tree
$tree, $user, $iscurrentuser, $course) {
134 if (!empty($course) && report_outline_can_access_user_report($user, $course)) {
135 $url = new moodle_url('/report/outline/user.php',
136 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'outline'));
137 $node = new core_user\output\myprofile\node
('reports', 'outline', get_string('outlinereport'), null, $url);
138 $tree->add_node($node);
139 $url = new moodle_url('/report/outline/user.php',
140 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'complete'));
141 $node = new core_user\output\myprofile\node
('reports', 'complete', get_string('completereport'), null, $url);
142 $tree->add_node($node);