forked from uofr/moodle-theme_urcourses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locallib.php
122 lines (102 loc) · 4.4 KB
/
locallib.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
<?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/>.
/**
* Theme UR Courses - Local library
*
* @package theme_urcourses
* @copyright 2023 Alexander Bias <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/***************************************************************
* EXTENSION POINT:
* Add whatever UR Courses local functions you need here.
**************************************************************/
function theme_urcourses_enable_darkmode() {
return set_user_preference('theme_urcourses_darkmode', true);
}
function theme_urcourses_disable_darkmode() {
return unset_user_preference('theme_urcourses_darkmode');
}
function theme_urcourses_darkmode_enabled() {
return get_user_preferences('theme_urcourses_darkmode', false);
}
function theme_urcourses_can_create_test_student($userid) {
global $DB;
$teacherroleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
$managerroleid = $DB->get_field('role', 'id', ['shortname' => 'manager']);
$designerroleid = $DB->get_field('role', 'id', ['shortname' => 'instdesigner']);
$isteacher = $DB->record_exists('role_assignments', ['userid' => $userid, 'roleid' => $teacherroleid]);
$ismanager = $DB->record_exists('role_assignments', ['userid' => $userid, 'roleid' => $managerroleid]);
$isdesigner = $DB->record_exists('role_assignments', ['userid' => $userid, 'roleid' => $designerroleid]);
return ($isteacher|| $ismanager || $isdesigner || is_siteadmin());
}
function theme_urcourses_has_test_student_account($username) {
global $DB;
$email = "[email protected]";
return $DB->record_exists('user', ['email' => $email]);
}
function theme_urcourses_create_darkmode_link() {
global $PAGE;
$darkmodeenabled = theme_urcourses_darkmode_enabled();
$darkmodelink = new stdClass();
$darkmodelink->divider = false;
$darkmodelink->itemtype = 'link';
$darkmodelink->link = true;
$darkmodelink->pixicon = $darkmodeenabled ? 'lightmode' : 'darkmode';
$darkmodelink->pixplugin = 'theme_urcourses';
$darkmodelink->title = theme_urcourses_darkmode_enabled()
? get_string('disabledarkmode', 'theme_urcourses')
: get_string('enabledarkmode', 'theme_urcourses');
$darkmodelink->titleidentifier = 'darkmode,theme_urcourses';
$darkmodelink->url = new moodle_url($PAGE->url, ['darkmode' => !$darkmodeenabled]);
return $darkmodelink;
}
function theme_urcourses_create_teststudent_link($hasteststudentaccount) {
global $USER;
$studentaccountlink = new \stdClass();
$studentaccountlink->attributes = [
[
'name' => 'data-action',
'value' => $hasteststudentaccount ? 'resetteststudent' : 'createteststudent'
]
];
$studentaccountlink->divider = false;
$studentaccountlink->itemtype = 'link';
$studentaccountlink->link = true;
$studentaccountlink->pixicon = 'i/user';
$studentaccountlink->title = $hasteststudentaccount
? get_string('modifyteststudent', 'theme_urcourses')
: get_string('createteststudent', 'theme_urcourses');
$studentaccountlink->titleidentifier = 'studentaccount,theme_urcourses';
$studentaccountlink->url = '#';
return $studentaccountlink;
}
function theme_urcourses_add_custom_user_menu_items($usermenuitems, $customitems) {
$itemcount = count($usermenuitems);
$preferenceskey = 0;
foreach($usermenuitems as $key => $item) {
if (isset($item->title) && $item->title == 'Preferences') {
$preferenceskey = $key;
break;
}
}
$insertpoint = $preferenceskey + 1;
return array_merge(
array_slice($usermenuitems, 0, $insertpoint),
$customitems,
array_slice($usermenuitems, $insertpoint, $itemcount)
);
}