-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.php
More file actions
119 lines (104 loc) · 3.42 KB
/
lib.php
File metadata and controls
119 lines (104 loc) · 3.42 KB
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
<?php
/**
* This file is part of Totara Learn
*
* Copyright (C) 2026 onwards Totara Learning Solutions LTD
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Dave Wallace <dave.wallace@totara.com>
* @package theme_example
*/
use core\theme\file\theme_file;
defined('MOODLE_INTERNAL') || die();
/**
* Adds theme appearance links to category nav.
*
* @param navigation_node $navigation The navigation node to extend
* @param context $context The context of the course
* @return void|null return null if we don't want to display the node.
*/
function theme_example_extend_navigation_category_settings($navigation, $context) {
global $PAGE, $CFG, $DB;
if (empty($CFG->tenantsenabled)) {
return null;
}
if (!$context->tenantid) {
return null;
}
if (!($context instanceof context_coursecat)) {
return;
}
$tenant = $DB->get_record('tenant', ['categoryid' => $context->instanceid]);
if (!$tenant) {
return null;
}
// Leave when user does not have the right capabilities.
$categorycontext = context_coursecat::instance($tenant->categoryid);
if (!has_capability('totara/tui:themesettings', $categorycontext)) {
return null;
}
$url = new moodle_url('/totara/tui/theme_settings.php',
[
'theme' => 'example',
'tenant_id' => $tenant->id,
]
);
$node = navigation_node::create(
get_string('pluginname', 'theme_example'),
$url,
navigation_node::NODETYPE_LEAF,
null,
'example_editor',
new pix_icon('i/settings', '')
);
$appearance = $navigation->find('category_appearance', navigation_node::TYPE_CONTAINER);
if (!$appearance) {
$appearance = $navigation->add(
get_string('appearance', 'admin'),
null,
navigation_node::TYPE_CONTAINER,
null,
'category_appearance'
);
}
$appearance->add_node($node);
if ($PAGE->url->compare($url, URL_MATCH_EXACT)) {
$appearance->force_open();
$node->make_active();
}
}
/**
* To download the file we upload in theme_example filearea
*
* @param stdClass$course
* @param stdClass $cm
* @param context $context
* @param string $filearea
* @param array $args
* @param bool$forcedownload
* @param array $options
* @return void Download the file
*/
function theme_example_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, $options = []) {
$component = 'theme_example';
$itemid = $args[0];
$filename = $args[1];
$fs = get_file_storage();
$file = $fs->get_file($context->id, $component, $filearea, $itemid, '/', $filename);
if (empty($file)) {
send_file_not_found();
}
send_stored_file($file, 60*60*24, 0, false, $options); // Enable long cache and disable forcedownload.
}