-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
109 lines (97 loc) · 3.84 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* This file contains public API of session report
*
* @package report
* @subpackage session
* @author Domenico Pontari <[email protected]>
* @copyright Institute of Tropical Medicine - Antwerp
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* This function extends the course navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function report_session_extend_navigation_course($navigation, $course, $context) {
if (has_capability('report/session:view', $context)) {
$url = new moodle_url('/report/session/index.php', array('id'=>$course->id));
$navigation->add(get_string('pluginname', 'report_session'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
}
/**
* This function extends the course navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $user
* @param stdClass $course The course to object for the report
*/
function report_session_extend_navigation_user($navigation, $user, $course) {
if (report_session_can_access_user_report($user, $course)) {
$url = new moodle_url('/report/session/user.php', array('userid'=>$user->id, 'id'=>$course->id));
$navigation->add(get_string('pluginname', 'report_session'), $url);
}
}
/**
* Is current user allowed to access this report
*
* @private defined in lib.php for performance reasons
*
* @param stdClass $user
* @param stdClass $course
* @return bool
*/
function report_session_can_access_user_report($user, $course) {
global $USER;
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);
if (has_capability('report/session:view', $coursecontext)) {
return true;
}
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
return true;
}
} else if ($user->id == $USER->id) {
if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
return true;
}
}
return false;
}
/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
* @return array
*//*
function report_session_page_type_list($pagetype, $parentcontext, $currentcontext) {
$array = array(
'*' => get_string('page-x', 'pagetype'),
'report-*' => get_string('page-report-x', 'pagetype'),
'report-session-*' => get_string('page-report-session-x', 'report_session'),
'report-session-index' => get_string('page-report-session-index', 'report_session'),
'report-session-user' => get_string('page-report-session-user', 'report_session'),
'report-session-cm' => get_string('page-report-session-cm', 'report_session')
);
return $array;
}
*/
function report_session_cron ($verbose = false) {
require_once ('locallib.php');
$result = false;
$page_num = 0;
$users = get_users(true, '', true, null, 'id', '', '', $page_num, 100, 'id, username');
while (!$result && !empty($users)) {
foreach ($users as $user) {
if ($user->username == 'guest') continue;
$result = report_session_update_user_sessions ($user->id, $verbose);
if ($result) break;
}
$users = get_users(true, '', true, null, 'id', '', '', ++$page_num, 100, 'id, username');
}
}