-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.php
204 lines (177 loc) · 6.49 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains functions used by the trainingsessions report
*
* @package report_trainingsessions
* @category report
* @copyright 2012 Valery Fremaux ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* This function extends the 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_trainingsessions_extend_navigation_course($navigation, $course, $context) {
if (has_capability('report/trainingsessions:view', $context)) {
$url = new moodle_url('/report/trainingsessions/index.php', array('id' => $course->id));
$label = get_string('pluginname', 'report_trainingsessions');
$navigation->add($label, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
}
function report_trainingsessions_page_type_list($pagetype, $parentcontext, $currentcontext) {
$array = array(
'*' => get_string('page-x', 'pagetype'),
'report-*' => get_string('page-report-x', 'pagetype'),
'report-trainingsessions-*' => get_string('page-report-trainingsessions-x', 'report_trainingsessions'),
'report-trainingsessions-index' => get_string('page-report-trainingsessions-index', 'report_trainingsessions'),
);
return $array;
}
/**
* 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_trainingsessions_can_access_user_report($user, $course) {
global $USER;
$coursecontext = context_course::instance($course->id);
if (has_capability('report/trainingsessions:view', $coursecontext)) {
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;
}
/**
* Called by the storage subsystem to give back a raw report
*
*/
function report_trainingsessions_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $USER;
if ($USER->id) {
require_capability('report/trainingsessions:downloadreports', $context);
}
if (!in_array($filearea, array('rawreports', 'reports'))) {
send_file_not_found();
}
$fs = get_file_storage();
$itemid = array_shift($args);
$filename = array_pop($args);
$filepath = $args ? '/'.implode('/', $args).'/' : '/';
if ((!$file = $fs->get_file($context->id, 'report_trainingsessions', $filearea, $itemid, $filepath, $filename)) ||
$file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 60 * 60, 0, true);
}
/**
* Tells wether a feature is supported or not. Gives back the
* implementation path where to fetch resources.
* @param string $feature a feature key to be tested.
*/
function report_trainingsessions_supports_feature($feature = null, $getsupported = false) {
global $CFG;
static $supports;
if (!during_initial_install()) {
$config = get_config('report_trainingsessions');
}
if (!isset($supports)) {
$supports = array(
'pro' => array(
'format' => array('xls', 'csv', 'pdf', 'json'),
'replay' => array('single', 'replay', 'shift', 'shiftto'),
'calculation' => array('coupling', 'specialgrades', 'multicourse'),
'xls' => array('calculated'),
'export' => array('ws')
),
'community' => array(
'format' => array('xls', 'csv'),
'replay' => array('single', 'replay'),
),
);
$prefer = array('format' => array(
'xls' => 'community',
'csv' => 'community'
));
}
if ($getsupported) {
return $supports;
}
// Check existance of the 'pro' dir in plugin.
if (is_dir(__DIR__.'/pro')) {
if ($feature == 'emulate/community') {
return 'pro';
}
if (empty($config->emulatecommunity)) {
$versionkey = 'pro';
} else {
$versionkey = 'community';
}
} else {
$versionkey = 'community';
}
if (empty($feature)) {
// Just return version.
return $versionkey;
}
list($feat, $subfeat) = explode('/', $feature);
if (!array_key_exists($feat, $supports[$versionkey])) {
return false;
}
if (!in_array($subfeat, $supports[$versionkey][$feat])) {
return false;
}
// Special condition for pdf dependencies.
if (($feature == 'format/pdf') && !is_dir($CFG->dirroot.'/local/vflibs')) {
return false;
}
if (array_key_exists($feat, $supports['community'])) {
if (in_array($subfeat, $supports['community'][$feat])) {
// If community exists, default path points community code.
if (isset($prefer[$feat][$subfeat])) {
// Configuration tells which location to prefer if explicit.
$versionkey = $prefer[$feat][$subfeat];
} else {
$versionkey = 'community';
}
}
}
return $versionkey;
}
/**
* Callback to verify if the given instance of store is supported by this report or not.
*
* @param string $instance store instance.
*
* @return bool returns true if the store is supported by the report, false otherwise.
*/
function report_trainingsessions_supports_feature_logstore($instance) {
if ($instance instanceof \core\log\sql_internal_reader || $instance instanceof \logstore_legacy\log\store) {
return true;
}
return false;
}