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 |
* Delete notification form.
|
|
|
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 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
28 |
|
|
|
29 |
class deletenotif_form extends moodleform {
|
|
|
30 |
public function definition() {
|
|
|
31 |
global $CFG, $DB;
|
|
|
32 |
|
|
|
33 |
$pluginalert = false;
|
|
|
34 |
$coursealert = false;
|
|
|
35 |
$courseslist = array();
|
|
|
36 |
$activitiesalert = false;
|
|
|
37 |
$activitieslist = array();
|
|
|
38 |
|
|
|
39 |
$mform = $this->_form;
|
|
|
40 |
$id = $this->_customdata['id'];
|
|
|
41 |
|
|
|
42 |
$mform->addElement('hidden', 'id', $id);
|
|
|
43 |
$mform->setType('id', PARAM_RAW);
|
|
|
44 |
|
|
|
45 |
// On recherche la notif définie au niveau des paramètres du plugin correspondant au type de la notif supprimée.
|
|
|
46 |
$record = $DB->get_record('local_mf_notification', array('id'=>$id));
|
|
|
47 |
$type = $record->type;
|
|
|
48 |
switch($type){
|
|
|
49 |
case "courseenroll":
|
|
|
50 |
$notifvalue = get_config('local_moofactory_notification', 'coursesenrollmentsnotification');
|
|
|
51 |
$customfieldname = 'courseenrollmentsnotification';
|
|
|
52 |
break;
|
|
|
53 |
case "courseaccess":
|
|
|
54 |
$notifvalue = get_config('local_moofactory_notification', 'coursesaccessnotification');
|
|
|
55 |
$customfieldname = 'courseaccessnotification';
|
|
|
56 |
break;
|
|
|
57 |
case "courseevent":
|
|
|
58 |
$notifvalue = get_config('local_moofactory_notification', 'courseseventsnotification');
|
|
|
59 |
$customfieldname = 'courseeventsnotification';
|
|
|
60 |
break;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Si la notif du plugin est celle qui est supprimée, il faut afficher une alerte.
|
|
|
64 |
if($notifvalue == $id){
|
|
|
65 |
$pluginalert = true;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
// Notification supprimée.
|
|
|
69 |
$records = $DB->get_records('local_mf_notification', array('type'=>$type), 'base DESC, name ASC');
|
|
|
70 |
$index = 0;
|
|
|
71 |
foreach($records as $record) {
|
|
|
72 |
$index++;
|
|
|
73 |
if($record->id == $id){
|
|
|
74 |
$deletednotif = $index;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// Pour tous les cours.
|
|
|
79 |
$sql = "SELECT id, fullname FROM {course} WHERE id <> 1";
|
|
|
80 |
$courses = $DB->get_records_sql($sql, array());
|
|
|
81 |
foreach ($courses as $course) {
|
|
|
82 |
$courseid = $course->id;
|
|
|
83 |
$coursenotif = (int)local_moofactory_notification_getCustomfield($courseid, $customfieldname, 'select');
|
|
|
84 |
|
|
|
85 |
// Si la notif du cours est celle qui est supprimée, il faut afficher une alerte.
|
|
|
86 |
if($coursenotif == $deletednotif){
|
|
|
87 |
$coursealert = true;
|
|
|
88 |
$courseslist[] = $course->fullname;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// Pour les activités.
|
|
|
92 |
$activities = local_moofactory_notification_get_all_activities($courseid);
|
|
|
93 |
|
|
|
94 |
foreach($activities as $activity){
|
|
|
95 |
$moduleid = $activity["id"];
|
|
|
96 |
$name = 'modulenotification_'.$courseid.'_'.$moduleid;
|
|
|
97 |
$notifid = get_config('local_moofactory_notification', $name);
|
|
|
98 |
|
|
|
99 |
// Si la notif de l'activité est celle qui est supprimée, il faut afficher une alerte.
|
|
|
100 |
if($id == $notifid){
|
|
|
101 |
$activitiesalert = true;
|
|
|
102 |
$activitieslist[] = $activity["name"] . " (" . $course->fullname . ")";
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
$name = $DB->get_field('local_mf_notification', 'name', array('id' => $id));
|
|
|
108 |
|
|
|
109 |
$mform->addElement('html', '<fieldset class="clearfix">');
|
|
|
110 |
if($pluginalert){
|
|
|
111 |
$mform->addElement('html', '<h6 style="margin-top:20px;color:var(--danger);">'.get_string('deleteplugin', 'local_moofactory_notification').'</h6>');
|
|
|
112 |
}
|
|
|
113 |
if($coursealert){
|
|
|
114 |
if(count($courseslist) > 1){
|
|
|
115 |
$mform->addElement('html', '<h6 style="margin-top:20px;color:var(--danger);">'.get_string('deletecourses', 'local_moofactory_notification').'</h6>');
|
|
|
116 |
foreach($courseslist as $item){
|
|
|
117 |
$mform->addElement('html', '<h6 style="margin-left:20px;color:var(--danger);">• '.$item.'</h6>');
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
else{
|
|
|
121 |
$mform->addElement('html', '<h6 style="margin-top:20px;color:var(--danger);">'.get_string('deletecourse', 'local_moofactory_notification').' « '.$courseslist[0].' ».</h6>');
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
if($activitiesalert){
|
|
|
125 |
if(count($activitieslist) > 1){
|
|
|
126 |
$mform->addElement('html', '<h6 style="margin-top:20px;color:var(--danger);">'.get_string('deleteactivities', 'local_moofactory_notification').'</h6>');
|
|
|
127 |
foreach($activitieslist as $item){
|
|
|
128 |
$mform->addElement('html', '<h6 style="margin-left:20px;color:var(--danger);">• '.$item.'</h6>');
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
else{
|
|
|
132 |
$mform->addElement('html', '<h6 style="margin-top:20px;color:var(--danger);">'.get_string('deleteactivity', 'local_moofactory_notification').' « '.$activitieslist[0].' ».</h6>');
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
$mform->addElement('html', '<h5 style="margin-top:20px">'.get_string('deleteconfirm', 'local_moofactory_notification', '« '.$name.' »').'</h5>');
|
|
|
136 |
$mform->addElement('html', '</fieldset>');
|
|
|
137 |
|
|
|
138 |
$this->add_action_buttons();
|
|
|
139 |
}
|
|
|
140 |
}
|