forked from eLearning-TUDarmstadt/moodle-tool_cleanupusers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
117 lines (97 loc) · 4.06 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
<?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/>.
/**
* handler for inplace editabled
*
* @package tool_cleanupusers
* @copyright 2024 Ostfalia
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/classes/output/inplace_editable.php');
require_once(__DIR__ . '/classes/userstatuschecker.php');
use core_external\external_api;
/**
* updates the configuration with the new value entered with editable
*
* @param $itemtype type of inplace editable
* @param $plugin plugin name
* @param $newvalue1 new value
* @return array|\core\output\inplace_editable|void
* @throws \core_external\restricted_context_exception
* @throws coding_exception
* @throws dml_exception
* @throws invalid_parameter_exception
* @throws moodle_exception
*/
function tool_cleanupusers_inplace_editable($itemtype, $plugin, $newvalue1) {
// Must call validate_context for either system, or course or course module context.
// This will both check access and set current context.
external_api::validate_context(context_system::instance());
// Check permission of the user to update this item.
require_admin();
if ($itemtype === 'authmethod') {
$newvalue1 = clean_param($newvalue1, PARAM_NOTAGS);
// Prepare the element for the output:
$auths = get_enabled_auth_plugins();
// convert string with array text e.g. "['0','1']" to actual array
$newvaluearray = str_replace("'", '"', $newvalue1);
$newvaluearray = json_decode($newvaluearray, true);
if (is_array($newvaluearray)) {
$displayvalues = [];
foreach ($newvaluearray as $index) {
$displayvalues[] = $auths[$index];
}
$newvaluetext = implode(',', $displayvalues);
} else {
if (is_string($newvaluearray)) {
$newvaluetext = $auths[$newvaluearray];
} else {
$newvaluetext = '';
}
}
set_config(CONFIG_AUTH_METHOD, $newvaluetext, 'userstatus_' . $plugin);
return \tool_cleanupusers\helper::render_auth_editable($plugin, $newvaluetext, $newvalue1);
}
if ($itemtype === 'deletetime') {
$newvalue1 = clean_param($newvalue1, PARAM_INT);
if ($newvalue1 < 0 ) {
// ignore values < 0
throw new moodle_exception("value must not be negative");
}
set_config(CONFIG_DELETETIME, $newvalue1, 'userstatus_' . $plugin);
$templ = \tool_cleanupusers\helper::render_deletetime_editable($plugin, $newvalue1);
return $templ;
}
if ($itemtype === 'suspendtime') {
$newvalue1 = clean_param($newvalue1, PARAM_INT);
if ($newvalue1 < 0 ) {
// ignore values < 0
throw new moodle_exception("value must not be negative");
}
set_config(CONFIG_SUSPENDTIME, $newvalue1, 'userstatus_' . $plugin);
return \tool_cleanupusers\helper::render_suspendtime_editable(
$plugin, $newvalue1);
}
if ($itemtype === 'neverloggedin') {
$newvalue1 = clean_param($newvalue1, PARAM_NOTAGS);
if (!empty($newvalue1) && ($newvalue1 != 0 && $newvalue1 != 1)) {
throw new moodle_exception("invalid value");
}
set_config(CONFIG_NEVER_LOGGED_IN, $newvalue1, 'userstatus_' . $plugin);
return \tool_cleanupusers\helper::render_no_login_editiable($plugin, $newvalue1);
}
}