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
 * local_moofactory_notification 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
require_once($CFG->libdir.'/formslib.php');
28
 
29
class managenotif_form extends moodleform {
30
    public function definition() {
31
        global $CFG, $DB, $OUTPUT;
32
 
33
        $mform = $this->_form;
34
 
35
        // Select des notifications.
36
        $records = $DB->get_records('local_mf_notification', null, 'base DESC, name ASC');
37
        $options[0] = get_string('choose', 'local_moofactory_notification');
38
        foreach($records as $recordchoice) {
39
            $options[$recordchoice->id] = $recordchoice->name;
40
        }
41
        $selectnotifications = $mform->addElement('select', 'selectnotifications', get_string('notifications', 'local_moofactory_notification'), $options, array('onchange' => 'javascript:document.getElementById(\'notificationsform\').submit();'));
42
 
43
        $addurl = new moodle_url($CFG->wwwroot . '/local/moofactory_notification/addnotif.php');
44
        $html = '<div class="form-group row"><div class="col-md-3">&nbsp;</div>';
45
 
46
        if(!empty($this->_customdata)){
47
            $selectnotifications->setSelected($this->_customdata['id']);
48
 
49
            $record = $DB->get_record('local_mf_notification', array('id' => $this->_customdata['id']), 'base, type, name, subject, bodyhtml');
50
 
51
            $duplicateurl = new moodle_url($CFG->wwwroot . '/local/moofactory_notification/duplicatenotif.php', array('id' => $this->_customdata['id']));
52
            $deleteurl = new moodle_url($CFG->wwwroot . '/local/moofactory_notification/deletenotif.php', array('id' => $this->_customdata['id']));
53
            if(empty($record->base)){
54
                $html .= '<div class="col-md-2"><a href="'.$duplicateurl.'">';
55
                $html .= $OUTPUT->pix_icon('t/copy', '');
56
                $html .= get_string('duplicate', 'local_moofactory_notification').'</a></div>';
57
                $html .= '<div class="col-md-2"><a href="'.$deleteurl.'">';
58
                $html .= $OUTPUT->pix_icon('t/delete', '');
59
                $html .= get_string('delete', 'local_moofactory_notification').'</a></div>';
60
                $html .= '<div class="col-md-5"><a href="'.$addurl.'">';
61
                $html .= $OUTPUT->pix_icon('i/addblock', '');
62
                $html .= get_string('add', 'local_moofactory_notification').'</a></div>';
63
            }
64
            else{
65
                $html .= '<div class="col-md-2"><a href="'.$duplicateurl.'">';
66
                $html .= $OUTPUT->pix_icon('t/copy', '');
67
                $html .= get_string('duplicate', 'local_moofactory_notification').'</a></div>';
68
                $html .= '<div class="col-md-7"><a href="'.$addurl.'">';
69
                $html .= $OUTPUT->pix_icon('i/addblock', '');
70
                $html .= get_string('add', 'local_moofactory_notification').'</a></div>';
71
            }
72
        }
73
        else{
74
            $html .= '<div class="col-md-7"><a href="'.$addurl.'">';
75
            $html .= $OUTPUT->pix_icon('i/addblock', '');
76
            $html .= get_string('add', 'local_moofactory_notification').'</a></div>';
77
        }
78
        $html .= '</div>';
79
 
80
        $mform->addElement('html', $html);
81
 
82
        $mform->addElement('text', 'notificationname', get_string('name', 'local_moofactory_notification'), 'size="50"');
83
        $mform->setType('notificationname', PARAM_RAW);
84
        $mform->addRule('notificationname', get_string('required', 'local_moofactory_notification'), 'required');
85
 
86
        if(!is_null($record->base) && $record->base != 1){
87
            $typeoptions['siteevent'] = get_string('siteevents', 'local_moofactory_notification');
88
            $typeoptions['courseevent'] = get_string('coursesevents', 'local_moofactory_notification');
89
            $typeoptions['courseenroll'] = get_string('coursesenrollments', 'local_moofactory_notification');
90
            $typeoptions['courseaccess'] = get_string('coursesaccess', 'local_moofactory_notification');
91
            $typeoptions['moduleaccess'] = get_string('moduleaccess', 'local_moofactory_notification');
92
            $select = $mform->addElement('select', 'notificationtype', get_string('type', 'local_moofactory_notification'), $typeoptions);
93
        }
94
        else{
95
            $mform->addElement('hidden', 'notificationtype');
96
            $mform->setType('notificationtype', PARAM_ALPHA);
97
            $mform->setDefault('notificationtype', $record->type);
98
        }
99
 
100
        $mform->addElement('text', 'notificationsubject', get_string('subject', 'local_moofactory_notification'), 'size="50"');
101
        $mform->setType('notificationsubject', PARAM_RAW);
102
        $mform->addRule('notificationsubject', get_string('required', 'local_moofactory_notification'), 'required');
103
 
104
        $mform->addElement('editor', 'notificationbodyhtml', get_string('bodyhtml', 'local_moofactory_notification'), 'wrap="virtual" rows="20" cols="80"');
105
        $mform->setType('notificationbodyhtml', PARAM_CLEANHTML);
106
 
107
        $mform->addElement('hidden', 'typeinitial');
108
        $mform->setType('typeinitial', PARAM_ALPHA);
109
        $mform->setDefault('typeinitial', $record->type);
110
 
111
        $html = '<div class="form-group row"><div class="col-md-3" style="margin-bottom: .5rem;">'.get_string('params', 'local_moofactory_notification').'</div>';
112
        $html .= '<div class="col-md-9">';
113
        $html .= '<table class="table table-sm merge-fields">';
114
        $html .= '  <tr>';
115
        $html .= '    <td width="250">{{firstname}}</td>';
116
        $html .= '    <td>'.get_string('params_firstname', 'local_moofactory_notification').'</td>';
117
        $html .= '  </tr>';
118
        $html .= '  <tr>';
119
        $html .= '    <td>{{lastname}}</td>';
120
        $html .= '    <td>'.get_string('params_lastname', 'local_moofactory_notification').'</td>';
121
        $html .= '  </tr>';
122
        $html .= '  <tr>';
123
        $html .= '    <td>{{username}}</td>';
124
        $html .= '    <td>'.get_string('params_username', 'local_moofactory_notification').'</td>';
125
        $html .= '  </tr>';
126
        $html .= '  <tr>';
127
        $html .= '    <td>{{usergroup}}</td>';
128
        $html .= '    <td>'.get_string('params_usergroup', 'local_moofactory_notification').'</td>';
129
        $html .= '  </tr>';
130
        $html .= '  <tr>';
131
        $html .= '    <td>{{eventdate}}</td>';
132
        $html .= '    <td>'.get_string('params_eventdate', 'local_moofactory_notification').'</td>';
133
        $html .= '  </tr>';
134
        $html .= '  <tr>';
135
        $html .= '    <td>{{eventname}}</td>';
136
        $html .= '    <td>'.get_string('params_eventname', 'local_moofactory_notification').'</td>';
137
        $html .= '  </tr>';
138
        $html .= '  <tr>';
139
        $html .= '    <td>{{coursename}}</td>';
140
        $html .= '    <td>'.get_string('params_coursename', 'local_moofactory_notification').'</td>';
141
        $html .= '  </tr>';
142
        $html .= '  <tr>';
143
        $html .= '    <td>{{coursestartdate}}</td>';
144
        $html .= '    <td>'.get_string('params_coursestartdate', 'local_moofactory_notification').'</td>';
145
        $html .= '  </tr>';
146
        $html .= '  <tr>';
147
        $html .= '    <td>{{courseenddate}}</td>';
148
        $html .= '    <td>'.get_string('params_courseenddate', 'local_moofactory_notification').'</td>';
149
        $html .= '  </tr>';
150
        $html .= '  <tr>';
151
        $html .= '    <td>{{courseenrolstartdate}}</td>';
152
        $html .= '    <td>'.get_string('params_courseenrolstartdate', 'local_moofactory_notification').'</td>';
153
        $html .= '  </tr>';
154
        $html .= '  <tr>';
155
        $html .= '    <td>{{courseenrolenddate}}</td>';
156
        $html .= '    <td>'.get_string('params_courseenrolenddate', 'local_moofactory_notification').'</td>';
157
        $html .= '  </tr>';
158
        $html .= '  <tr>';
159
        $html .= '    <td>{{courseurl}}</td>';
160
        $html .= '    <td>'.get_string('params_courseurl', 'local_moofactory_notification').'</td>';
161
        $html .= '  </tr>';
162
        $html .= '  <tr>';
163
        $html .= '    <td>{{activityname}}</td>';
164
        $html .= '    <td>'.get_string('params_activityname', 'local_moofactory_notification').'</td>';
165
        $html .= '  </tr>';
166
        $html .= '  <tr>';
167
        $html .= '    <td>{{lmsurl}}</td>';
168
        $html .= '    <td>'.get_string('params_lmsurl', 'local_moofactory_notification').'</td>';
169
        $html .= '  </tr>';
170
        $html .= '  <tr>';
171
        $html .= '    <td>{{lmsname}}</td>';
172
        $html .= '    <td>'.get_string('params_lmsname', 'local_moofactory_notification').'</td>';
173
        $html .= '  </tr>';
174
        $html .= '  <tr>';
175
        $html .= '    <td>{{interval}}</td>';
176
        $html .= '    <td>'.get_string('params_interval', 'local_moofactory_notification').'</td>';
177
        $html .= '  </tr>';
178
        $html .= '</table>';
179
        $html .= '</div></div>';
180
 
181
 
182
 
183
        $mform->addElement('html', $html);
184
 
185
        if(!empty($this->_customdata)){
186
            $mform->setDefault('notificationname', $record->name);
187
            if(!is_null($select)){
188
                $select->setSelected($record->type);
189
            }
190
            $mform->setDefault('notificationsubject', $record->subject);
191
            //$mform->setDefault('notificationbodyhtml', $record->bodyhtml);
192
            $mform->setDefault('notificationbodyhtml', array('text' => $record->bodyhtml,'format' => FORMAT_HTML));
193
        }
194
        else{
195
            $mform->setDefault('notificationname', ' ');
196
            $mform->setDefault('notificationsubject', ' ');
197
        }
198
 
199
        $mform->disable_form_change_checker();
200
 
201
        $this->add_action_buttons();
202
    }
203
 
204
 
205
}