1434 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Upgrade scripts for the notification local plugin
|
|
|
19 |
*
|
|
|
20 |
* @package local_moofactory_notification
|
|
|
21 |
* @copyright 2020 Patrick ROCHET <patrick.r@lmsfactory.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Upgrade script for local_moofactory_notification
|
|
|
29 |
*
|
|
|
30 |
* @param int $oldversion the version we are upgrading from
|
|
|
31 |
* @return bool result
|
|
|
32 |
*/
|
|
|
33 |
function xmldb_local_moofactory_notification_upgrade($oldversion) {
|
|
|
34 |
global $CFG, $DB;
|
|
|
35 |
require_login();
|
|
|
36 |
|
|
|
37 |
$dbman = $DB->get_manager();
|
|
|
38 |
|
|
|
39 |
if ($oldversion < 2021012700) {
|
|
|
40 |
// Define table local_mf_accessnotif to be created.
|
|
|
41 |
$table = new xmldb_table('local_mf_accessnotif');
|
|
|
42 |
|
|
|
43 |
// Adding fields to table local_mf_accessnotif.
|
|
|
44 |
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
|
|
45 |
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
46 |
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
47 |
$table->add_field('notificationtime', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
48 |
$table->add_field('notificationnumber', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
49 |
|
|
|
50 |
// Adding keys to table local_mf_accessnotif.
|
|
|
51 |
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
|
|
52 |
|
|
|
53 |
// Conditionally launch create table for local_mf_accessnotif.
|
|
|
54 |
if (!$dbman->table_exists($table)) {
|
|
|
55 |
$dbman->create_table($table);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if ($oldversion < 2021020900) {
|
|
|
60 |
// Notifications par défaut.
|
|
|
61 |
// Non accès aux cours.
|
|
|
62 |
$record = $DB->get_record('local_mf_notification', array('type'=>'courseaccess', 'base'=>1));
|
|
|
63 |
if(empty($record)){
|
|
|
64 |
$html = "{{firstname}} {{lastname}}<br><br>";
|
|
|
65 |
$html .= "Vous êtes inscrit à la formation « \"<a href=\"{{courseurl}}\"\>{{coursename}}</a>\" » dans la plateforme {{lmsname}}.<br>";
|
|
|
66 |
$html .= "Vous n’êtes pas venu dans ce cours depuis au moins {{interval}}. Rencontrez vous un problème ?<br>";
|
|
|
67 |
$html .= "Nous vous invitons à vous reconnecter et à suivre votre formation.";
|
|
|
68 |
|
|
|
69 |
$record = new stdClass();
|
|
|
70 |
$record->base = 1;
|
|
|
71 |
$record->type = "courseaccess";
|
|
|
72 |
$record->name = "Non accès aux cours par défaut";
|
|
|
73 |
$record->subject = "Non accès à un cours";
|
|
|
74 |
$record->bodyhtml = $html;
|
|
|
75 |
|
|
|
76 |
$DB->insert_record('local_mf_notification', $record);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
if ($oldversion < 2021031500) {
|
|
|
81 |
// Notifications par défaut.
|
|
|
82 |
// Evènement de site.
|
|
|
83 |
$record = $DB->get_record('local_mf_notification', array('type'=>'siteevent', 'base'=>1));
|
|
|
84 |
if(empty($record)){
|
|
|
85 |
$html = "{{firstname}} {{lastname}}<br><br>";
|
|
|
86 |
$html .= "Le {{eventdate}}, {{eventname}} sur la plateforme « <a href=\"{{lmsurl}}\"\>{{lmsname}}</a> », n’oubliez pas d’inscrire cet évènement dans votre calendrier.";
|
|
|
87 |
|
|
|
88 |
$record = new stdClass();
|
|
|
89 |
$record->base = 1;
|
|
|
90 |
$record->type = "siteevent";
|
|
|
91 |
$record->name = "Evènement de site par défaut";
|
|
|
92 |
$record->subject = "Rappel d'évènement de site";
|
|
|
93 |
$record->bodyhtml = $html;
|
|
|
94 |
|
|
|
95 |
$DB->insert_record('local_mf_notification', $record);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
if ($oldversion < 2024112700) {
|
|
|
100 |
$table = new xmldb_table('local_mf_modaccessnotif');
|
|
|
101 |
|
|
|
102 |
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
|
|
103 |
$table->add_field('moduleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
104 |
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
105 |
$table->add_field('notificationtime', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
106 |
$table->add_field('notificationnumber', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
|
|
107 |
|
|
|
108 |
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
|
|
109 |
|
|
|
110 |
// Créer la table si elle n'existe pas déjà.
|
|
|
111 |
if (!$dbman->table_exists($table)) {
|
|
|
112 |
$dbman->create_table($table);
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
upgrade_plugin_savepoint(true, 2024112700, 'local', 'moofactory_notification');
|
|
|
116 |
}
|
|
|
117 |
if ($oldversion < 2024112800) {
|
|
|
118 |
// Notifications par défaut.
|
|
|
119 |
// Notification de levee de restriction.
|
|
|
120 |
$record = $DB->get_record('local_mf_notification', array('type'=>'moduleaccess', 'base'=>1));
|
|
|
121 |
if(empty($record)){
|
|
|
122 |
$html = "{{firstname}} {{lastname}}<br><br>";
|
|
|
123 |
$html .= "Vous êtes inscrit à la formation « \"{{coursename}}\" » dans la plateforme {{lmsname}}.<br>";
|
|
|
124 |
$html .= "L'activité \"{{activityname}}\" est maintenant disponible.";
|
|
|
125 |
$record = new stdClass();
|
|
|
126 |
$record->base = 1;
|
|
|
127 |
$record->type = "moduleaccess";
|
|
|
128 |
$record->name = "Notification levée de restriction";
|
|
|
129 |
$record->subject = "Levée de restriction de l'acivité";
|
|
|
130 |
$record->bodyhtml = $html;
|
|
|
131 |
|
|
|
132 |
$DB->insert_record('local_mf_notification', $record);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
if ($oldversion < 2024122700) {
|
|
|
137 |
$table = new xmldb_table('local_mf_event_notifications');
|
|
|
138 |
|
|
|
139 |
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
|
|
140 |
$table->add_field('eventid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
141 |
$table->add_field('notificationtime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
142 |
$table->add_field('notified', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'Indicates if the event has been notified');
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
|
|
146 |
|
|
|
147 |
// Créer la table si elle n'existe pas déjà
|
|
|
148 |
if (!$dbman->table_exists($table)) {
|
|
|
149 |
$dbman->create_table($table);
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
// Sauvegarder le point de mise à jour pour cette version
|
|
|
153 |
upgrade_plugin_savepoint(true, 2024122700, 'local', 'moofactory_notification');
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
// Création des champs personnalisés de cours dans la catégorie 'Notifications'.
|
|
|
158 |
$categoryid = $DB->get_field('customfield_category', 'id', array('name' => get_string('notifications_category', 'local_moofactory_notification')));
|
|
|
159 |
|
|
|
160 |
if(empty($categoryid)){
|
|
|
161 |
$handler = core_course\customfield\course_handler::create();
|
|
|
162 |
$categoryid = $handler->create_category(get_string('notifications_category', 'local_moofactory_notification'));
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
// ********** Peut être utile ***********
|
|
|
166 |
//$handler->move_field(field_controller $field, int $categoryid, int $beforeid = 0)
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
if ($categoryid) {
|
|
|
170 |
$category = \core_customfield\category_controller::create($categoryid);
|
|
|
171 |
|
|
|
172 |
// Champ 'Inscriptions à ce cours'
|
|
|
173 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollments'));
|
|
|
174 |
if(empty($id)){
|
|
|
175 |
$type = "checkbox";
|
|
|
176 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
177 |
|
|
|
178 |
$handler = $field->get_handler();
|
|
|
179 |
if (!$handler->can_configure()) {
|
|
|
180 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
$data = new stdClass();
|
|
|
184 |
$data->name = get_string('courseenrollments', 'local_moofactory_notification');
|
|
|
185 |
$data->shortname = 'courseenrollments';
|
|
|
186 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
187 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
188 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
189 |
$data->categoryid = $categoryid;
|
|
|
190 |
$data->type = $type;
|
|
|
191 |
$data->id = 0;
|
|
|
192 |
|
|
|
193 |
$handler->save_field_configuration($field, $data);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
// Champ 'Delai'
|
|
|
197 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollmentstime'));
|
|
|
198 |
if(empty($id)){
|
|
|
199 |
$type = "text";
|
|
|
200 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
201 |
|
|
|
202 |
$handler = $field->get_handler();
|
|
|
203 |
if (!$handler->can_configure()) {
|
|
|
204 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
$data = new stdClass();
|
|
|
208 |
$data->name = get_string('courseenrollmentstime', 'local_moofactory_notification');
|
|
|
209 |
$data->shortname = 'courseenrollmentstime';
|
|
|
210 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 6, "ispassword" => "0", "link" => "", "locked" => "0", "visibility" => "2");
|
|
|
211 |
$data->description_editor = array("text" => get_string('courseenrollmentstime_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
|
|
|
212 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
213 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
214 |
$data->categoryid = $categoryid;
|
|
|
215 |
$data->type = $type;
|
|
|
216 |
$data->id = 0;
|
|
|
217 |
|
|
|
218 |
$handler->save_field_configuration($field, $data);
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
$beforeid = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccess'));
|
|
|
222 |
// Select choix de la notification
|
|
|
223 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollmentsnotification'));
|
|
|
224 |
if(empty($id)){
|
|
|
225 |
$type = "select";
|
|
|
226 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
227 |
|
|
|
228 |
$handler = $field->get_handler();
|
|
|
229 |
if (!$handler->can_configure()) {
|
|
|
230 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
$array = Array();
|
|
|
234 |
$records = $DB->get_records('local_mf_notification', array('type'=>'courseenroll'));
|
|
|
235 |
foreach($records as $record) {
|
|
|
236 |
$array[] = $record->name;
|
|
|
237 |
}
|
|
|
238 |
$options = implode("\n", $array);
|
|
|
239 |
$record = $DB->get_record('local_mf_notification', array('id'=>get_config('local_moofactory_notification', 'coursesenrollmentsnotification')));
|
|
|
240 |
$defaultvalue = $record->name;
|
|
|
241 |
|
|
|
242 |
$data = new stdClass();
|
|
|
243 |
$data->name = get_string('usednotification', 'local_moofactory_notification');
|
|
|
244 |
$data->shortname = 'courseenrollmentsnotification';
|
|
|
245 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
246 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
247 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
248 |
$data->categoryid = $categoryid;
|
|
|
249 |
$data->type = $type;
|
|
|
250 |
$data->id = 0;
|
|
|
251 |
|
|
|
252 |
$handler->save_field_configuration($field, $data);
|
|
|
253 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
//Delete champs 'courseaccessnotification2' && 'courseaccessrole2' && 'courseaccesscopie'
|
|
|
257 |
$idcourseaccessnotif2 = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccessnotification2'));
|
|
|
258 |
if($idcourseaccessnotif2){
|
|
|
259 |
$DB->delete_records('customfield_field', array('id' => $idcourseaccessnotif2));
|
|
|
260 |
}
|
|
|
261 |
$idcourseaccessrole2 = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccessrole2'));
|
|
|
262 |
if($idcourseaccessrole2){
|
|
|
263 |
$DB->delete_records('customfield_field', array('id' => $idcourseaccessrole2));
|
|
|
264 |
}
|
|
|
265 |
$copyfield = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccesscopie'));
|
|
|
266 |
if ($copyfield) {
|
|
|
267 |
$DB->delete_records('customfield_field', array('id' => $copyfield));
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
// Select choix de la notification 2
|
|
|
271 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollmentsnotification2'));
|
|
|
272 |
if(empty($id)){
|
|
|
273 |
$type = "select";
|
|
|
274 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
275 |
|
|
|
276 |
$handler = $field->get_handler();
|
|
|
277 |
if (!$handler->can_configure()) {
|
|
|
278 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
$array = Array();
|
|
|
282 |
$records = $DB->get_records('local_mf_notification', array('type'=>'courseenroll'));
|
|
|
283 |
foreach($records as $record) {
|
|
|
284 |
$array[] = $record->name;
|
|
|
285 |
}
|
|
|
286 |
$options = implode("\n", $array);
|
|
|
287 |
$record = $DB->get_record('local_mf_notification', array('id'=>get_config('local_moofactory_notification', 'coursesaccessnotification')));
|
|
|
288 |
$defaultvalue = $record->name;
|
|
|
289 |
|
|
|
290 |
$data = new stdClass();
|
|
|
291 |
$data->name = get_string('usednotification2', 'local_moofactory_notification');
|
|
|
292 |
$data->shortname = 'courseenrollmentsnotification2';
|
|
|
293 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
294 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
295 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
296 |
$data->categoryid = $categoryid;
|
|
|
297 |
$data->type = $type;
|
|
|
298 |
$data->id = 0;
|
|
|
299 |
|
|
|
300 |
$handler->save_field_configuration($field, $data);
|
|
|
301 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
//Select choix role notif 2
|
|
|
305 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollmentsrole'));
|
|
|
306 |
if(empty($id)){
|
|
|
307 |
$type = "select";
|
|
|
308 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
309 |
|
|
|
310 |
$handler = $field->get_handler();
|
|
|
311 |
if (!$handler->can_configure()) {
|
|
|
312 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
$roles = $DB->get_records('role', null, '', 'id, name, shortname');
|
|
|
316 |
$rolenames = role_fix_names($roles);
|
|
|
317 |
|
|
|
318 |
$array = [];
|
|
|
319 |
foreach ($roles as $role) {
|
|
|
320 |
$array[] = $rolenames[$role->id]->localname ;
|
|
|
321 |
}
|
|
|
322 |
$options = implode("\n", $array);
|
|
|
323 |
|
|
|
324 |
$data = new stdClass();
|
|
|
325 |
$data->name = get_string('selectrole2', 'local_moofactory_notification');
|
|
|
326 |
$data->shortname = 'courseenrollmentsrole';
|
|
|
327 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
328 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
329 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
330 |
$data->categoryid = $categoryid;
|
|
|
331 |
$data->type = $type;
|
|
|
332 |
$data->id = 0;
|
|
|
333 |
|
|
|
334 |
$handler->save_field_configuration($field, $data);
|
|
|
335 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
// Champ 'Non accès à ce cours'
|
|
|
339 |
$beforeid = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseevents'));
|
|
|
340 |
|
|
|
341 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccess'));
|
|
|
342 |
if(empty($id)){
|
|
|
343 |
$type = "checkbox";
|
|
|
344 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
345 |
|
|
|
346 |
$handler = $field->get_handler();
|
|
|
347 |
if (!$handler->can_configure()) {
|
|
|
348 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
$data = new stdClass();
|
|
|
352 |
$data->name = get_string('courseaccess', 'local_moofactory_notification');
|
|
|
353 |
$data->shortname = 'courseaccess';
|
|
|
354 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
355 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
356 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
357 |
$data->categoryid = $categoryid;
|
|
|
358 |
$data->type = $type;
|
|
|
359 |
$data->id = 0;
|
|
|
360 |
|
|
|
361 |
$handler->save_field_configuration($field, $data);
|
|
|
362 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
// Champ 'Depuis'
|
|
|
366 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccesstime'));
|
|
|
367 |
if(empty($id)){
|
|
|
368 |
$type = "text";
|
|
|
369 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
370 |
|
|
|
371 |
$handler = $field->get_handler();
|
|
|
372 |
if (!$handler->can_configure()) {
|
|
|
373 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
$data = new stdClass();
|
|
|
377 |
$data->name = get_string('courseaccesstime', 'local_moofactory_notification');
|
|
|
378 |
$data->shortname = 'courseaccesstime';
|
|
|
379 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 6, "ispassword" => "0", "link" => "", "locked" => "0", "visibility" => "2");
|
|
|
380 |
$data->description_editor = array("text" => get_string('courseaccesstime_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
|
|
|
381 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
382 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
383 |
$data->categoryid = $categoryid;
|
|
|
384 |
$data->type = $type;
|
|
|
385 |
$data->id = 0;
|
|
|
386 |
|
|
|
387 |
$handler->save_field_configuration($field, $data);
|
|
|
388 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
// Select choix de la notification
|
|
|
392 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseaccessnotification'));
|
|
|
393 |
if(empty($id)){
|
|
|
394 |
$type = "select";
|
|
|
395 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
396 |
|
|
|
397 |
$handler = $field->get_handler();
|
|
|
398 |
if (!$handler->can_configure()) {
|
|
|
399 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
$array = Array();
|
|
|
403 |
$records = $DB->get_records('local_mf_notification', array('type'=>'courseaccess'));
|
|
|
404 |
foreach($records as $record) {
|
|
|
405 |
$array[] = $record->name;
|
|
|
406 |
}
|
|
|
407 |
$options = implode("\n", $array);
|
|
|
408 |
$record = $DB->get_record('local_mf_notification', array('id'=>get_config('local_moofactory_notification', 'coursesaccessnotification')));
|
|
|
409 |
$defaultvalue = $record->name;
|
|
|
410 |
|
|
|
411 |
$data = new stdClass();
|
|
|
412 |
$data->name = get_string('usednotification', 'local_moofactory_notification');
|
|
|
413 |
$data->shortname = 'courseaccessnotification';
|
|
|
414 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
415 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
416 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
417 |
$data->categoryid = $categoryid;
|
|
|
418 |
$data->type = $type;
|
|
|
419 |
$data->id = 0;
|
|
|
420 |
|
|
|
421 |
$handler->save_field_configuration($field, $data);
|
|
|
422 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
423 |
}
|
|
|
424 |
|
|
|
425 |
if ($oldversion<2025013100) {// Mise à jour des options
|
|
|
426 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseenrollmentsrole'));
|
|
|
427 |
if($id){
|
|
|
428 |
$field = $DB->get_record('customfield_field', array('shortname' => 'courseenrollmentsrole'));
|
|
|
429 |
$configdata = json_decode($field->configdata, true);
|
|
|
430 |
|
|
|
431 |
$roles = $DB->get_records('role', null, '', 'id, name, shortname');
|
|
|
432 |
$rolenames = role_fix_names($roles);
|
|
|
433 |
$new_options = implode("\n", array_column($rolenames, 'localname'));
|
|
|
434 |
|
|
|
435 |
if ($configdata['options'] !== $new_options) {
|
|
|
436 |
$configdata['options'] = $new_options;
|
|
|
437 |
$field->configdata = json_encode($configdata);
|
|
|
438 |
$DB->update_record('customfield_field', $field);
|
|
|
439 |
}
|
|
|
440 |
upgrade_plugin_savepoint(true, 2025013100, 'local', 'moofactory_notification');
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
// Champ 'Evènements liés à ce cours'
|
|
|
445 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseevents'));
|
|
|
446 |
if(empty($id)){
|
|
|
447 |
$type = "checkbox";
|
|
|
448 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
449 |
|
|
|
450 |
$handler = $field->get_handler();
|
|
|
451 |
if (!$handler->can_configure()) {
|
|
|
452 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
$data = new stdClass();
|
|
|
456 |
$data->name = get_string('courseevents', 'local_moofactory_notification');
|
|
|
457 |
$data->shortname = 'courseevents';
|
|
|
458 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
459 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
460 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
461 |
$data->categoryid = $categoryid;
|
|
|
462 |
$data->type = $type;
|
|
|
463 |
$data->id = 0;
|
|
|
464 |
|
|
|
465 |
$handler->save_field_configuration($field, $data);
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
// Champ 'Tenir compte des restrictions d'accès aux activités'
|
|
|
469 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseeventscheckavailability'));
|
|
|
470 |
if(empty($id)){
|
|
|
471 |
$type = "checkbox";
|
|
|
472 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
473 |
|
|
|
474 |
$handler = $field->get_handler();
|
|
|
475 |
if (!$handler->can_configure()) {
|
|
|
476 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
$data = new stdClass();
|
|
|
480 |
$data->name = get_string('courseeventscheckavailability', 'local_moofactory_notification');
|
|
|
481 |
$data->shortname = 'courseeventscheckavailability';
|
|
|
482 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
483 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
484 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
485 |
$data->categoryid = $categoryid;
|
|
|
486 |
$data->type = $type;
|
|
|
487 |
$data->id = 0;
|
|
|
488 |
|
|
|
489 |
$handler->save_field_configuration($field, $data);
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
// Champ 'Ne pas tenir compte des restrictions de type "date"'
|
|
|
493 |
$beforeid = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseeventsnotification'));
|
|
|
494 |
|
|
|
495 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseeventscheckdateavailability'));
|
|
|
496 |
if(empty($id)){
|
|
|
497 |
$type = "checkbox";
|
|
|
498 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
499 |
|
|
|
500 |
$handler = $field->get_handler();
|
|
|
501 |
if (!$handler->can_configure()) {
|
|
|
502 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
$data = new stdClass();
|
|
|
506 |
$data->name = get_string('courseeventscheckdateavailability', 'local_moofactory_notification');
|
|
|
507 |
$data->shortname = 'courseeventscheckdateavailability';
|
|
|
508 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
509 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
510 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
511 |
$data->categoryid = $categoryid;
|
|
|
512 |
$data->type = $type;
|
|
|
513 |
$data->id = 0;
|
|
|
514 |
|
|
|
515 |
$handler->save_field_configuration($field, $data);
|
|
|
516 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
// Champ 'Ne pas tenir compte des restrictions de type "groupe"'
|
|
|
520 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseeventscheckgroupavailability'));
|
|
|
521 |
if(empty($id)){
|
|
|
522 |
$type = "checkbox";
|
|
|
523 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
524 |
|
|
|
525 |
$handler = $field->get_handler();
|
|
|
526 |
if (!$handler->can_configure()) {
|
|
|
527 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
$data = new stdClass();
|
|
|
531 |
$data->name = get_string('courseeventscheckgroupavailability', 'local_moofactory_notification');
|
|
|
532 |
$data->shortname = 'courseeventscheckgroupavailability';
|
|
|
533 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
534 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
535 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
536 |
$data->categoryid = $categoryid;
|
|
|
537 |
$data->type = $type;
|
|
|
538 |
$data->id = 0;
|
|
|
539 |
|
|
|
540 |
$handler->save_field_configuration($field, $data);
|
|
|
541 |
$handler->move_field($field, $categoryid, $beforeid);
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
// Select choix de la notification
|
|
|
545 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => 'courseeventsnotification'));
|
|
|
546 |
if(empty($id)){
|
|
|
547 |
$type = "select";
|
|
|
548 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
549 |
|
|
|
550 |
$handler = $field->get_handler();
|
|
|
551 |
if (!$handler->can_configure()) {
|
|
|
552 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
$array = Array();
|
|
|
556 |
$records = $DB->get_records('local_mf_notification', array('type'=>'courseevent'));
|
|
|
557 |
foreach($records as $record) {
|
|
|
558 |
$array[] = $record->name;
|
|
|
559 |
}
|
|
|
560 |
$options = implode("\n", $array);
|
|
|
561 |
$record = $DB->get_record('local_mf_notification', array('id'=>get_config('local_moofactory_notification', 'courseseventsnotification')));
|
|
|
562 |
$defaultvalue = $record->name;
|
|
|
563 |
|
|
|
564 |
$data = new stdClass();
|
|
|
565 |
$data->name = get_string('usednotification', 'local_moofactory_notification');
|
|
|
566 |
$data->shortname = 'courseeventsnotification';
|
|
|
567 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0", "locked" => "0", "visibility" => "2");
|
|
|
568 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
569 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
570 |
$data->categoryid = $categoryid;
|
|
|
571 |
$data->type = $type;
|
|
|
572 |
$data->id = 0;
|
|
|
573 |
|
|
|
574 |
$handler->save_field_configuration($field, $data);
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
// Champs rappels
|
|
|
578 |
$configvars = ['daysbeforeevents1', 'hoursbeforeevents1', 'daysbeforeevents2', 'hoursbeforeevents2', 'daysbeforeevents3', 'hoursbeforeevents3'];
|
|
|
579 |
foreach($configvars as $configvar){
|
|
|
580 |
$name = $configvar;
|
|
|
581 |
$id = $DB->get_field('customfield_field', 'id', array('shortname' => $name));
|
|
|
582 |
if(empty($id)){
|
|
|
583 |
$type = "text";
|
|
|
584 |
$field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
|
|
|
585 |
|
|
|
586 |
$handler = $field->get_handler();
|
|
|
587 |
if (!$handler->can_configure()) {
|
|
|
588 |
print_error('nopermissionconfigure', 'core_customfield');
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
$data = new stdClass();
|
|
|
592 |
$data->name = get_string($name, 'local_moofactory_notification');
|
|
|
593 |
$data->shortname = $name;
|
|
|
594 |
$data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 3, "ispassword" => "0", "link" => "", "locked" => "0", "visibility" => "2");
|
|
|
595 |
$data->description_editor = array("text" => get_string($name.'_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
|
|
|
596 |
$data->mform_isexpanded_id_header_specificsettings = 1;
|
|
|
597 |
$data->mform_isexpanded_id_course_handler_header = 1;
|
|
|
598 |
$data->categoryid = $categoryid;
|
|
|
599 |
$data->type = $type;
|
|
|
600 |
$data->id = 0;
|
|
|
601 |
|
|
|
602 |
$handler->save_field_configuration($field, $data);
|
|
|
603 |
}
|
|
|
604 |
}
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
return true;
|
|
|
608 |
}
|