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 functions used by the log reports
20 * This file is also required by /admin/reports/stats/index.php.
24 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die;
31 * This function extends the navigation with the report items
33 * @param navigation_node $navigation The navigation node to extend
34 * @param stdClass $course The course to object for the report
35 * @param stdClass $context The context of the course
37 function report_stats_extend_navigation_course($navigation, $course, $context) {
39 if (empty($CFG->enablestats
)) {
42 if (has_capability('report/stats:view', $context)) {
43 $url = new moodle_url('/report/stats/index.php', array('course'=>$course->id
));
44 $navigation->add(get_string('pluginname', 'report_stats'), $url, navigation_node
::TYPE_SETTING
, null, null, new pix_icon('i/report', ''));
49 * This function extends the course navigation with the report items
51 * @param navigation_node $navigation The navigation node to extend
52 * @param stdClass $user
53 * @param stdClass $course The course to object for the report
55 function report_stats_extend_navigation_user($navigation, $user, $course) {
57 if (empty($CFG->enablestats
)) {
60 if (report_stats_can_access_user_report($user, $course)) {
61 $url = new moodle_url('/report/stats/user.php', array('id'=>$user->id
, 'course'=>$course->id
));
62 $navigation->add(get_string('stats'), $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_stats_can_access_user_report($user, $course) {
78 $coursecontext = context_course
::instance($course->id
);
79 $personalcontext = context_user
::instance($user->id
);
81 if (has_capability('report/stats:view', $coursecontext)) {
85 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
86 if ($course->showreports
and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
90 } else if ($user->id
== $USER->id
) {
91 if ($course->showreports
and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
100 * Return a list of page types
101 * @param string $pagetype current page type
102 * @param stdClass $parentcontext Block's parent context
103 * @param stdClass $currentcontext Current context of block
106 function report_stats_page_type_list($pagetype, $parentcontext, $currentcontext) {
108 '*' => get_string('page-x', 'pagetype'),
109 'report-*' => get_string('page-report-x', 'pagetype'),
110 'report-stats-*' => get_string('page-report-stats-x', 'report_stats'),
111 'report-stats-index' => get_string('page-report-stats-index', 'report_stats'),
112 'report-stats-user' => get_string('page-report-stats-user', 'report_stats')
118 * Callback to verify if the given instance of store is supported by this report or not.
120 * @param string $instance store instance.
122 * @return bool returns true if the store is supported by the report, false otherwise.
124 function report_stats_supports_logstore($instance) {
125 if ($instance instanceof \core\log\sql_internal_reader ||
$instance instanceof \logstore_legacy\log\store
) {