Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * The main mod_stickynotes configuration form.
19
 *
20
 * @package     mod_stickynotes
21
 * @copyright   2021 Olivier VALENTIN
22
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->dirroot.'/course/moodleform_mod.php');
28
 
29
/**
30
 * Module instance settings form.
31
 *
32
 * @package     mod_stickynotes
33
 * @copyright   2021 Olivier VALENTIN
34
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class mod_stickynotes_mod_form extends moodleform_mod {
37
 
38
    /**
39
     * Defines forms elements
40
     */
41
    public function definition() {
42
        global $CFG;
43
 
44
        $mform = $this->_form;
45
 
46
        // Adding the "general" fieldset, where all the common settings are shown.
47
        $mform->addElement('header', 'general', get_string('general', 'form'));
48
 
49
        // Adding the standard "name" field.
50
        $mform->addElement('text', 'name', get_string('stickynotesname', 'mod_stickynotes'), array('size' => '64'));
51
 
52
        if (!empty($CFG->formatstringstriptags)) {
53
            $mform->setType('name', PARAM_TEXT);
54
        } else {
55
            $mform->setType('name', PARAM_CLEANHTML);
56
        }
57
 
58
        $mform->addRule('name', null, 'required', null, 'client');
59
        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
60
 
61
        // Adding the standard "intro" and "introformat" fields.
62
        if ($CFG->branch >= 29) {
63
            $this->standard_intro_elements();
64
        } else {
65
            $this->add_intro_editor();
66
        }
67
 
68
        // Adding the "colors" fieldset.
69
        $mform->addElement('header', 'settings_notes', get_string('settings_notes', 'stickynotes'));
70
 
71
        // Enable the limitation of notes ?
72
        $mform->addElement('advcheckbox', 'limitstickynotes', get_string('limitstickynotes', 'stickynotes'));
73
        $mform->addHelpButton('limitstickynotes', 'limitstickynotes', 'stickynotes');
74
 
75
        // Max number of notes.
76
        $mform->disabledIf('maxstickynotes', 'limitstickynotes', '0');
77
        $mform->addElement('text', 'maxstickynotes', get_string('maxstickynotes', 'stickynotes'));
78
        $mform->setType('maxstickynotes', PARAM_INT);
79
        $mform->addRule('maxstickynotes', get_string('maxstickynoteserror', 'stickynotes'), 'regex', '/^[0-9]+$/', 'client');
80
 
81
        // Show authors ?
82
        $mform->addElement('advcheckbox', 'viewauthor', get_string('viewauthor', 'stickynotes'));
83
        $mform->addHelpButton('viewauthor', 'viewauthor', 'stickynotes');
84
 
85
        // Students can move any notes ?
86
        $mform->addElement('advcheckbox', 'moveallnotes', get_string('moveallnotes', 'stickynotes'));
87
        $mform->addHelpButton('moveallnotes', 'moveallnotes', 'stickynotes');
88
 
89
        // Students can see all notes ?
90
        $mform->addElement('advcheckbox', 'seeallnotes', get_string('seeallnotes', 'stickynotes'));
91
        $mform->addHelpButton('seeallnotes', 'seeallnotes', 'stickynotes');
92
        $mform->setDefault('seeallnotes',  '1');
93
 
94
        // Rotate notes ?
95
        $mform->addElement('advcheckbox', 'rotate', get_string('rotate', 'stickynotes'));
96
        $mform->addHelpButton('rotate', 'rotate', 'stickynotes');
97
        $mform->setDefault('rotate',  '1');
98
 
99
        // Adding the "votes" fieldset.
100
        $mform->addElement('header', 'settings_votes', get_string('settings_votes', 'stickynotes'));
101
 
102
        // Define votes types :0 = no votes, 1 = user can like a vote.
103
        $options = array(
104
            '0'      => get_string('votenone', 'stickynotes'),
105
            '1'      => get_string('votelike', 'stickynotes')
106
        );
107
 
108
        $mform->addElement('select', 'votes', get_string('votetype', 'stickynotes'), $options);
109
        $mform->addHelpButton('votes', 'votetype', 'stickynotes');
110
 
111
        // Enable the limitation of votes ?
112
        $mform->disabledIf('limitvotes', 'votes', '0');
113
        $mform->addElement('advcheckbox', 'limitvotes', get_string('limitvotes', 'stickynotes'));
114
        $mform->addHelpButton('limitvotes', 'limitvotes', 'stickynotes');
115
 
116
        // Max number of votes.
117
        $mform->disabledIf('maxlimitvotes', 'votes', '0');
118
        $mform->disabledIf('maxlimitvotes', 'limitvotes', '1');
119
        $maxvoteschoice = array(
120
            1   => 1,
121
            2   => 2,
122
            3   => 3,
123
            4   => 4,
124
            5   => 5,
125
            6   => 6,
126
            7   => 7,
127
            8   => 8,
128
            9   => 9,
129
            10  => 10,
130
        );
131
        $mform->addElement('select', 'maxlimitvotes', get_string('maxlimitvotes', 'stickynotes'), $maxvoteschoice);
132
        $mform->addHelpButton('maxlimitvotes', 'maxlimitvotes', 'stickynotes');
133
        $mform->setType('maxlimitvotes', PARAM_INT);
134
 
135
        // Adding the "colors" fieldset.
136
        $mform->addElement('header', 'settings_colors', get_string('settings_colors', 'stickynotes'));
137
 
138
        // Can users choose background colors ?
139
        $mform->addElement('advcheckbox', 'colors', get_string('colors', 'stickynotes'));
140
        $mform->addHelpButton('colors', 'colors', 'stickynotes');
141
        $mform->setDefault('colors',  '1');
142
 
143
        // Display caption in activity ?
144
        $mform->addElement('advcheckbox', 'displaystickycaption', get_string('displaystickycaption', 'stickynotes'));
145
        $mform->addHelpButton('displaystickycaption', 'displaystickycaption', 'stickynotes');
146
 
147
        // Text to introduce choice of colors and their meanings.
148
        $mform->addElement('static', 'color_show', '', get_string('choosecolors', 'stickynotes'));
149
 
150
        // Color 1.
151
        $mform->disabledIf('color1', 'colors', '0');
152
        $mform->addElement('advcheckbox', 'color1', '<div style="background-color:'.get_config('mod_stickynotes', 'color1').'">
153
'.get_string('color1_title', 'stickynotes').'</div>');
154
        $mform->setDefault('color1',  '1');
155
 
156
        $mform->disabledIf('color1_meaning', 'colors', '0');
157
        $mform->disabledIf('color1_meaning', 'color1', '0');
158
        $mform->addElement('text', 'color1_meaning', get_string('color1_meaning', 'stickynotes'));
159
        $mform->setType('color1_meaning', PARAM_TEXT);
160
 
161
        // Color 2.
162
        $mform->disabledIf('color2', 'colors', '0');
163
        $mform->addElement('advcheckbox', 'color2', '<div style="background-color:'.get_config('mod_stickynotes', 'color2').'">
164
'.get_string('color2_title', 'stickynotes').'</div>');
165
        $mform->setDefault('color2',  '1');
166
 
167
        $mform->disabledIf('color2_meaning', 'colors', '0');
168
        $mform->disabledIf('color2_meaning', 'color2', '0');
169
        $mform->addElement('text', 'color2_meaning', get_string('color2_meaning', 'stickynotes'));
170
        $mform->setType('color2_meaning', PARAM_TEXT);
171
 
172
        // Color 3.
173
        $mform->disabledIf('color3', 'colors', '0');
174
        $mform->addElement('advcheckbox', 'color3', '<div style="background-color:'.get_config('mod_stickynotes', 'color3').'">
175
'.get_string('color3_title', 'stickynotes').'</div>');
176
        $mform->setDefault('color3',  '1');
177
 
178
        $mform->disabledIf('color3_meaning', 'colors', '0');
179
        $mform->disabledIf('color3_meaning', 'color3', '0');
180
        $mform->addElement('text', 'color3_meaning', get_string('color3_meaning', 'stickynotes'));
181
        $mform->setType('color3_meaning', PARAM_TEXT);
182
 
183
        // Color 4.
184
        $mform->disabledIf('color4', 'colors', '0');
185
        $mform->addElement('advcheckbox', 'color4', '<div style="background-color:'.get_config('mod_stickynotes', 'color4').'">
186
'.get_string('color4_title', 'stickynotes').'</div>');
187
        $mform->setDefault('color4',  '1');
188
 
189
        $mform->disabledIf('color4_meaning', 'colors', '0');
190
        $mform->disabledIf('color4_meaning', 'color4', '0');
191
        $mform->addElement('text', 'color4_meaning', get_string('color4_meaning', 'stickynotes'));
192
        $mform->setType('color4_meaning', PARAM_TEXT);
193
 
194
        // Color 5.
195
        $mform->disabledIf('color5', 'colors', '0');
196
        $mform->addElement('advcheckbox', 'color5', '<div style="background-color:'.get_config('mod_stickynotes', 'color5').'">
197
'.get_string('color5_title', 'stickynotes').'</div>');
198
        $mform->setDefault('color5',  '1');
199
 
200
        $mform->disabledIf('color5_meaning', 'colors', '0');
201
        $mform->disabledIf('color5_meaning', 'color5', '0');
202
        $mform->addElement('text', 'color5_meaning', get_string('color5_meaning', 'stickynotes'));
203
        $mform->setType('color5_meaning', PARAM_TEXT);
204
 
205
        // Color 6.
206
        $mform->disabledIf('color6', 'colors', '0');
207
        $mform->addElement('advcheckbox', 'color6', '<div style="background-color:'.get_config('mod_stickynotes', 'color6').'">
208
'.get_string('color6_title', 'stickynotes').'</div>');
209
        $mform->setDefault('color6',  '1');
210
 
211
        $mform->disabledIf('color6_meaning', 'colors', '0');
212
        $mform->disabledIf('color6_meaning', 'color6', '0');
213
        $mform->addElement('text', 'color6_meaning', get_string('color6_meaning', 'stickynotes'));
214
        $mform->setType('color6_meaning', PARAM_TEXT);
215
 
216
        // Add standard elements.
217
        $this->standard_coursemodule_elements();
218
 
219
        // Add standard buttons.
220
        $this->add_action_buttons();
221
    }
222
 
223
    /**
224
     * Preprocess data.
225
     * @param array $defaultvalues
226
     */
227
    public function data_preprocessing(&$defaultvalues) {
228
        $defaultvalues['completionstickynotesenabled'] = !empty($defaultvalues['completionstickynotes']) ? 1 : 0;
229
    }
230
 
231
    /**
232
     * Add elements for setting the custom completion rules.
233
     *
234
     * @category completion
235
     * @return array List of added element names, or names of wrapping group elements.
236
     */
237
 
238
    public function add_completion_rules() {
239
        $mform = $this->_form;
240
 
241
        $group = [
242
            $mform->createElement(
243
            'checkbox',
244
            'completionstickynotesenabled',
245
            ' ',
246
            get_string('completionstickynotesenabled', 'mod_stickynotes')
247
            ),
248
            $mform->createElement(
249
                'text',
250
                'completionstickynotes',
251
                ' ',
252
                ['size' => 3]
253
            ),
254
        ];
255
        $mform->setType('completionstickynotes', PARAM_INT);
256
        $mform->addGroup(
257
            $group,
258
            'completionstickynotesgroup',
259
            get_string('completionstickynotesgroup', 'mod_stickynotes'),
260
            [' '],
261
            false);
262
        $mform->disabledIf('completionstickynotes', 'completionstickynotesenabled', 'notchecked');
263
 
264
        return ['completionstickynotesgroup'];
265
    }
266
 
267
    /**
268
     * Determines if completion is enabled for this module.
269
     *
270
     * @param array $data
271
     * @return bool
272
     */
273
    public function completion_rule_enabled($data) {
274
        return (!empty($data['completionstickynotesenabled']) && $data['completionstickynotes'] != 0);
275
    }
276
 
277
    /**
278
     * Allows module to modify the data returned by form get_data().
279
     * This method is also called in the bulk activity completion form.
280
     *
281
     * Only available on moodleform_mod.
282
     *
283
     * @param stdClass $data the form data to be modified.
284
     */
285
    public function data_postprocessing($data) {
286
        parent::data_postprocessing($data);
287
        // Turn off completion settings if the checkboxes aren't ticked.
288
        if (!empty($data->completionunlocked)) {
289
            $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
290
            if (empty($data->completionstickynotesenabled) || !$autocompletion) {
291
                $data->completionstickynotes = 0;
292
            }
293
        }
294
    }
295
}