forked from sbourget/moodle-mod_pcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_form.php
More file actions
355 lines (309 loc) · 14.6 KB
/
Copy pathmod_form.php
File metadata and controls
355 lines (309 loc) · 14.6 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?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 pcast 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_pcast
* @copyright 2010 Stephen Bourget
* @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');
/**
* The main pcast 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_pcast
* @copyright 2010 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_pcast_mod_form extends moodleform_mod {
/**
* The form definition.
*/
public function definition() {
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
$pcastconfig = get_config('mod_pcast');
// Adding the "general" fieldset, where all the common settings are showed.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field.
$mform->addElement('text', 'name', get_string('pcastname', 'pcast'), ['size' => '64']);
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEAN);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Adding the standard "intro" and "introformat" fields.
$this->standard_intro_elements();
// Adding the max upload size of episodes.
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0);
$mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'pcast'), $choices);
$mform->addHelpButton('maxbytes', 'maxattachmentsize', 'pcast');
$mform->setDefault('maxbytes', $COURSE->maxbytes);
$mform->addElement(
'filetypes',
'allowedfiletypes',
get_string('allowedfiletypes', 'pcast'),
['onlytypes' => ['html_audio', 'web_audio', 'html_video', 'web_video'], 'allowunknown' => true]
);
$mform->addHelpButton('allowedfiletypes', 'allowedfiletypes', 'pcast');
$mform->setDefault('allowedfiletypes', 'web_audio,web_video,html_video,html_audio');
// RSS Settings.
if ($CFG->enablerssfeeds && isset($pcastconfig->enablerssfeeds) && $pcastconfig->enablerssfeeds) {
$mform->addElement('header', 'rss', get_string('rss'));
// RSS enabled.
$mform->addElement('selectyesno', 'enablerssfeed', get_string('enablerssfeed', 'pcast'));
$mform->addHelpButton('enablerssfeed', 'enablerssfeed', 'pcast');
// RSS Entries per feed.
$choices = [];
$choices[1] = '1';
$choices[2] = '2';
$choices[3] = '3';
$choices[4] = '4';
$choices[5] = '5';
$choices[10] = '10';
$choices[15] = '15';
$choices[20] = '20';
$choices[25] = '25';
$choices[30] = '30';
$choices[40] = '40';
$choices[50] = '50';
$mform->addElement('select', 'rssepisodes', get_string('rssepisodes', 'pcast'), $choices);
$mform->addHelpButton('rssepisodes', 'rssepisodes', 'pcast');
$mform->disabledIf('rssepisodes', 'enablerssfeed', 'eq', 0);
$mform->setDefault('rssepisodes', 10);
// RSS Sort Order.
$sortorder = [];
$sortorder[0] = get_string('createasc', 'pcast');
$sortorder[1] = get_string('createdesc', 'pcast');
$mform->addElement('select', 'rsssortorder', get_string('rsssortorder', 'pcast'), $sortorder);
$mform->addHelpButton('rsssortorder', 'rsssortorder', 'pcast');
$mform->setDefault('rsssortorder', 2);
$mform->disabledIf('rsssortorder', 'enablerssfeed', 'eq', 0);
}
// Itunes.
if ($CFG->enablerssfeeds && isset($pcastconfig->enablerssitunes) && $pcastconfig->enablerssitunes) {
// Itunes Tags.
$mform->addElement('header', 'itunes', get_string('itunes', 'pcast'));
// Enable Itunes Tags.
$mform->addElement('selectyesno', 'enablerssitunes', get_string('enablerssitunes', 'pcast'));
$mform->addHelpButton('enablerssitunes', 'enablerssitunes', 'pcast');
$mform->setDefault('enablerssitunes', 0);
$mform->disabledIf('enablerssitunes', 'enablerssfeed', 'eq', 0);
// Subtitle.
$mform->addElement('text', 'subtitle', get_string('subtitle', 'pcast'), ['size' => '64']);
$mform->setType('subtitle', PARAM_NOTAGS);
$mform->addHelpButton('subtitle', 'subtitle', 'pcast');
$mform->disabledIf('subtitle', 'enablerssitunes', 'eq', 0);
$mform->addRule('subtitle', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Owner.
$ownerlist = [];
$context = context_course::instance($COURSE->id);
if ($owners = get_users_by_capability($context, 'mod/pcast:manage', 'u.*', 'u.lastaccess')) {
foreach ($owners as $owner) {
$ownerlist[$owner->id] = $owner->firstname . ' ' . $owner->lastname;
}
}
$mform->addElement('select', 'userid', get_string('author', 'pcast'), $ownerlist);
$mform->addHelpButton('userid', 'author', 'pcast');
$mform->disabledIf('userid', 'enablerssitunes', 'eq', 0);
// Keywords.
$mform->addElement('text', 'keywords', get_string('keywords', 'pcast'), ['size' => '64']);
$mform->setType('keywords', PARAM_NOTAGS);
$mform->addHelpButton('keywords', 'keywords', 'pcast');
$mform->disabledIf('keywords', 'enablerssitunes', 'eq', 0);
$mform->addRule('keywords', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Category form element.
$mform->addElement('selectgroups', 'category', get_string('category', 'pcast'), pcast_get_categories());
$mform->addHelpButton('category', 'category', 'pcast');
$mform->disabledIf('category', 'enablerssitunes', 'eq', 0);
// Content.
$explicit = [];
$explicit[0] = get_string('yes');
$explicit[1] = get_string('no');
$explicit[2] = get_string('clean', 'pcast');
$mform->addElement('select', 'explicit', get_string('explicit', 'pcast'), $explicit);
$mform->addHelpButton('explicit', 'explicit', 'pcast');
$mform->disabledIf('explicit', 'enablerssitunes', 'eq', 0);
$mform->setDefault('explicit', 2);
}
// General Podcast settings.
$mform->addElement('header', 'posting', get_string('setupposting', 'pcast'));
// Allow comments.
if ($CFG->usecomments) {
$mform->addElement('selectyesno', 'userscancomment', get_string('userscancomment', 'pcast'));
$mform->addHelpButton('userscancomment', 'userscancomment', 'pcast');
$mform->setDefault('userscancomment', 0);
}
// Allow users to post episodes.
$mform->addElement('selectyesno', 'userscanpost', get_string('userscanpost', 'pcast'));
$mform->addHelpButton('userscanpost', 'userscanpost', 'pcast');
$mform->setDefault('userscanpost', 1);
// Require approval for posts.
$mform->addElement('selectyesno', 'requireapproval', get_string('requireapproval', 'pcast'));
$mform->addHelpButton('requireapproval', 'requireapproval', 'pcast');
$mform->setDefault('requireapproval', 1);
// Allow Display authors names.
$mform->addElement('selectyesno', 'displayauthor', get_string('displayauthor', 'pcast'));
$mform->addHelpButton('displayauthor', 'displayauthor', 'pcast');
$mform->setDefault('displayauthor', 0);
// Allow Display of viewers names.
$mform->addElement('selectyesno', 'displayviews', get_string('displayviews', 'pcast'));
$mform->addHelpButton('displayviews', 'displayviews', 'pcast');
$mform->setDefault('displayviews', 0);
// Allow users to select categories.
$mform->addElement('selectyesno', 'userscancategorize', get_string('userscancategorize', 'pcast'));
$mform->addHelpButton('userscancategorize', 'userscancategorize', 'pcast');
$mform->setDefault('userscancategorize', 0);
$mform->disabledIf('userscancategorize', 'enablerssitunes', 'eq', 0);
// Show X episodes per page.
$mform->addElement('text', 'episodesperpage', get_string('episodesperpage', 'pcast'));
$mform->addHelpButton('episodesperpage', 'episodesperpage', 'pcast');
$mform->setDefault('episodesperpage', 10);
$mform->addRule('episodesperpage', null, 'numeric', null, 'client');
$mform->setType('episodesperpage', PARAM_INT);
// Images.
$mform->addElement('header', 'images', get_string('image', 'pcast'));
$mform->addElement(
'filemanager',
'image',
get_string('imagefile', 'pcast'),
null,
['subdirs' => 0, 'maxfiles' => 1, 'filetypes' => ['jpeg', 'png'], 'returnvalue' => 'ref_id'],
);
// Image Size (Height).
$size = [];
$size[0] = get_string('noresize', 'pcast');
$size[16] = "16";
$size[32] = "32";
$size[48] = "48";
$size[64] = "64";
$size[128] = "128";
$size[144] = "144";
$size[200] = "200";
$size[400] = "400";
$mform->addElement('select', 'imageheight', get_string('imageheight', 'pcast'), $size);
$mform->addHelpButton('imageheight', 'imageheight', 'pcast');
$mform->setDefault('imageheight', 144);
// Image Size (Width).
unset($size);
$size = [];
$size[0] = get_string('noresize', 'pcast');
$size[16] = "16";
$size[32] = "32";
$size[48] = "48";
$size[64] = "64";
$size[128] = "128";
$size[144] = "144";
$mform->addElement('select', 'imagewidth', get_string('imagewidth', 'pcast'), $size);
$mform->addHelpButton('imagewidth', 'imagewidth', 'pcast');
$mform->setDefault('imagewidth', 144);
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
/**
* Function used to edit user data before save.
* @param array $defaultvalues
*/
public function data_preprocessing(&$defaultvalues) {
parent::data_preprocessing($defaultvalues);
if ($this->current->instance) {
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('id');
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_pcast', 'logo', 0, ['subdirs' => false]);
$defaultvalues['image'] = $draftitemid;
// Convert topcategory and nested to a single category.
$defaultvalues['category'] = (int)$defaultvalues['topcategory'] * 1000 + (int)$defaultvalues['nestedcategory'];
}
// Set up the completion checkboxes which aren't part of standard data.
// We also make the default value (if you turn on the checkbox) for those
// numbers to be 1, this will not apply unless checkbox is ticked.
if (!empty($defaultvalues['completionepisodes'])) {
$defaultvalues['completionepisodesenabled'] = 1;
} else {
$defaultvalues['completionepisodesenabled'] = 0;
}
if (empty($defaultvalues['completionepisodes'])) {
$defaultvalues['completionepisodes'] = 1;
}
}
/**
* Add completion rules to form.
* @return array
*/
public function add_completion_rules() {
$mform =& $this->_form;
$suffix = $this->get_suffix();
$completionepisodes = 'completionepisodes' . $suffix;
$completionepisodesenabled = 'completionepisodesenabled' . $suffix;
$completionepisodesgroup = 'completionepisodesgroup' . $suffix;
$group = [];
$group[] =& $mform->createElement(
'checkbox',
$completionepisodesenabled,
'',
get_string('completionepisodes', 'pcast')
);
$group[] =& $mform->createElement('text', $completionepisodes, '', ['size' => 3]);
$mform->setType($completionepisodes, PARAM_INT);
$mform->addGroup(
$group,
$completionepisodesgroup,
get_string('completionepisodesgroup', 'pcast'),
[' '],
false
);
$mform->disabledIf($completionepisodes, $completionepisodesenabled, 'notchecked');
return [$completionepisodesgroup];
}
/**
* Enable completion rules.
* @param stdcalss $data
* @return array
*/
public function completion_rule_enabled($data) {
$suffix = $this->get_suffix();
return (!empty($data['completionepisodesenabled' . $suffix]) && $data['completionepisodes' . $suffix] != 0);
}
/**
* Used to load form data.
* @return object | boolean
*/
public function get_data() {
$data = parent::get_data();
if (!$data) {
return false;
}
if (!empty($data->completionunlocked)) {
// Turn off completion settings if the checkboxes aren't ticked.
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
if (empty($data->completionepisodesenabled) || !$autocompletion) {
$data->completionepisodes = 0;
}
}
return $data;
}
}