-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib.php
116 lines (103 loc) · 4 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
<?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/>.
/**
* Moodle hooks for local_adele
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_adele\learning_path_editors;
use local_adele\learning_paths;
define('COURSES_COND_MASTER', 200);
define('COURSES_COND_NODE_FINISHED', 190);
define('COURSES_COND_PARENT_NODE', 180);
define('COURSES_COND_CATQUIZ', 170);
define('COURSES_COND_MODQUIZ', 160);
define('COURSES_COND_MANUALLY', 150);
define('COURSES_COND_TIMED', 140);
define('COURSES_PRIORITY_BEST', 1);
define('COURSES_PRIORITY_SECOND', 2);
define('COURSES_PRIORITY_THIRD', 3);
define('SESSION_KEY_ADELE', 'LOCAL_ADELE_EDITOR');
define('SESSION_KEY_ADELE_ROLE', 'LOCAL_ADELE_ROLE');
/**
* Renders the popup Link.
*
* @param renderer_base $renderer
* @return string The HTML
*/
function local_adele_render_navbar_output(\renderer_base $renderer) {
global $CFG, $DB, $USER;
if (
!isloggedin() ||
isguestuser()
) {
return '';
}
$iseditor = learning_paths::check_access();
if (
$iseditor === true
) {
$output = '<div class="popover-region nav-link icon-no-margin dropdown">
<a class="btn btn-secondary"
id="dropdownMenuButton" aria-haspopup="true" aria-expanded="false" href="'
. $CFG->wwwroot . '/local/adele/index.php#/learningpaths"
role="button">
' . get_string('btnadele', 'local_adele') . '
</a>
</div>';
return $output;
}
return '';
}
/**
* Callback checking permissions and preparing the file for serving plugin files, see File API.
*
* @param stdClass $course the course object
* @param stdClass $cm the course module object
* @param stdClass $context the context
* @param string $filearea the name of the file area
* @param array $args extra arguments (itemid, path)
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if the file not found, just send the file otherwise and do not return anything
*/
function local_adele_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
// Check the contextlevel is as expected - if your plugin is a block.
// We need context course if wee like to acces template files.
if (!in_array($context->contextlevel, [CONTEXT_SYSTEM])) {
return false;
}
// Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
$itemid = array_shift($args); // The first item in the $args array.
$filename = array_pop($args); // The last item in the $args array.
if (!$args) {
// Var $args is empty => the path is '/'.
$filepath = '/';
} else {
// Var $args contains elements of the filepath.
$filepath = '/' . implode('/', $args) . '/';
}
// Retrieve the file from the Files API.
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'local_adele', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false; // The file does not exist.
}
// Send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 0, 0, true, $options);
}