-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsettings.php
More file actions
151 lines (128 loc) · 6.06 KB
/
settings.php
File metadata and controls
151 lines (128 loc) · 6.06 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
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
<?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/>.
/**
* Settings for the confetti plugin
*
* @package local_confetti
* @copyright 2025 Odei Alba <odeialba@odeialba.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use local_confetti\admin_setting_configemoji;
if ($hassiteconfig) { // Needs this condition or there is an error on login page.
// Create the new settings page - make sure we use proper section names as per documentation
$settings = new admin_settingpage('local_confetti', get_string('pluginname', 'local_confetti'));
$ADMIN->add('localplugins', $settings);
// Add settings section header.
$settings->add(new admin_setting_heading(
'local_confetti/settingsheader',
get_string('settingsheader', 'local_confetti'),
get_string('settingsdescription', 'local_confetti')
));
// Add first checkbox setting - Enable on frontpage.
$settings->add(new admin_setting_configcheckbox(
'local_confetti/enableonfrontpage',
get_string('enableonfrontpage', 'local_confetti'),
get_string('enableonfrontpage_desc', 'local_confetti'),
0 // Default value (0 = unchecked, 1 = checked).
));
// Add first checkbox setting - Enable on frontpage.
$settings->add(new admin_setting_configcheckbox(
'local_confetti/displayeverylogin',
get_string('displayeverylogin', 'local_confetti'),
get_string('displayeverylogin_desc', 'local_confetti'),
1 // Default value (0 = unchecked, 1 = checked).
));
// Confetti preset selection
$confettipresets = [
'realistic' => get_string('confettipresetrealistic', 'local_confetti'),
'fireworks' => get_string('confettipresetfireworks', 'local_confetti'),
'snow' => get_string('confettipresetsnow', 'local_confetti'),
'school' => get_string('confettipresetschool', 'local_confetti'),
'emoji' => get_string('confettipresetemoji', 'local_confetti'),
'text' => get_string('confettipresettext', 'local_confetti')
];
$settings->add(new admin_setting_configselect(
'local_confetti/confettipreset',
get_string('confettipreset', 'local_confetti'),
get_string('confettipreset_desc', 'local_confetti'),
'realistic', // Default value
$confettipresets
));
// Show a text input when the value of the preset is text
$settings->add(new admin_setting_configtext(
'local_confetti/confettitext',
get_string('confettitext', 'local_confetti'),
get_string('confettitext_desc', 'local_confetti'),
'' // Default value
));
$settings->hide_if('local_confetti/confettitext', 'local_confetti/confettipreset', 'neq', 'text');
/*$settings->add(new admin_setting_configemoji(
'local_confetti/confettiemoji',
get_string('confettiemoji', 'local_confetti'),
get_string('confettiemoji_desc', 'local_confetti'),
'' // Default value
));
$settings->hide_if('local_confetti/confettiemoji', 'local_confetti/confettipreset', 'neq', 'emoji');*/
// Add preview button
$previewhtml = \core\output\html_writer::start_div('form-item row');
$previewhtml .= \core\output\html_writer::start_div('form-label col-sm-3 text-sm-end');
$previewhtml .= \core\output\html_writer::tag('label', get_string('previewconfetti', 'local_confetti'));
$previewhtml .= \core\output\html_writer::end_div();
$previewhtml .= \core\output\html_writer::start_div('form-setting col-sm-9');
$previewhtml .= \core\output\html_writer::tag('p', get_string('previewconfetti_desc', 'local_confetti'));
$previewhtml .= \core\output\html_writer::tag('button', get_string('previewbutton', 'local_confetti'),
['id' => 'local_confetti_preview_button', 'class' => 'btn btn-secondary mb-4', 'type' => 'button']);
$previewhtml .= \core\output\html_writer::end_div();
$previewhtml .= \core\output\html_writer::end_div();
$settings->add(new admin_setting_heading(
'local_confetti/previewheading',
'',
$previewhtml
));
// Add Moodle events section header
$settings->add(new admin_setting_heading(
'local_confetti/moodleevents',
get_string('moodleevents', 'local_confetti'),
get_string('moodleevents_desc', 'local_confetti')
));
$observeroptions = [];
include("db/events.php");
// Copy the $observers array and remove the first element
$observeroptions = $observers;
array_shift($observeroptions);
// Create a new array from $observeroptions in the same format as $eventsoptions
$observerevents = [];
foreach ($observeroptions as $observer) {
$eventname = $observer['eventname'];
// Extract the last part after the last backslash
$parts = explode('\\', $eventname);
$eventkey = end($parts);
// Convert to lowercase to match eventsoptions format
$eventkey = strtolower($eventkey);
// Add to the new array with the event key as the key
$observerevents[$eventkey] = get_string('event_' . $eventkey, 'local_confetti', $eventkey);
}
$settings->add(new admin_setting_configmultiselect(
'local_confetti/eventselect',
get_string('eventselect', 'local_confetti'),
get_string('eventselect_desc', 'local_confetti'),
[], // Default selection
$observerevents
));
global $PAGE;
$PAGE->requires->js_call_amd('local_confetti/preview', 'init');
}