Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
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.
8
//
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.
13
//
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/>.
16
 
17
/**
18
 * Public API of the log report.
19
 *
20
 * Defines the APIs used by log reports
21
 *
22
 * @package    report_log
23
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
1441 ariadna 27
use core\report_helper;
28
 
1 efrain 29
defined('MOODLE_INTERNAL') || die;
30
 
31
/**
32
 * This function extends the navigation with the report items
33
 *
34
 * @param navigation_node $navigation The navigation node to extend
35
 * @param stdClass $course The course to object for the report
36
 * @param stdClass $context The context of the course
37
 */
38
function report_log_extend_navigation_course($navigation, $course, $context) {
1441 ariadna 39
    if (
40
        has_capability('report/log:view', $context)
41
        && report_helper::has_valid_group($context)
42
    ) {
1 efrain 43
        $url = new moodle_url('/report/log/index.php', array('id'=>$course->id));
44
        $navigation->add(get_string('pluginname', 'report_log'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
45
    }
46
}
47
 
48
/**
49
 * Callback to verify if the given instance of store is supported by this report or not.
50
 *
51
 * @param string $instance store instance.
52
 *
53
 * @return bool returns true if the store is supported by the report, false otherwise.
54
 */
55
function report_log_supports_logstore($instance) {
56
    if ($instance instanceof \core\log\sql_reader) {
57
        return true;
58
    }
59
    return false;
60
}
61
 
62
/**
63
 * This function extends the course navigation with the report items
64
 *
65
 * @param navigation_node $navigation The navigation node to extend
66
 * @param stdClass $user
67
 * @param stdClass $course The course to object for the report
68
 */
69
function report_log_extend_navigation_user($navigation, $user, $course) {
70
    list($all, $today) = report_log_can_access_user_report($user, $course);
71
 
72
    if ($today) {
73
        $url = new moodle_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'today'));
74
        $navigation->add(get_string('todaylogs'), $url);
75
    }
76
    if ($all) {
77
        $url = new moodle_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'all'));
78
        $navigation->add(get_string('alllogs'), $url);
79
    }
80
}
81
 
82
/**
83
 * Is current user allowed to access this report
84
 *
85
 * @access private defined in lib.php for performance reasons
86
 * @global stdClass $USER
87
 * @param stdClass $user
88
 * @param stdClass $course
89
 * @return array with two elements $all, $today
90
 */
91
function report_log_can_access_user_report($user, $course) {
92
    global $USER;
93
 
94
    $coursecontext = context_course::instance($course->id);
95
    $personalcontext = context_user::instance($user->id);
96
 
97
    if ($user->id == $USER->id) {
98
        if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
99
            return array(true, true);
100
        }
101
    } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
102
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
103
            return array(true, true);
104
        }
105
    }
106
 
107
    // Check if $USER shares group with $user (in case separated groups are enabled and 'moodle/site:accessallgroups' is disabled).
108
    if (!groups_user_groups_visible($course, $user->id)) {
109
        return array(false, false);
110
    }
111
 
112
    $today = false;
113
    $all = false;
114
 
115
    if (has_capability('report/log:viewtoday', $coursecontext)) {
116
        $today = true;
117
    }
118
    if (has_capability('report/log:view', $coursecontext)) {
119
        $all = true;
120
    }
121
 
122
    return array($all, $today);
123
}
124
 
125
/**
126
 * This function extends the module navigation with the report items
127
 *
128
 * @param navigation_node $navigation The navigation node to extend
129
 * @param stdClass $cm
130
 */
131
function report_log_extend_navigation_module($navigation, $cm) {
1441 ariadna 132
    if (
133
        has_capability('report/log:view', context_course::instance($cm->course))
134
        && report_helper::has_valid_group(context_module::instance($cm->id))
135
    ) {
136
        $url = new moodle_url('/report/log/index.php', [
137
            'chooselog' => '1',
138
            'id' => $cm->course,
139
            'modid' => $cm->id,
140
            'isactivitypage' => '1',
141
        ]);
1 efrain 142
        $navigation->add(get_string('logs'), $url, navigation_node::TYPE_SETTING, null, 'logreport', new pix_icon('i/report', ''));
143
    }
144
}
145
 
146
/**
147
 * Return a list of page types
148
 *
149
 * @param string $pagetype current page type
150
 * @param stdClass $parentcontext Block's parent context
151
 * @param stdClass $currentcontext Current context of block
152
 * @return array a list of page types
153
 */
154
function report_log_page_type_list($pagetype, $parentcontext, $currentcontext) {
155
    $array = array(
156
        '*'                => get_string('page-x', 'pagetype'),
157
        'report-*'         => get_string('page-report-x', 'pagetype'),
158
        'report-log-*'     => get_string('page-report-log-x',  'report_log'),
159
        'report-log-index' => get_string('page-report-log-index',  'report_log'),
160
        'report-log-user'  => get_string('page-report-log-user',  'report_log')
161
    );
162
    return $array;
163
}
164
 
165
/**
166
 * Add nodes to myprofile page.
167
 *
168
 * @param \core_user\output\myprofile\tree $tree Tree object
169
 * @param stdClass $user user object
170
 * @param bool $iscurrentuser
171
 * @param stdClass $course Course object
172
 *
173
 * @return bool
174
 */
175
function report_log_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
176
    if (empty($course)) {
177
        // We want to display these reports under the site context.
178
        $course = get_fast_modinfo(SITEID)->get_course();
179
    }
180
    list($all, $today) = report_log_can_access_user_report($user, $course);
181
    if ($today) {
182
        // Today's log.
183
        $url = new moodle_url('/report/log/user.php',
184
            array('id' => $user->id, 'course' => $course->id, 'mode' => 'today'));
185
        $node = new core_user\output\myprofile\node('reports', 'todayslogs', get_string('todaylogs'), null, $url);
186
        $tree->add_node($node);
187
    }
188
 
189
    if ($all) {
190
        // All logs.
191
        $url = new moodle_url('/report/log/user.php',
192
            array('id' => $user->id, 'course' => $course->id, 'mode' => 'all'));
193
        $node = new core_user\output\myprofile\node('reports', 'alllogs', get_string('alllogs'), null, $url);
194
        $tree->add_node($node);
195
    }
196
    return true;
197
}