forked from ericmerrill/moodle-mod_webexactivity
/
mod_form.php
149 lines (127 loc) · 6.08 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
<?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/>.
/**
* An activity to interface with WebEx.
*
* @package mod_webexactvity
* @author Eric Merrill <merrill@oakland.edu>
* @copyright 2014 Oakland University
* @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');
/**
* Class the creates the mod_form.
*
* @package mod_webexactvity
* @author Eric Merrill <merrill@oakland.edu>
* @copyright 2014 Oakland University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_webexactivity_mod_form extends \moodleform_mod {
/**
* Called to define this moodle form
*
* @return void
*/
public function definition() {
global $CFG, $DB, $OUTPUT;
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
// Types cannot be changed. Check if it's already set.
if (!empty($this->current->id)) {
$typename = \mod_webexactivity\meeting::get_meeting_type_name($this->current->type);
$mform->addElement('static', 'typestatic', get_string('meetingtype', 'webexactivity'), $typename);
} else {
$meetingtypes = \mod_webexactivity\meeting::get_available_types($this->context);
if (count($meetingtypes) == 0) {
throw new \coding_exception('There are no valid meeting types for this user. Admin must fix.');
} else if (count($meetingtypes) == 1) {
$keys = array_keys($meetingtypes);
$type = array_pop($keys);
$mform->addElement('static', 'typestatic', get_string('meetingtype', 'webexactivity'), $meetingtypes[$type]);
$mform->addElement('hidden', 'type', $type);
} else {
$mform->addElement('select', 'type', get_string('meetingtype', 'webexactivity'), $meetingtypes);
$mform->setDefault('type', get_config('webexactivity', 'defaultmeetingtype'));
}
$mform->setType('type', PARAM_INT);
}
$mform->addElement('text', 'name', get_string('webexactivityname', 'webexactivity'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$this->add_intro_editor(false);
$mform->addElement('date_time_selector', 'starttime', get_string('starttime', 'webexactivity'));
$mform->addRule('starttime', null, 'required', null, 'client');
$duration = array();
$duration[] =& $mform->createElement('text', 'duration', '', array('size' => '4'));
$duration[] =& $mform->createElement('static', 'durationname', '', '('.get_string('minutes').')');
$mform->addGroup($duration, 'durationgroup', get_string('duration', 'webexactivity'), array(' '), false);
$mform->setType('duration', PARAM_INT);
$mform->addRule('durationgroup', null, 'required', null, 'client');
$mform->setDefault('duration', 20);
$mform->addHelpButton('durationgroup', 'duration', 'webexactivity');
$mform->addElement('passwordunmask', 'password', get_string('meetingpassword', 'webexactivity'));
$mform->setType('password', PARAM_TEXT);
$mform->addRule('password', null, 'maxlength', 16, 'client');
$req = get_config('webexactivity', 'requiremeetingpassword');
if ($req) {
$mform->addRule('password', null, 'required', null, 'client');
}
$mform->addElement('header', 'additionalsettings', get_string('additionalsettings', 'webexactivity'));
$mform->addElement('checkbox', 'studentdownload', get_string('studentdownload', 'webexactivity'));
$mform->setDefault('studentdownload', 1);
$mform->addHelpButton('studentdownload', 'studentdownload', 'webexactivity');
$mform->addElement('checkbox', 'longavailability', get_string('longavailability', 'webexactivity'));
$mform->setDefault('longavailability', 0);
$mform->addHelpButton('longavailability', 'longavailability', 'webexactivity');
$mform->addElement('date_time_selector', 'endtime', get_string('availabilityendtime', 'webexactivity'));
$mform->setDefault('endtime', (time() + (3600 * 24 * 14)));
$mform->addRule('starttime', null, 'required', null, 'client');
$mform->disabledIf('endtime', 'longavailability');
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
/**
* Any data processing needed before the form is displayed.
*
* @param array $defaultvalues
*/
public function data_preprocessing(&$data) {
if (isset($data['endtime'])) {
$data['longavailability'] = 1;
} else {
$data['longavailability'] = 0;
$data['endtime'] = time() + (3600 * 24 * 14);
}
}
/**
* Perform minimal validation on the settings form.
*
* @param array $data
* @param array $files
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($data['instance'] == 0) {
// Check that the passed type is valid.
if (!isset($data['type']) || (!\mod_webexactivity\meeting::is_valid_type($data['type'], $this->context))) {
$errors['type'] = get_string('invalidtype', 'webexactivity');
}
}
return $errors;
}
}