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 * Public API of the log report.
20 * Defines the APIs used by log reports
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die;
30 * This function extends the navigation with the report items
32 * @param navigation_node $navigation The navigation node to extend
33 * @param stdClass $course The course to object for the report
34 * @param stdClass $context The context of the course
36 function report_log_extend_navigation_course($navigation, $course, $context) {
37 if (has_capability('report/log:view', $context)) {
38 $url = new moodle_url('/report/log/index.php', array('id'=>$course->id
));
39 $navigation->add(get_string('pluginname', 'report_log'), $url, navigation_node
::TYPE_SETTING
, null, null, new pix_icon('i/report', ''));
44 * Callback to verify if the given instance of store is supported by this report or not.
46 * @param string $instance store instance.
48 * @return bool returns true if the store is supported by the report, false otherwise.
50 function report_log_supports_logstore($instance) {
51 if ($instance instanceof \core\log\sql_reader
) {
58 * This function extends the course navigation with the report items
60 * @param navigation_node $navigation The navigation node to extend
61 * @param stdClass $user
62 * @param stdClass $course The course to object for the report
64 function report_log_extend_navigation_user($navigation, $user, $course) {
65 list($all, $today) = report_log_can_access_user_report($user, $course);
68 $url = new moodle_url('/report/log/user.php', array('id'=>$user->id
, 'course'=>$course->id
, 'mode'=>'today'));
69 $navigation->add(get_string('todaylogs'), $url);
72 $url = new moodle_url('/report/log/user.php', array('id'=>$user->id
, 'course'=>$course->id
, 'mode'=>'all'));
73 $navigation->add(get_string('alllogs'), $url);
78 * Is current user allowed to access this report
80 * @access private defined in lib.php for performance reasons
81 * @global stdClass $USER
82 * @param stdClass $user
83 * @param stdClass $course
84 * @return array with two elements $all, $today
86 function report_log_can_access_user_report($user, $course) {
89 $coursecontext = context_course
::instance($course->id
);
90 $personalcontext = context_user
::instance($user->id
);
92 if ($user->id
== $USER->id
) {
93 if ($course->showreports
and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
94 return array(true, true);
96 } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
97 if ($course->showreports
and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
98 return array(true, true);
102 // Check if $USER shares group with $user (in case separated groups are enabled and 'moodle/site:accessallgroups' is disabled).
103 if (!groups_user_groups_visible($course, $user->id
)) {
104 return array(false, false);
110 if (has_capability('report/log:viewtoday', $coursecontext)) {
113 if (has_capability('report/log:view', $coursecontext)) {
117 return array($all, $today);
121 * This function extends the module navigation with the report items
123 * @param navigation_node $navigation The navigation node to extend
124 * @param stdClass $cm
126 function report_log_extend_navigation_module($navigation, $cm) {
127 if (has_capability('report/log:view', context_course
::instance($cm->course
))) {
128 $url = new moodle_url('/report/log/index.php', array('chooselog'=>'1','id'=>$cm->course
,'modid'=>$cm->id
));
129 $navigation->add(get_string('logs'), $url, navigation_node
::TYPE_SETTING
, null, 'logreport');
134 * Return a list of page types
136 * @param string $pagetype current page type
137 * @param stdClass $parentcontext Block's parent context
138 * @param stdClass $currentcontext Current context of block
139 * @return array a list of page types
141 function report_log_page_type_list($pagetype, $parentcontext, $currentcontext) {
143 '*' => get_string('page-x', 'pagetype'),
144 'report-*' => get_string('page-report-x', 'pagetype'),
145 'report-log-*' => get_string('page-report-log-x', 'report_log'),
146 'report-log-index' => get_string('page-report-log-index', 'report_log'),
147 'report-log-user' => get_string('page-report-log-user', 'report_log')
153 * Add nodes to myprofile page.
155 * @param \core_user\output\myprofile\tree $tree Tree object
156 * @param stdClass $user user object
157 * @param bool $iscurrentuser
158 * @param stdClass $course Course object
162 function report_log_myprofile_navigation(core_user\output\myprofile\tree
$tree, $user, $iscurrentuser, $course) {
163 if (empty($course)) {
164 // We want to display these reports under the site context.
165 $course = get_fast_modinfo(SITEID
)->get_course();
167 list($all, $today) = report_log_can_access_user_report($user, $course);
170 $url = new moodle_url('/report/log/user.php',
171 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'today'));
172 $node = new core_user\output\myprofile\node
('reports', 'todayslogs', get_string('todaylogs'), null, $url);
173 $tree->add_node($node);
178 $url = new moodle_url('/report/log/user.php',
179 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'all'));
180 $node = new core_user\output\myprofile\node
('reports', 'alllogs', get_string('alllogs'), null, $url);
181 $tree->add_node($node);