-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathlib.php
135 lines (122 loc) · 3.8 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
<?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/>.
/**
* Block XP lib.
*
* @package block_xp
* @copyright 2014 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use block_xp\di;
use block_xp\local\plugin\addon;
/**
* Environment check.
*
* @return environment_results
*/
function block_xp_env_check_addon_compatibility(environment_results $result) {
if (!addon::is_container_present() || addon::is_compatible()) {
return null;
}
$result->setFeedbackStr(['envcheckaddonincompatibilitymessage', 'block_xp']);
$result->setStatus(false);
return $result;
}
/**
* Statuc checks.
*
* @return array
*/
function block_xp_status_checks(): array {
if (!addon::is_container_present()) {
return [];
}
return [new \block_xp\local\check\addon_compatibility()];
}
/**
* File serving.
*
* @param stdClass $course The course object.
* @param stdClass $bi Block instance record.
* @param context $context The context object.
* @param string $filearea The file area.
* @param array $args List of arguments.
* @param bool $forcedownload Whether or not to force the download of the file.
* @param array $options Array of options.
* @return void|false
*/
function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = []) {
$fs = di::get('file_server');
if ($fs instanceof \block_xp\local\file\block_file_server) {
$fs->serve_block_file($course, $bi, $context, $filearea, $args, $forcedownload, $options);
}
}
/**
* Navbar injection.
*
* @param \renderer_base $output The global renderer.
*/
function block_xp_render_navbar_output($output) {
global $USER, $COURSE, $PAGE;
// Never applies if not logged in.
if (!$USER->id || isguestuser()) {
return '';
}
$config = di::get('config');
if (!$config->get('navbardisplay')) {
return '';
}
// If we display per course, we require to be in a course, but not the frontpage.
$sitewide = $config->get('context') == CONTEXT_SYSTEM;
if (!$sitewide && (!$PAGE->context->get_course_context(false) || $COURSE->id == SITEID)) {
return '';
}
// Check if enabled.
$world = di::get('course_world_factory')->get_world($COURSE->id);
if (!$world->get_config()->get('enabled')) {
return;
}
// Check that the user can see the content.
$accessperms = $world->get_access_permissions();
if (!$accessperms->can_access()) {
return '';
}
$renderer = di::get('renderer');
return $renderer->navbar_widget($world, $world->get_store()->get_state($USER->id));
}
/**
* Get user preferences.
*
* @return array
*/
function block_xp_user_preferences() {
return [
'block_xp_notices' => [
'type' => PARAM_BOOL,
'permissioncallback' => function($user) {
global $USER;
return $user->id == $USER->id;
},
],
'block_xp_notice_quest' => [
'type' => PARAM_BOOL,
'permissioncallback' => function($user) {
global $USER;
return $user->id == $USER->id;
},
],
];
}