-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings.php
197 lines (169 loc) · 9.01 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
<?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/>.
/**
* Liquidus
*
* @package local_liquidus
* @copyright Copyright (c) 2020 Open LMS
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_liquidus\api\analytics;
use local_liquidus\injector;
defined('MOODLE_INTERNAL') || die;
/** @var admin_root $ADMIN */
/** @var bool $hassiteconfig */
global $CFG, $PAGE;
if (!$hassiteconfig) {
return;
}
$pluginname = 'local_liquidus';
// Var to hold the 'notchecked' hide-if condition for ease of use.
$notcheckedcondition = 'notchecked';
$settings = new admin_settingpage($pluginname, get_string('pluginname', $pluginname));
$ADMIN->add('localplugins', $settings);
if ($ADMIN->fulltree) {
// We need to import the library to use a setting update callback in here.
require_once($CFG->dirroot.'/local/liquidus/lib.php');
$name = new lang_string('general', $pluginname);
$description = new lang_string('general_help', $pluginname);
$settings->add(new admin_setting_heading('general', $name, $description));
$name = "{$pluginname}/enabled";
$title = new lang_string('enabled', $pluginname);
$description = empty($CFG->local_liquidus_disable_tracker_config) ? new lang_string('enabled_desc', $pluginname) :
new lang_string('enabled_olms_desc', $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$setting->set_updatedcallback('local_liquidus_create_consent_log');
$settings->add($setting);
if (empty($CFG->local_liquidus_disable_tracker_config)) { // Flag to disable plugin config (for internal Open LMS use.)
$types = injector::get_instance()->get_analytics_types();
foreach ($types as $type) {
$name = new lang_string($type, $pluginname);
$description = new lang_string("{$type}_desc", $pluginname);
// Setting names must be unique due to bugs in admin_apply_default_settings.
$settings->add(new admin_setting_heading('heading' . $type, $name, $description));
$prefix = "{$pluginname}/{$type}";
$name = $prefix;
$title = new lang_string($type, $pluginname);
$description = new lang_string("{$type}_desc", $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
if (!empty($CFG->local_liquidus_enable_eventdef)) {
$name = "{$prefix}_eventdef";
$title = new lang_string('eventdef', $pluginname);
$description = new lang_string('eventdef_desc', $pluginname);
$default = '';
$setting = new admin_setting_configtextarea($name, $title, $description, $default);
$settings->add($setting);
}
$name = "{$prefix}_unidentifiable_staticshares";
$title = new lang_string('unidentifiable_staticshares', $pluginname);
$description = new lang_string('unidentifiable_staticshares_desc', $pluginname);
$staticshares = $default = [];
foreach (\local_liquidus\api\analytics::UNIDENTIFIABLE_STATIC_SHARES as $share) {
$staticshares[$share] = get_string('staticshares_' . $share, 'local_liquidus');
$default[] = $share;
}
$setting = new admin_setting_configmultiselect($name, $title, $description, $default, $staticshares);
$settings->add($setting);
$name = "{$prefix}_masquerade_handling";
$title = new lang_string('masquerade_handling', $pluginname);
$description = new lang_string('masquerade_handling_desc', $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
$name = "{$prefix}_trackadmin";
$title = new lang_string('trackadmin', $pluginname);
$description = new lang_string('trackadmin_desc', $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
$name = "{$prefix}_tracknonadmin";
$title = new lang_string('tracknonadmin', $pluginname);
$description = new lang_string('tracknonadmin_desc', $pluginname);
$default = '1';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
$name = "{$prefix}_cleanurl";
$title = new lang_string('cleanurl', $pluginname);
$description = new lang_string('cleanurl_desc', $pluginname);
$default = '1';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
// TODO: Enable and show this setting only if user has accepted the privacy agreement.
$name = "{$prefix}_share_identifiable";
$title = new lang_string('shareidentifiable', $pluginname);
$description = new lang_string('shareidentifiable_desc', $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
$name = "{$prefix}_trackroles";
$title = new lang_string('trackroles', $pluginname);
$description = new lang_string('trackroles_desc', $pluginname);
$roles = $default = [];
$allrolesshortname = local_liquidus\api\analytics::get_allrolesshortname();
foreach ($allrolesshortname as $role) {
$roles[$role] = $role;
$default[] = $role;
}
$setting = new admin_setting_configmultiselect($name, $title, $description, $default, $roles);
$settings->add($setting);
if (!empty($CFG->local_liquidus_identifiable_share_providers) && in_array($type, $CFG->local_liquidus_identifiable_share_providers)) {
$name = "{$prefix}_identifiable_staticshares";
$title = new lang_string('identifiable_staticshares', $pluginname);
$description = new lang_string('identifiable_staticshares_desc', $pluginname);
$staticshares = $default = [];
foreach (\local_liquidus\api\analytics::IDENTIFIABLE_STATIC_SHARES as $share) {
$staticshares[$share] = get_string('staticshares_' . $share, 'local_liquidus');
$default[] = $share;
}
$setting = new admin_setting_configmultiselect($name, $title, $description, $default, $staticshares);
$settings->add($setting);
}
// Additional settings specific to providers.
foreach (injector::SETTING_PROVIDER_MAPPING as $setting => $providers) {
if (isset($providers[$type])) {
$name = "{$prefix}_{$setting}";
$title = new lang_string($setting, $pluginname);
$description = new lang_string("{$setting}_desc", $pluginname);
$default = '0';
$setting = new admin_setting_configcheckbox($name, $title, $description, $default);
$settings->add($setting);
}
}
$classname = "\\local_liquidus\\api\\{$type}";
if (!class_exists($classname, true)) {
debugging("Local Liquidus Module: Analytics setting '{$type}' doesn't map to a class name.");
}
/** @var analytics $engine */
$engine = new $classname;
$configsettings = $engine::get_config_settings();
foreach ($configsettings as $configsetting) {
$name = "{$pluginname}/{$configsetting}";
$title = new lang_string($configsetting, $pluginname);
$description = new lang_string("{$configsetting}_desc", $pluginname);
$default = '';
$setting = new admin_setting_configtext($name, $title, $description, $default);
$settings->add($setting);
}
}
if (!CLI_SCRIPT) {
// AMD that moves settings into tabs.
$PAGE->requires->js_call_amd('local_liquidus/settings-handler-lazy', 'init', ['types' => $types]);
}
}
}