-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.php
307 lines (270 loc) · 13.5 KB
/
settings.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Plugin administration pages are defined here.
*
* @package quiz_archiver
* @category admin
* @copyright 2024 Niels Gandraß <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die(); // @codeCoverageIgnore
require_once(__DIR__ . '/classes/local/autoinstall.php');
use quiz_archiver\ArchiveJob;
use quiz_archiver\local\admin\setting\admin_setting_archive_filename_pattern;
use quiz_archiver\local\admin\setting\admin_setting_attempt_filename_pattern;
use quiz_archiver\local\admin\setting\admin_setting_configcheckbox_alwaystrue;
use quiz_archiver\local\autoinstall;
use quiz_archiver\Report;
global $DB;
if ($hassiteconfig) {
$settings = new admin_settingpage('quiz_archiver_settings', new lang_string('pluginname', 'quiz_archiver'));
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
if ($ADMIN->fulltree) {
// Descriptive text.
$settings->add(new admin_setting_heading('quiz_archiver/header_docs',
null,
get_string('setting_header_docs_desc', 'quiz_archiver')
));
// Autoinstall.
if (autoinstall::plugin_is_unconfigured()) {
// @codingStandardsIgnoreStart
$autoinstallurl = new moodle_url('/mod/quiz/report/archiver/adminui/autoinstall.php');
$autoinstalldesc = "<a href='{$autoinstallurl}' class='btn btn-primary'>".get_string('autoinstall_start_now', 'quiz_archiver')."</a>";
$autoinstalldesc .= "<br><br><p>".get_string('autoinstall_explanation', 'quiz_archiver')."</p>";
// @codingStandardsIgnoreEnd
} else {
$autoinstalldesc = get_string('autoinstall_already_configured', 'quiz_archiver');
}
$settings->add(new admin_setting_description('quiz_archiver/autoinstall',
get_string('setting_autoconfigure', 'quiz_archiver'),
$autoinstalldesc
));
// Generic settings.
$settings->add(new admin_setting_heading('quiz_archiver/header_archive_worker',
get_string('setting_header_archive_worker', 'quiz_archiver'),
get_string('setting_header_archive_worker_desc', 'quiz_archiver')
));
// Worker URL.
$settings->add(new admin_setting_configtext('quiz_archiver/worker_url',
get_string('setting_worker_url', 'quiz_archiver'),
get_string('setting_worker_url_desc', 'quiz_archiver'),
'',
PARAM_TEXT
));
// Webservice.
$settings->add(new admin_setting_configselect('quiz_archiver/webservice_id',
get_string('webservice', 'webservice'),
get_string('setting_webservice_desc', 'quiz_archiver'),
null,
[-1 => ''] + $DB->get_records_menu('external_services', null, 'name ASC', 'id, name')
));
// Webservice user.
$settings->add(new admin_setting_configtext('quiz_archiver/webservice_userid',
get_string('setting_webservice_userid', 'quiz_archiver'),
get_string('setting_webservice_userid_desc', 'quiz_archiver'),
'',
PARAM_INT
));
// Job timeout.
$settings->add(new admin_setting_configtext('quiz_archiver/job_timeout_min',
get_string('setting_job_timeout_min', 'quiz_archiver'),
get_string('setting_job_timeout_min_desc', 'quiz_archiver'),
'60',
PARAM_INT
));
// Custom Moodle base URL.
$settings->add(new admin_setting_configtext('quiz_archiver/internal_wwwroot',
get_string('setting_internal_wwwroot', 'quiz_archiver'),
get_string('setting_internal_wwwroot_desc', 'quiz_archiver'),
'',
PARAM_TEXT
));
// Job Presets.
$settings->add(new admin_setting_heading('quiz_archiver/header_job_presets',
get_string('setting_header_job_presets', 'quiz_archiver'),
get_string('setting_header_job_presets_desc', 'quiz_archiver'),
));
// Export Attempts.
$settings->add(new admin_setting_configcheckbox_alwaystrue('quiz_archiver/job_preset_export_attempts',
get_string('export_attempts', 'quiz_archiver'),
get_string('export_attempts_help', 'quiz_archiver'),
'1',
));
// Attempt report sections.
foreach (Report::SECTIONS as $section) {
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_export_report_section_'.$section,
get_string('export_report_section_'.$section, 'quiz_archiver'),
get_string('export_report_section_'.$section.'_help', 'quiz_archiver'),
'1',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
foreach (Report::SECTION_DEPENDENCIES[$section] as $dependency) {
$set->add_dependent_on('quiz_archiver/job_preset_export_report_section_'.$dependency);
}
$settings->add($set);
}
// Export Quiz Backup.
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_export_quiz_backup',
get_string('export_quiz_backup', 'quiz_archiver'),
get_string('export_quiz_backup_help', 'quiz_archiver'),
'1',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Export Course Backup.
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_export_course_backup',
get_string('export_course_backup', 'quiz_archiver'),
get_string('export_course_backup_help', 'quiz_archiver'),
'0',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Export paper format.
$set = new admin_setting_configselect('quiz_archiver/job_preset_export_attempts_paper_format',
get_string('export_attempts_paper_format', 'quiz_archiver'),
get_string('export_attempts_paper_format_help', 'quiz_archiver'),
'A4',
array_combine(Report::PAPER_FORMATS, Report::PAPER_FORMATS),
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Archive filename pattern.
$set = new admin_setting_archive_filename_pattern('quiz_archiver/job_preset_archive_filename_pattern',
get_string('archive_filename_pattern', 'quiz_archiver'),
get_string('archive_filename_pattern_help', 'quiz_archiver', [
'variables' => array_reduce(
ArchiveJob::ARCHIVE_FILENAME_PATTERN_VARIABLES,
fn ($res, $varname) => $res."<li><code>\${".$varname."}</code>: ".
get_string('export_attempts_filename_pattern_variable_'.$varname, 'quiz_archiver').
"</li>"
, ""
),
'forbiddenchars' => implode('', ArchiveJob::FILENAME_FORBIDDEN_CHARACTERS),
]),
'quiz-archive-${courseshortname}-${courseid}-${quizname}-${quizid}_${date}-${time}',
PARAM_TEXT,
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Attempt filename pattern.
$set = new admin_setting_attempt_filename_pattern('quiz_archiver/job_preset_export_attempts_filename_pattern',
get_string('export_attempts_filename_pattern', 'quiz_archiver'),
get_string('export_attempts_filename_pattern_help', 'quiz_archiver', [
'variables' => array_reduce(
ArchiveJob::ATTEMPT_FILENAME_PATTERN_VARIABLES,
fn ($res, $varname) => $res."<li><code>\${".$varname."}</code>: ".
get_string('export_attempts_filename_pattern_variable_'.$varname, 'quiz_archiver').
"</li>"
, ""
),
'forbiddenchars' => implode('', ArchiveJob::FILENAME_FORBIDDEN_CHARACTERS),
]),
'attempt-${attemptid}-${username}_${date}-${time}',
PARAM_TEXT,
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Image optimization.
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_export_attempts_image_optimize',
get_string('export_attempts_image_optimize', 'quiz_archiver'),
get_string('export_attempts_image_optimize_help', 'quiz_archiver'),
'0',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Image optimization: Max width.
$set = new admin_setting_configtext('quiz_archiver/job_preset_export_attempts_image_optimize_width',
get_string('export_attempts_image_optimize_width', 'quiz_archiver'),
get_string('export_attempts_image_optimize_width_help', 'quiz_archiver'),
'1280',
PARAM_INT
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$set->add_dependent_on('quiz_archiver/job_preset_export_attempts_image_optimize');
$settings->add($set);
// Image optimization: Max height.
$set = new admin_setting_configtext('quiz_archiver/job_preset_export_attempts_image_optimize_height',
get_string('export_attempts_image_optimize_height', 'quiz_archiver'),
get_string('export_attempts_image_optimize_height_help', 'quiz_archiver'),
'1280',
PARAM_INT
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$set->add_dependent_on('quiz_archiver/job_preset_export_attempts_image_optimize');
$settings->add($set);
// Image optimization: Quality.
$set = new admin_setting_configtext('quiz_archiver/job_preset_export_attempts_image_optimize_quality',
get_string('export_attempts_image_optimize_quality', 'quiz_archiver'),
get_string('export_attempts_image_optimize_quality_help', 'quiz_archiver'),
'85',
PARAM_INT
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$set->add_dependent_on('quiz_archiver/job_preset_export_attempts_image_optimize');
$settings->add($set);
// Keep HTML files.
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_export_attempts_keep_html_files',
get_string('export_attempts_keep_html_files', 'quiz_archiver'),
get_string('export_attempts_keep_html_files_help', 'quiz_archiver'),
'0',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, false);
$settings->add($set);
// Archive autodelete.
$set = new admin_setting_configcheckbox('quiz_archiver/job_preset_archive_autodelete',
get_string('archive_autodelete', 'quiz_archiver'),
get_string('archive_autodelete_help', 'quiz_archiver'),
'0',
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, true);
$settings->add($set);
// Archive autodelete: Retention time.
$set = new admin_setting_configduration('quiz_archiver/job_preset_archive_retention_time',
get_string('archive_retention_time', 'quiz_archiver'),
get_string('archive_retention_time_help', 'quiz_archiver'),
3 * YEARSECS,
DAYSECS
);
$set->set_locked_flag_options(admin_setting_flag::ENABLED, true);
$set->add_dependent_on('quiz_archiver/job_preset_archive_autodelete');
$settings->add($set);
// Time-Stamp Protocol settings.
$settings->add(new admin_setting_heading('quit_archiver/header_tsp',
get_string('setting_header_tsp', 'quiz_archiver'),
get_string('setting_header_tsp_desc', 'quiz_archiver')
));
// Enable TSP.
$settings->add(new admin_setting_configcheckbox('quiz_archiver/tsp_enable',
get_string('setting_tsp_enable', 'quiz_archiver'),
get_string('setting_tsp_enable_desc', 'quiz_archiver'),
'0'
));
// TSP automatic signing.
$settings->add(new admin_setting_configcheckbox('quiz_archiver/tsp_automatic_signing',
get_string('setting_tsp_automatic_signing', 'quiz_archiver'),
get_string('setting_tsp_automatic_signing_desc', 'quiz_archiver'),
'1'
));
// TSP server URL.
$settings->add(new admin_setting_configtext('quiz_archiver/tsp_server_url',
get_string('setting_tsp_server_url', 'quiz_archiver'),
get_string('setting_tsp_server_url_desc', 'quiz_archiver'),
'https://freetsa.org/tsr',
PARAM_URL
));
}
}