forked from nadavkav/moodle-mod_videofile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
275 lines (244 loc) · 10.4 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The main videofile configuration form.
*
* It uses the standard core Moodle formslib. For more info about them, please
* visit: http://docs.moodle.org/en/Development:lib/formslib.php
*
* @package mod_videofile
* @copyright 2013 Jonas Nockert <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/course/moodleform_mod.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once("$CFG->libdir/resourcelib.php");
require_once($CFG->libdir . '/filelib.php');
class mod_videofile_mod_form extends moodleform_mod {
/**
* Defines the videofile instance configuration form.
*
* @return void
*/
public function definition() {
global $CFG;
$config = get_config('videofile');
$mform =& $this->_form;
// Name and description fields.
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('name'), array('size' => '48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name',
get_string('maximumchars', '', 255),
'maxlength',
255,
'client');
// Function add_intro_editor() deprecated in 2.9.
if (method_exists($this, 'standard_intro_elements')) {
$this->standard_intro_elements();
} else {
$this->add_intro_editor(false);
}
// Video fields.
$mform->addElement('header',
'video_fieldset',
get_string('video_fieldset', 'videofile'));
// Width.
$mform->addElement('text',
'width',
get_string('width', 'videofile'),
array('size' => 4));
$mform->setType('width', PARAM_INT);
$mform->addHelpButton('width', 'width', 'videofile');
$mform->addRule('width', null, 'required', null, 'client');
$mform->addRule('width', null, 'numeric', null, 'client');
$mform->addRule('width', null, 'nonzero', null, 'client');
$mform->setDefault('width', $config->width);
// Height.
$mform->addElement('text',
'height',
get_string('height', 'videofile'),
array('size' => 4));
$mform->setType('height', PARAM_INT);
$mform->addHelpButton('height', 'height', 'videofile');
$mform->addRule('height', null, 'required', null, 'client');
$mform->addRule('height', null, 'numeric', null, 'client');
$mform->addRule('height', null, 'nonzero', null, 'client');
$mform->setDefault('height', $config->height);
// Responsive.
$mform->addElement('advcheckbox',
'responsive',
get_string('responsive', 'videofile'),
get_string('responsive_label', 'videofile'));
$mform->setType('responsive', PARAM_INT);
$mform->addHelpButton('responsive', 'responsive', 'videofile');
$mform->setDefault('responsive', $config->responsive);
// Responsive.
$mform->addElement('advcheckbox',
'mpegdash',
get_string('mpegdash', 'videofile'),
get_string('mpegdash_label', 'videofile'));
$mform->setType('mpegdash', PARAM_INT);
$mform->addHelpButton('mpegdash', 'mpegdash', 'videofile');
$mform->setDefault('mpegdash', $config->mpegdash);
// Responsive.
$mform->addElement('advcheckbox',
'transcript',
get_string('transcript', 'videofile'),
get_string('transcript_label', 'videofile'));
$mform->setType('transcript', PARAM_INT);
$mform->addHelpButton('transcript', 'transcript', 'videofile');
$mform->setDefault('transcript', $config->transcript);
// Video file url
$mform->addElement('url', 'externalurl', get_string('externalurl_label', 'videofile'), array('size'=>'60'), array('usefilepicker'=>true));
$mform->setType('externalurl', PARAM_URL);
$mform->addRule('externalurl',
get_string('maximumchars', '', 255),
'maxlength',
255,
'client');
// Video file manager.
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => -1,
'accepted_types' => array('.mp4', '.webm', '.ogv'));
$mform->addElement(
'filemanager',
'videos',
get_string('videos', 'videofile'),
null,
$options);
//$mform->addHelpButton('videos', 'videos', 'videofile');
//$mform->addRule('videos', null, 'required', null, 'client');
// Posters file manager.
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => 1,
'accepted_types' => array('image'));
$mform->addElement(
'filemanager',
'posters',
get_string('posters', 'videofile'),
null,
$options);
$mform->addHelpButton('posters', 'posters', 'videofile');
// Captions file manager.
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => -1,
'accepted_types' => array('.vtt'));
$mform->addElement(
'filemanager',
'captions',
get_string('captions', 'videofile'),
null,
$options);
$mform->addHelpButton('captions', 'captions', 'videofile');
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('appearance'));
if ($this->current->instance) {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
} else {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
}
if (count($options) == 1) {
$mform->addElement('hidden', 'display');
$mform->setType('display', PARAM_INT);
reset($options);
$mform->setDefault('display', key($options));
} else {
$mform->addElement('select', 'display', get_string('displayselect', 'resource'), $options);
$mform->setDefault('display', $config->display);
$mform->addHelpButton('display', 'displayselect', 'resource');
}
// Standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Standard buttons, common to all modules.
$this->add_action_buttons();
}
/**
* Prepares the form before data are set.
*
* @param array $data to be set
* @return void
*/
public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => -1);
$draftitemid = file_get_submitted_draft_itemid('videos');
file_prepare_draft_area($draftitemid,
$this->context->id,
'mod_videofile',
'videos',
0,
$options);
$defaultvalues['videos'] = $draftitemid;
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => 1);
$draftitemid = file_get_submitted_draft_itemid('posters');
file_prepare_draft_area($draftitemid,
$this->context->id,
'mod_videofile',
'posters',
0,
$options);
$defaultvalues['posters'] = $draftitemid;
$options = array('subdirs' => false,
'maxbytes' => 0,
'maxfiles' => -1);
$draftitemid = file_get_submitted_draft_itemid('captions');
file_prepare_draft_area($draftitemid,
$this->context->id,
'mod_videofile',
'captions',
0,
$options);
$defaultvalues['captions'] = $draftitemid;
if (empty($defaultvalues['width'])) {
$defaultvalues['width'] = 800;
}
if (empty($defaultvalues['height'])) {
$defaultvalues['height'] = 500;
}
}
}
/**
* Validates the form input
*
* @param array $data submitted data
* @param array $files submitted files
* @return array eventual errors indexed by the field name
*/
public function validation($data, $files) {
$errors = array();
if ($data['width'] <= 0) {
$errors['width'] = get_string('err_positive', 'videofile');
}
if ($data['height'] <= 0) {
$errors['height'] = get_string('err_positive', 'videofile');
}
return $errors;
}
}