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', new pix_icon('i/report', ''))
130 ->set_show_in_secondary_navigation(false);
135 * Return a list of page types
137 * @param string $pagetype current page type
138 * @param stdClass $parentcontext Block's parent context
139 * @param stdClass $currentcontext Current context of block
140 * @return array a list of page types
142 function report_log_page_type_list($pagetype, $parentcontext, $currentcontext) {
144 '*' => get_string('page-x', 'pagetype'),
145 'report-*' => get_string('page-report-x', 'pagetype'),
146 'report-log-*' => get_string('page-report-log-x', 'report_log'),
147 'report-log-index' => get_string('page-report-log-index', 'report_log'),
148 'report-log-user' => get_string('page-report-log-user', 'report_log')
154 * Add nodes to myprofile page.
156 * @param \core_user\output\myprofile\tree $tree Tree object
157 * @param stdClass $user user object
158 * @param bool $iscurrentuser
159 * @param stdClass $course Course object
163 function report_log_myprofile_navigation(core_user\output\myprofile\tree
$tree, $user, $iscurrentuser, $course) {
164 if (empty($course)) {
165 // We want to display these reports under the site context.
166 $course = get_fast_modinfo(SITEID
)->get_course();
168 list($all, $today) = report_log_can_access_user_report($user, $course);
171 $url = new moodle_url('/report/log/user.php',
172 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'today'));
173 $node = new core_user\output\myprofile\node
('reports', 'todayslogs', get_string('todaylogs'), null, $url);
174 $tree->add_node($node);
179 $url = new moodle_url('/report/log/user.php',
180 array('id' => $user->id
, 'course' => $course->id
, 'mode' => 'all'));
181 $node = new core_user\output\myprofile\node
('reports', 'alllogs', get_string('alllogs'), null, $url);
182 $tree->add_node($node);