Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Installation code 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
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
function xmldb_local_moofactory_notification_install()
29
{
30
    global $DB;
31
 
32
    // Notifications par défaut.
33
    // Inscriptionx aux cours.
34
    $html = "{{firstname}} {{lastname}}<br><br>";
35
    $html .= "Vous êtes inscrit à la formation « {{coursename}} » dans la plateforme {{lmsname}}.<br>";
36
    $html .= "Pour vous connecter : <a href=\"{{lmsurl}}\"\>{{lmsurl}}</a><br><br>";
37
    $html .= "Votre identifiant : {{username}}";
38
 
39
    $record = new stdClass();
40
    $record->base = 1;
41
    $record->type = "courseenroll";
42
    $record->name = "Inscription par défaut";
43
    $record->subject = "Inscription à un cours";
44
    $record->bodyhtml = $html;
45
 
46
    $DB->insert_record('local_mf_notification', $record);
47
 
48
    // Non accès aux cours.
49
    $html = "{{firstname}} {{lastname}}<br><br>";
50
    $html .= "Vous êtes inscrit à la formation « \"<a href=\"{{courseurl}}\"\>{{coursename}}</a>\" » dans la plateforme {{lmsname}}.<br>";
51
    $html .= "Vous n’êtes pas venu dans ce cours depuis au moins {{interval}}. Rencontrez vous un problème ?<br>";
52
    $html .= "Nous vous invitons à vous reconnecter et à suivre votre formation.";
53
 
54
    $record = new stdClass();
55
    $record->base = 1;
56
    $record->type = "courseaccess";
57
    $record->name = "Non accès aux cours par défaut";
58
    $record->subject = "Non accès à un cours";
59
    $record->bodyhtml = $html;
60
 
61
    $DB->insert_record('local_mf_notification', $record);
62
 
63
    // Evènement de site.
64
    $html = "{{firstname}} {{lastname}}<br><br>";
65
    $html .= "Le {{eventdate}}, {{eventname}} sur la plateforme « <a href=\"{{lmsurl}}\"\>{{lmsname}}</a> », n’oubliez pas d’inscrire cet évènement dans votre calendrier.";
66
 
67
    $record = new stdClass();
68
    $record->base = 1;
69
    $record->type = "siteevent";
70
    $record->name = "Evènement de site par défaut";
71
    $record->subject = "Rappel d'évènement de site";
72
    $record->bodyhtml = $html;
73
 
74
    $DB->insert_record('local_mf_notification', $record);
75
 
76
    // Evènement de cours.
77
    $html = "{{firstname}} {{lastname}}<br><br>";
78
    $html .= "Le {{eventdate}}, un(e) {{eventname}} dans le cours « \"<a href=\"{{courseurl}}\"\>{{coursename}}</a>\" », n’oubliez pas de l’inscrire dans votre calendrier.<br><br>";
79
    $html .= "Nous comptons sur vous pour respecter cette échéance.";
80
 
81
    $record = new stdClass();
82
    $record->base = 1;
83
    $record->type = "courseevent";
84
    $record->name = "Evènement de cours par défaut";
85
    $record->subject = "Rappel d'évènement de cours";
86
    $record->bodyhtml = $html;
87
 
88
    $DB->insert_record('local_mf_notification', $record);
89
 
90
    $html = "{{firstname}} {{lastname}}<br><br>";
91
    $html .= "Vous êtes inscrit à la formation « \"{{coursename}}\" » dans la plateforme {{lmsname}}.<br>";
92
    $html .= "L'activité \"{{activityname}}\" est maintenant disponible.";
93
    $record = new stdClass();
94
    $record->base = 1;
95
    $record->type = "moduleaccess";
96
    $record->name = "Notification levée de restriction";
97
    $record->subject = "Levée de restriction de l'acivité";
98
    $record->bodyhtml = $html;
99
 
100
    $DB->insert_record('local_mf_notification', $record);
101
 
102
 
103
    // Création des champs personnalisés de cours dans la catégorie 'Notifications'.
104
    require_login();
105
 
106
    $handler = core_course\customfield\course_handler::create();
107
    $categoryid = $handler->create_category(get_string('notifications_category', 'local_moofactory_notification'));
108
 
109
    if ($categoryid) {
110
        $category = \core_customfield\category_controller::create($categoryid);
111
 
112
        // Champ 'Inscriptions à ce cours'
113
        $type = "checkbox";
114
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
115
        $handler = $field->get_handler();
116
        if (!$handler->can_configure()) {
117
            print_error('nopermissionconfigure', 'core_customfield');
118
        }
119
 
120
        $data = new stdClass();
121
        $data->name = get_string('courseenrollments', 'local_moofactory_notification');
122
        $data->shortname = 'courseenrollments';
123
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
124
        $data->mform_isexpanded_id_header_specificsettings = 1;
125
        $data->mform_isexpanded_id_course_handler_header = 1;
126
        $data->categoryid = $categoryid;
127
        $data->type = $type;
128
        $data->id = 0;
129
 
130
        $handler->save_field_configuration($field, $data);
131
 
132
        // Champ 'Delai'
133
        $type = "text";
134
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
135
 
136
        $handler = $field->get_handler();
137
        if (!$handler->can_configure()) {
138
            print_error('nopermissionconfigure', 'core_customfield');
139
        }
140
 
141
        $data = new stdClass();
142
        $data->name = get_string('courseenrollmentstime', 'local_moofactory_notification');
143
        $data->shortname = 'courseenrollmentstime';
144
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 6, "ispassword" => "0", "link" => "",  "locked" => "0",  "visibility" => "2");
145
        $data->description_editor = array("text" => get_string('courseenrollmentstime_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
146
        $data->mform_isexpanded_id_header_specificsettings = 1;
147
        $data->mform_isexpanded_id_course_handler_header = 1;
148
        $data->categoryid = $categoryid;
149
        $data->type = $type;
150
        $data->id = 0;
151
 
152
        $handler->save_field_configuration($field, $data);
153
 
154
        // Select choix de la notification
155
        $type = "select";
156
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
157
 
158
        $handler = $field->get_handler();
159
        if (!$handler->can_configure()) {
160
            print_error('nopermissionconfigure', 'core_customfield');
161
        }
162
 
163
        $array = array();
164
        $records = $DB->get_records('local_mf_notification', array('type' => 'courseenroll'));
165
        foreach ($records as $record) {
166
            $array[] = $record->name;
167
        }
168
        $options = implode("\n", $array);
169
        $record = $DB->get_record('local_mf_notification', array('id' => get_config('local_moofactory_notification', 'coursesenrollmentsnotification')));
170
        $defaultvaluenotif = $record->name;
171
 
172
        $data = new stdClass();
173
        $data->name = get_string('usednotification', 'local_moofactory_notification');
174
        $data->shortname = 'courseenrollmentsnotification';
175
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvaluenotif, "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
176
        $data->mform_isexpanded_id_header_specificsettings = 1;
177
        $data->mform_isexpanded_id_course_handler_header = 1;
178
        $data->categoryid = $categoryid;
179
        $data->type = $type;
180
        $data->id = 0;
181
 
182
         // Select choix de la notification 2
183
 
184
         $type = "select";
185
         $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
186
 
187
         $handler = $field->get_handler();
188
         if (!$handler->can_configure()) {
189
             print_error('nopermissionconfigure', 'core_customfield');
190
         }
191
 
192
         $array = array();
193
         $records = $DB->get_records('local_mf_notification', array('type' => 'courseenroll'));
194
         foreach ($records as $record) {
195
             $array[] = $record->name;
196
         }
197
         $options = implode("\n", $array);
198
 
199
         $data = new stdClass();
200
         $data->name = get_string('usednotification2', 'local_moofactory_notification');
201
         $data->shortname = 'courseenrollmentsnotification2';
202
         $data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvaluenotif, "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
203
         $data->mform_isexpanded_id_header_specificsettings = 1;
204
         $data->mform_isexpanded_id_course_handler_header = 1;
205
         $data->categoryid = $categoryid;
206
         $data->type = $type;
207
         $data->id = 0;
208
 
209
         $handler->save_field_configuration($field, $data);
210
 
211
         //Select choix role notif 2
212
 
213
         $type = "select";
214
         $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
215
 
216
         $handler = $field->get_handler();
217
         if (!$handler->can_configure()) {
218
             print_error('nopermissionconfigure', 'core_customfield');
219
         }
220
 
221
         $roles = $DB->get_records('role', null, '', 'id, shortname');
222
         $rolenames = role_fix_names($roles);
223
 
224
         $array = [];
225
         foreach ($roles as $role) {
226
             $array[] = $rolenames[$role->id]->localname ;
227
         }
228
         $options = implode("\n", $array);
229
 
230
         $data = new stdClass();
231
         $data->name = get_string('selectrole2', 'local_moofactory_notification');
232
         $data->shortname = 'courseenrollmentsrole';
233
         $data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
234
         $data->mform_isexpanded_id_header_specificsettings = 1;
235
         $data->mform_isexpanded_id_course_handler_header = 1;
236
         $data->categoryid = $categoryid;
237
         $data->type = $type;
238
         $data->id = 0;
239
 
240
        $handler->save_field_configuration($field, $data);
241
 
242
        // Champ 'Non accès à ce cours'
243
        $type = "checkbox";
244
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
245
 
246
        $handler = $field->get_handler();
247
        if (!$handler->can_configure()) {
248
            print_error('nopermissionconfigure', 'core_customfield');
249
        }
250
 
251
        $data = new stdClass();
252
        $data->name = get_string('courseaccess', 'local_moofactory_notification');
253
        $data->shortname = 'courseaccess';
254
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
255
        $data->mform_isexpanded_id_header_specificsettings = 1;
256
        $data->mform_isexpanded_id_course_handler_header = 1;
257
        $data->categoryid = $categoryid;
258
        $data->type = $type;
259
        $data->id = 0;
260
 
261
        $handler->save_field_configuration($field, $data);
262
 
263
        // Champ 'Depuis'
264
        $type = "text";
265
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
266
 
267
        $handler = $field->get_handler();
268
        if (!$handler->can_configure()) {
269
            print_error('nopermissionconfigure', 'core_customfield');
270
        }
271
 
272
        $data = new stdClass();
273
        $data->name = get_string('courseaccesstime', 'local_moofactory_notification');
274
        $data->shortname = 'courseaccesstime';
275
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 6, "ispassword" => "0", "link" => "",  "locked" => "0",  "visibility" => "2");
276
        $data->description_editor = array("text" => get_string('courseaccesstime_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
277
        $data->mform_isexpanded_id_header_specificsettings = 1;
278
        $data->mform_isexpanded_id_course_handler_header = 1;
279
        $data->categoryid = $categoryid;
280
        $data->type = $type;
281
        $data->id = 0;
282
 
283
        $handler->save_field_configuration($field, $data);
284
 
285
        // Select choix de la notification
286
 
287
        $type = "select";
288
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
289
 
290
        $handler = $field->get_handler();
291
        if (!$handler->can_configure()) {
292
            print_error('nopermissionconfigure', 'core_customfield');
293
        }
294
 
295
        $array = array();
296
        $records = $DB->get_records('local_mf_notification', array('type' => 'courseaccess'));
297
        foreach ($records as $record) {
298
            $array[] = $record->name;
299
        }
300
        $options = implode("\n", $array);
301
        $record = $DB->get_record('local_mf_notification', array('id' => get_config('local_moofactory_notification', 'coursesaccessnotification')));
302
        $defaultvalue = $record->name;
303
 
304
        $data = new stdClass();
305
        $data->name = get_string('usednotification', 'local_moofactory_notification');
306
        $data->shortname = 'courseaccessnotification';
307
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
308
        $data->mform_isexpanded_id_header_specificsettings = 1;
309
        $data->mform_isexpanded_id_course_handler_header = 1;
310
        $data->categoryid = $categoryid;
311
        $data->type = $type;
312
        $data->id = 0;
313
 
314
        $handler->save_field_configuration($field, $data);
315
 
316
        $handler->save_field_configuration($field, $data);
317
 
318
        // Champ 'Copie à'
319
 
320
        $type = "text";
321
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
322
 
323
        $handler = $field->get_handler();
324
        if (!$handler->can_configure()) {
325
            print_error('nopermissionconfigure', 'core_customfield');
326
        }
327
 
328
        $data = new stdClass();
329
        $data->name = get_string('copienotif', 'local_moofactory_notification');
330
        $data->shortname = 'courseaccesscopie';
331
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "maxlength" => 255, "locked" => "0",  "visibility" => "2");
332
        $data->mform_isexpanded_id_header_specificsettings = 1;
333
        $data->mform_isexpanded_id_course_handler_header = 1;
334
        $data->categoryid = $categoryid;
335
        $data->type = $type;
336
        $data->id = 0;
337
 
338
        $handler->save_field_configuration($field, $data);
339
 
340
        // Champ 'Evènements liés à ce cours'
341
        $type = "checkbox";
342
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
343
        $handler = $field->get_handler();
344
        if (!$handler->can_configure()) {
345
            print_error('nopermissionconfigure', 'core_customfield');
346
        }
347
 
348
        $data = new stdClass();
349
        $data->name = get_string('courseevents', 'local_moofactory_notification');
350
        $data->shortname = 'courseevents';
351
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
352
        $data->mform_isexpanded_id_header_specificsettings = 1;
353
        $data->mform_isexpanded_id_course_handler_header = 1;
354
        $data->categoryid = $categoryid;
355
        $data->type = $type;
356
        $data->id = 0;
357
 
358
        $handler->save_field_configuration($field, $data);
359
 
360
        // Champ 'Tenir compte des restrictions d'accès aux activités'
361
        $type = "checkbox";
362
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
363
 
364
        $handler = $field->get_handler();
365
        if (!$handler->can_configure()) {
366
            print_error('nopermissionconfigure', 'core_customfield');
367
        }
368
 
369
        $data = new stdClass();
370
        $data->name = get_string('courseeventscheckavailability', 'local_moofactory_notification');
371
        $data->shortname = 'courseeventscheckavailability';
372
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
373
        $data->mform_isexpanded_id_header_specificsettings = 1;
374
        $data->mform_isexpanded_id_course_handler_header = 1;
375
        $data->categoryid = $categoryid;
376
        $data->type = $type;
377
        $data->id = 0;
378
 
379
        $handler->save_field_configuration($field, $data);
380
 
381
        // Champ 'Ne pas tenir compte des restrictions de type "date"'
382
        $type = "checkbox";
383
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
384
 
385
        $handler = $field->get_handler();
386
        if (!$handler->can_configure()) {
387
            print_error('nopermissionconfigure', 'core_customfield');
388
        }
389
 
390
        $data = new stdClass();
391
        $data->name = get_string('courseeventscheckdateavailability', 'local_moofactory_notification');
392
        $data->shortname = 'courseeventscheckdateavailability';
393
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
394
        $data->mform_isexpanded_id_header_specificsettings = 1;
395
        $data->mform_isexpanded_id_course_handler_header = 1;
396
        $data->categoryid = $categoryid;
397
        $data->type = $type;
398
        $data->id = 0;
399
 
400
        $handler->save_field_configuration($field, $data);
401
 
402
        // Champ 'Ne pas tenir compte des restrictions de type "groupe"'
403
        $type = "checkbox";
404
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
405
 
406
        $handler = $field->get_handler();
407
        if (!$handler->can_configure()) {
408
            print_error('nopermissionconfigure', 'core_customfield');
409
        }
410
 
411
        $data = new stdClass();
412
        $data->name = get_string('courseeventscheckgroupavailability', 'local_moofactory_notification');
413
        $data->shortname = 'courseeventscheckgroupavailability';
414
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "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
 
423
        // Select choix de la notification
424
        $type = "select";
425
        $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
426
 
427
        $handler = $field->get_handler();
428
        if (!$handler->can_configure()) {
429
            print_error('nopermissionconfigure', 'core_customfield');
430
        }
431
 
432
        $array = array();
433
        $records = $DB->get_records('local_mf_notification', array('type' => 'courseevent'));
434
        foreach ($records as $record) {
435
            $array[] = $record->name;
436
        }
437
        $options = implode("\n", $array);
438
        $record = $DB->get_record('local_mf_notification', array('id' => get_config('local_moofactory_notification', 'courseseventsnotification')));
439
        $defaultvalue = $record->name;
440
 
441
        $data = new stdClass();
442
        $data->name = get_string('usednotification', 'local_moofactory_notification');
443
        $data->shortname = 'courseeventsnotification';
444
        $data->configdata = array("required" => "0", "uniquevalues" => "0", "options" => $options, "defaultvalue" => $defaultvalue, "checkbydefault" => "0",  "locked" => "0",  "visibility" => "2");
445
        $data->mform_isexpanded_id_header_specificsettings = 1;
446
        $data->mform_isexpanded_id_course_handler_header = 1;
447
        $data->categoryid = $categoryid;
448
        $data->type = $type;
449
        $data->id = 0;
450
 
451
        $handler->save_field_configuration($field, $data);
452
 
453
        // Champs rappels
454
        $configvars = ['daysbeforeevents1', 'hoursbeforeevents1', 'daysbeforeevents2', 'hoursbeforeevents2', 'daysbeforeevents3', 'hoursbeforeevents3'];
455
        foreach ($configvars as $configvar) {
456
            $name = $configvar;
457
            $type = "text";
458
            $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
459
 
460
            $handler = $field->get_handler();
461
            if (!$handler->can_configure()) {
462
                print_error('nopermissionconfigure', 'core_customfield');
463
            }
464
 
465
            $data = new stdClass();
466
            $data->name = get_string($name, 'local_moofactory_notification');
467
            $data->shortname = $name;
468
            $data->configdata = array("required" => "0", "uniquevalues" => "0", "defaultvalue" => "", "displaysize" => 3, "maxlength" => 3, "ispassword" => "0", "link" => "",  "locked" => "0",  "visibility" => "2");
469
            $data->description_editor = array("text" => get_string($name . '_desc', 'local_moofactory_notification'), "format" => "1", "itemid" => 123);
470
            $data->mform_isexpanded_id_header_specificsettings = 1;
471
            $data->mform_isexpanded_id_course_handler_header = 1;
472
            $data->categoryid = $categoryid;
473
            $data->type = $type;
474
            $data->id = 0;
475
 
476
            $handler->save_field_configuration($field, $data);
477
        }
478
    }
479
 
480
    return true;
481
}