-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlib.php
executable file
·182 lines (162 loc) · 6.14 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
<?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/>.
/**
* Lib file
*
* introduced 23/05/17 17:59
*
* @package local_kopere_dashboard
* @copyright 2017 Eduardo Kraus {@link http://eduardokraus.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Function local_kopere_dashboard_extends_navigation
*
* @param global_navigation $nav
*
* @throws Exception
*/
function local_kopere_dashboard_extends_navigation(global_navigation $nav) {
local_kopere_dashboard_extend_navigation($nav);
}
/**
* Function local_kopere_dashboard_extend_navigation
*
* @param global_navigation $nav
*
* @throws Exception
*/
function local_kopere_dashboard_extend_navigation(global_navigation $nav) {
global $CFG, $PAGE;
require_once(__DIR__ . "/locallib.php");
$CFG->custommenuitems = trim($CFG->custommenuitems);
$CFG->custommenuitems = preg_replace('/.*kopere_dashboard.*/', "", $CFG->custommenuitems);
$CFG->custommenuitems = trim($CFG->custommenuitems);
if (isloggedin()) {
if ($CFG->branch > 400 && @get_config("local_kopere_dashboard", "menu")) {
$context = context_system::instance();
$hascapability = has_capability("local/kopere_dashboard:view", $context) ||
has_capability("local/kopere_dashboard:manage", $context);
if ($hascapability) {
$name = get_string("modulename", "local_kopere_dashboard");
$link = local_kopere_dashboard_makeurl("dashboard", "start");
$PAGE->requires->js_call_amd("local_kopere_dashboard/start_load",
"moremenu", [$name, $link]);
}
if (@get_config("local_kopere_dashboard", "menuwebpages")) {
add_pages_custommenuitems_400();
}
} else {
$context = context_system::instance();
if (has_capability("local/kopere_dashboard:view", $context) ||
has_capability("local/kopere_dashboard:manage", $context)) {
$node = $nav->add(
get_string("pluginname", "local_kopere_dashboard"),
new moodle_url(local_kopere_dashboard_makeurl("dashboard", "start")),
navigation_node::TYPE_CUSTOM,
null,
"kopere_dashboard",
new pix_icon("icon", get_string("pluginname", "local_kopere_dashboard"), "local_kopere_dashboard")
);
$node->showinflatnavigation = true;
}
}
} else {
if ($CFG->branch > 400 && @get_config("local_kopere_dashboard", "menu")) {
add_pages_custommenuitems_400();
}
}
}
/**
* Function add_pages_custommenuitems_400
*/
function add_pages_custommenuitems_400() {
global $CFG;
$cache = \cache::make("local_kopere_dashboard", "report_getdata_cache");
if (false && $cache->has("local_kopere_dashboard_menu")) {
$CFG->extramenu = $cache->get("local_kopere_dashboard_menu");
} else {
try {
$CFG->extramenu = "";
local_kopere_dashboard_extend_navigation__get_menus(0, "");
$cache->set("local_kopere_dashboard_menu", $CFG->extramenu);
} catch (dml_exception $e) { // phpcs:disable
}
}
$CFG->custommenuitems = "{$CFG->custommenuitems}\n{$CFG->extramenu}";
}
/**
* Function local_kopere_dashboard_extend_navigation__get_menus
*
* @param $menuid
* @param $prefix
*
* @throws dml_exception
*/
function local_kopere_dashboard_extend_navigation__get_menus($menuid, $prefix) {
global $DB, $CFG;
$menus = $DB->get_records_sql("
SELECT *
FROM {local_kopere_dashboard_menu}
WHERE menuid = :menuid
AND inheader = 1",
["menuid" => $menuid]);
foreach ($menus as $menu) {
$where = ["visible" => 1, "menuid" => $menu->id];
$webpages = $DB->get_records("local_kopere_dashboard_pages", $where, "pageorder ASC");
$CFG->extramenu .= "{$prefix} {$menu->title}|{$CFG->wwwroot}/local/kopere_dashboard/?menu={$menu->link}\n";
if ($webpages) {
/** @var \local_kopere_dashboard\vo\local_kopere_dashboard_pages $webpage */
foreach ($webpages as $webpage) {
$link = "{$CFG->wwwroot}/local/kopere_dashboard/?p={$webpage->link}";
$CFG->extramenu .= "{$prefix}- {$webpage->title}|{$link}\n";
}
}
local_kopere_dashboard_extend_navigation__get_menus($menu->id, "{$prefix}-");
}
}
/**
* Function local_kopere_dashboard_pluginfile
*
* @param $course
* @param $cm
* @param $context
* @param $filearea
* @param $args
* @param $forcedownload
* @param array $options
*
* @return bool
* @throws coding_exception
*/
function local_kopere_dashboard_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
if ($filearea == "overviewfiles") {
$filename = array_pop($args);
$filepath = $args ? "/" . implode("/", $args) . "/" : "/";
$fs = get_file_storage();
$file = $fs->get_file($context->id, "course", $filearea, 0, $filepath, $filename);
if (!$file || $file->is_directory()) {
die("ops...");
}
send_stored_file($file, 0, 0, $forcedownload, $options);
}
$fs = get_file_storage();
if (!$file = $fs->get_file($context->id, "local_kopere_dashboard", "editor_webpages", $args[0], "/", $args[1])) {
return false;
}
send_stored_file($file, 0, 0, $forcedownload, $options);
return true;
}