Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * prints the forms to choose an item-typ to create items and to choose a template to use
19
 *
20
 * @author Andreas Grabs
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24
 
25
//It must be included from a Moodle page
26
if (!defined('MOODLE_INTERNAL')) {
27
    die('Direct access to this script is forbidden.');
28
}
29
 
30
require_once($CFG->libdir.'/formslib.php');
31
 
32
/**
33
 * The feedback_edit_use_template_form
34
 *
35
 * @deprecated since 4.0 new dynamic forms created
1441 ariadna 36
 * @todo       MDL-83522 This class will be deleted in Moodle 6.0.
1 efrain 37
 */
1441 ariadna 38
#[\core\attribute\deprecated(
39
    replacement: 'mod_feedback\form\use_template_form',
40
    since: '4.0',
41
    mdl: 'MDL-71914',
42
    reason: 'New dynamic forms have been created instead.'
43
)]
1 efrain 44
class feedback_edit_use_template_form extends moodleform {
45
    public function __construct($action = null, $customdata = null, $method = 'post', $target = '',
46
            $attributes = null, $editable = true, $ajaxformdata = null) {
47
        debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
48
        parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
49
    }
50
 
51
    /**
52
     * Overrides parent static method for deprecation purposes.
53
     *
54
     * @deprecated since 4.0
55
     * @return array
56
     */
57
    public static function get_js_module() {
58
        debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
59
        return parent::get_js_module();
60
    }
61
 
62
    /**
63
     * Overrides parent static method for deprecation purposes.
64
     *
65
     * @deprecated since 4.0
66
     * @param array $simulatedsubmitteddata
67
     * @param array $simulatedsubmittedfiles
68
     * @param string $method
69
     * @param null $formidentifier
70
     * @return array
71
     */
72
    public static function mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
73
            $method = 'post', $formidentifier = null) {
74
        debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
75
        return parent::mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
76
    }
77
 
78
    /**
79
     * Overrides parent static method for deprecation purposes.
80
     *
81
     * @deprecated since 4.0
82
     * @param array $data
83
     * @return array
84
     */
85
    public static function mock_generate_submit_keys($data = []) {
86
        debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
87
        return parent::mock_generate_submit_keys($data);
88
    }
89
 
90
    /**
91
     * Overrides parent static method for deprecation purposes.
92
     *
93
     * @deprecated since 4.0
94
     * @param array $simulatedsubmitteddata
95
     * @param array $simulatedsubmittedfiles
96
     * @param string $method
97
     * @param null $formidentifier
98
     */
99
    public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
100
            $method = 'post', $formidentifier = null) {
101
        debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
102
        parent::mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
103
    }
104
 
105
    /**
106
     * Form definition
107
     */
108
    public function definition() {
109
        $mform =& $this->_form;
110
 
111
        $course = $this->_customdata['course'];
112
 
113
        $elementgroup = array();
114
        //headline
115
        $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
116
        // hidden elements
117
        $mform->addElement('hidden', 'id');
118
        $mform->setType('id', PARAM_INT);
119
 
120
        // visible elements
121
        $templates_options = array();
122
        $owntemplates = feedback_get_template_list($course, 'own');
123
        $publictemplates = feedback_get_template_list($course, 'public');
124
 
125
        $options = array();
126
        if ($owntemplates or $publictemplates) {
127
            $options[''] = array('' => get_string('choosedots'));
128
 
129
            if ($owntemplates) {
130
                $courseoptions = array();
131
                foreach ($owntemplates as $template) {
132
                    $courseoptions[$template->id] = format_string($template->name);
133
                }
134
                $options[get_string('course')] = $courseoptions;
135
            }
136
 
137
            if ($publictemplates) {
138
                $publicoptions = array();
139
                foreach ($publictemplates as $template) {
140
                    $publicoptions[$template->id] = format_string($template->name);
141
                }
142
                $options[get_string('public', 'feedback')] = $publicoptions;
143
            }
144
 
145
            $attributes = [
146
                'onChange="this.form.submit()"',
147
                'data-form-change-checker-override="1"',
148
            ];
149
            $elementgroup[] = $mform->createElement(
150
                'selectgroups',
151
                'templateid',
152
                get_string('using_templates', 'feedback'),
153
                $options,
154
                implode(' ', $attributes)
155
            );
156
 
157
            $elementgroup[] = $mform->createElement('submit',
158
                                                     'use_template',
159
                                                     get_string('use_this_template', 'feedback'),
160
                                                     array('class' => 'hiddenifjs'));
161
 
162
            $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
163
        } else {
164
            $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
165
        }
166
 
167
        $this->set_data(array('id' => $this->_customdata['id']));
168
    }
169
}
170
 
171
/**
172
 * The feedback_edit_create_template_form
173
 *
174
 * @deprecated since 4.0, new dynamic forms have been created instead.
175
 */
176
class feedback_edit_create_template_form extends moodleform {
177
    public function __construct($action = null, $customdata = null, $method = 'post',
178
            $target = '', $attributes = null, $editable = true, $ajaxformdata = null) {
179
        debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
180
        parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
181
    }
182
 
183
    /**
184
     * Overrides parent static method for deprecation purposes.
185
     *
186
     * @deprecated since 4.0
187
     * @return array
188
     */
189
    public static function get_js_module() {
190
        debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
191
        return parent::get_js_module();
192
    }
193
 
194
    /**
195
     * Overrides parent static method for deprecation purposes.
196
     *
197
     * @deprecated since 4.0
198
     * @param array $simulatedsubmitteddata
199
     * @param array $simulatedsubmittedfiles
200
     * @param string $method
201
     * @param null $formidentifier
202
     * @return array
203
     */
204
    public static function mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
205
            $method = 'post', $formidentifier = null) {
206
        debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
207
        return parent::mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
208
    }
209
 
210
    /**
211
     * Overrides parent static method for deprecation purposes.
212
     *
213
     * @deprecated since 4.0
214
     * @param array $data
215
     * @return array
216
     */
217
    public static function mock_generate_submit_keys($data = []) {
218
        debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
219
        return parent::mock_generate_submit_keys($data);
220
    }
221
 
222
    /**
223
     * Overrides parent static method for deprecation purposes.
224
     *
225
     * @deprecated since 4.0
226
     * @param array $simulatedsubmitteddata
227
     * @param array $simulatedsubmittedfiles
228
     * @param string $method
229
     * @param null $formidentifier
230
     */
231
    public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
232
            $method = 'post', $formidentifier = null) {
233
        debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER);
234
        parent::mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
235
    }
236
 
237
    /**
238
     * Form definition
239
     */
240
    public function definition() {
241
        $mform =& $this->_form;
242
 
243
        // hidden elements
244
        $mform->addElement('hidden', 'id');
245
        $mform->setType('id', PARAM_INT);
246
        $mform->addElement('hidden', 'do_show');
247
        $mform->setType('do_show', PARAM_ALPHANUMEXT);
248
        $mform->setConstant('do_show', 'edit');
249
 
250
        // visible elements
251
        $elementgroup = array();
252
 
253
        $elementgroup[] = $mform->createElement('text',
254
                                                 'templatename',
255
                                                 get_string('name', 'feedback'),
256
                                                 ['maxlength' => '200']);
257
 
258
        if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
259
            $elementgroup[] = $mform->createElement('checkbox',
260
                                                     'ispublic', '',
261
                                                     get_string('public', 'feedback'));
262
        }
263
 
264
 
265
        $mform->addGroup($elementgroup,
266
                         'elementgroup',
267
                         get_string('name', 'feedback'),
268
                         array(' '),
269
                         false);
270
 
271
        // Buttons.
272
        $mform->addElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
273
 
274
        $mform->setType('templatename', PARAM_TEXT);
275
 
276
        $this->set_data(array('id' => $this->_customdata['id']));
277
    }
278
 
279
    /**
280
     * Form validation
281
     *
282
     * @param array $data array of ("fieldname"=>value) of submitted data
283
     * @param array $files array of uploaded files "element_name"=>tmp_file_path
284
     * @return array of "element_name"=>"error_description" if there are errors,
285
     *         or an empty array if everything is OK (true allowed for backwards compatibility too).
286
     */
287
    public function validation($data, $files) {
288
        $errors = parent::validation($data, $files);
289
        if (!isset($data['templatename']) || trim(strval($data['templatename'])) === '') {
290
            $errors['elementgroup'] = get_string('name_required', 'feedback');
291
        }
292
        return $errors;
293
    }
294
}
295