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 * This function extends the course navigation with the report items
46 * @param navigation_node $navigation The navigation node to extend
47 * @param stdClass $user
48 * @param stdClass $course The course to object for the report
50 function report_log_extend_navigation_user($navigation, $user, $course) {
51 list($all, $today) = report_log_can_access_user_report($user, $course);
54 $url = new moodle_url('/report/log/user.php', array('id'=>$user->id
, 'course'=>$course->id
, 'mode'=>'today'));
55 $navigation->add(get_string('todaylogs'), $url);
58 $url = new moodle_url('/report/log/user.php', array('id'=>$user->id
, 'course'=>$course->id
, 'mode'=>'all'));
59 $navigation->add(get_string('alllogs'), $url);
64 * Is current user allowed to access this report
66 * @access private defined in lib.php for performance reasons
67 * @global stdClass $USER
68 * @param stdClass $user
69 * @param stdClass $course
70 * @return array with two elements $all, $today
72 function report_log_can_access_user_report($user, $course) {
75 $coursecontext = context_course
::instance($course->id
);
76 $personalcontext = context_user
::instance($user->id
);
81 if (has_capability('report/log:view', $coursecontext)) {
84 if (has_capability('report/log:viewtoday', $coursecontext)) {
88 if ($today and $all) {
89 return array(true, true);
92 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
93 if ($course->showreports
and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
94 return array(true, true);
97 } else if ($user->id
== $USER->id
) {
98 if ($course->showreports
and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
99 return array(true, true);
103 return array($all, $today);
107 * This function extends the module navigation with the report items
109 * @param navigation_node $navigation The navigation node to extend
110 * @param stdClass $cm
112 function report_log_extend_navigation_module($navigation, $cm) {
113 if (has_capability('report/log:view', context_course
::instance($cm->course
))) {
114 $url = new moodle_url('/report/log/index.php', array('chooselog'=>'1','id'=>$cm->course
,'modid'=>$cm->id
));
115 $navigation->add(get_string('logs'), $url, navigation_node
::TYPE_SETTING
, null, 'logreport');
120 * Return a list of page types
122 * @param string $pagetype current page type
123 * @param stdClass $parentcontext Block's parent context
124 * @param stdClass $currentcontext Current context of block
125 * @return array a list of page types
127 function report_log_page_type_list($pagetype, $parentcontext, $currentcontext) {
129 '*' => get_string('page-x', 'pagetype'),
130 'report-*' => get_string('page-report-x', 'pagetype'),
131 'report-log-*' => get_string('page-report-log-x', 'report_log'),
132 'report-log-index' => get_string('page-report-log-index', 'report_log'),
133 'report-log-user' => get_string('page-report-log-user', 'report_log')