forked from ncstate-delta/moodle-mod_zoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_form.php
executable file
·211 lines (179 loc) · 8.63 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
<?php
// This file is part of the Zoom plugin for 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 zoom 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_zoom
* @copyright 2015 UC Regents
* @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($CFG->dirroot.'/mod/zoom/lib.php');
require_once($CFG->dirroot.'/mod/zoom/locallib.php');
/**
* Module instance settings form
*
* @package mod_zoom
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_zoom_mod_form extends moodleform_mod {
/**
* Defines forms elements
*/
public function definition() {
global $USER;
$service = new mod_zoom_webservice();
// Check if the logged-in user exists on Zoom.
if (!$service->user_getbyemail($USER->email)) {
zoom_print_error('user/getbyemail', $service->lasterror);
}
$zoomuser = $service->lastresponse;
// If updating, ensure we can get the meeting on Zoom.
// If the meeting can't be found, zoom_print_error will offer to recreate the meeting on Zoom.
$isnew = empty($this->_cm);
if (!$isnew && !$service->get_meeting_info($this->current)) {
zoom_print_error('meeting/get', $service->lasterror, $this->_cm->id);
}
// Start of form definition.
$mform = $this->_form;
// Adding the "general" fieldset, where all the common settings are showed.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Add topic (stored in database as 'name').
$mform->addElement('text', 'name', get_string('topic', 'zoom'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 300), 'maxlength', 300, 'client');
// Add description ('intro' and 'introformat').
$this->standard_intro_elements();
// Add date/time. Validation in validation().
$mform->addElement('date_time_selector', 'start_time', get_string('start_time', 'zoom'));
// Disable for recurring meetings.
$mform->disabledIf('start_time', 'recurring', 'checked');
// Add duration.
$mform->addElement('duration', 'duration', get_string('duration', 'zoom'), array('optional' => false));
// Validation in validation(). Default to one hour.
$mform->setDefault('duration', array('number' => 1, 'timeunit' => 3600));
// Disable for recurring meetings.
$mform->disabledIf('duration', 'recurring', 'checked');
// Add recurring.
$mform->addElement('advcheckbox', 'recurring', get_string('recurringmeeting', 'zoom'));
$mform->setDefault('recurring', 0);
$mform->addHelpButton('recurring', 'recurringmeeting', 'zoom');
// Add webinar, disabled if the user cannot create webinars.
$webinarattr = null;
if (!$zoomuser->enable_webinar) {
$webinarattr = array('disabled' => true, 'group' => null);
}
$mform->addElement('advcheckbox', 'webinar', get_string('webinar', 'zoom'), '', $webinarattr);
$mform->setDefault('webinar', 0);
$mform->addHelpButton('webinar', 'webinar', 'zoom');
// Add password.
$mform->addElement('passwordunmask', 'password', get_string('password', 'zoom'), array('maxlength' => '10'));
// Check password uses valid characters.
$regex = '/^[a-zA-Z0-9@_*-]{1,10}$/';
$mform->addRule('password', get_string('err_password', 'mod_zoom'), 'regex', $regex, 'client');
$mform->disabledIf('password', 'webinar', 'checked');
// Add host/participants video (checked by default).
$mform->addGroup(array(
$mform->createElement('radio', 'option_host_video', '', get_string('on', 'zoom'), true),
$mform->createElement('radio', 'option_host_video', '', get_string('off', 'zoom'), false)
), null, get_string('option_host_video', 'zoom'));
$mform->setDefault('option_host_video', true);
$mform->disabledIf('option_host_video', 'webinar', 'checked');
$mform->addGroup(array(
$mform->createElement('radio', 'option_participants_video', '', get_string('on', 'zoom'), true),
$mform->createElement('radio', 'option_participants_video', '', get_string('off', 'zoom'), false)
), null, get_string('option_participants_video', 'zoom'));
$mform->setDefault('option_participants_video', true);
$mform->disabledIf('option_participants_video', 'webinar', 'checked');
// Add audio options.
$mform->addGroup(array(
$mform->createElement('radio', 'option_audio', '', get_string('audio_telephony', 'zoom'), ZOOM_AUDIO_TELEPHONY),
$mform->createElement('radio', 'option_audio', '', get_string('audio_voip', 'zoom'), ZOOM_AUDIO_VOIP),
$mform->createElement('radio', 'option_audio', '', get_string('audio_both', 'zoom'), ZOOM_AUDIO_BOTH)
), null, get_string('option_audio', 'zoom'));
$mform->setDefault('option_audio', ZOOM_AUDIO_BOTH);
// Add meeting options. Make sure we pass $appendName as false
// so the options aren't nested in a 'meetingoptions' array.
$mform->addGroup(array(
// Join before host.
$mform->createElement('advcheckbox', 'option_jbh', '', get_string('option_jbh', 'zoom'))
), 'meetingoptions', get_string('meetingoptions', 'zoom'), null, false);
$mform->addHelpButton('meetingoptions', 'meetingoptions', 'zoom');
$mform->disabledIf('meetingoptions', 'webinar', 'checked');
// Add meeting id.
$mform->addElement('hidden', 'meeting_id', -1);
$mform->setType('meeting_id', PARAM_ALPHANUMEXT);
// Add host id (will error if user does not have an account on Zoom).
$mform->addElement('hidden', 'host_id', zoom_get_user_id());
$mform->setType('host_id', PARAM_ALPHANUMEXT);
// Add standard grading elements.
$this->standard_grading_coursemodule_elements();
$mform->setDefault('grade', false);
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
/**
* More validation on form data.
* See documentation in lib/formslib.php.
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files) {
$errors = array();
// Only check for scheduled meetings.
if (empty($data['recurring'])) {
// Make sure start date is in the future.
if ($data['start_time'] < strtotime('today')) {
$errors['start_time'] = get_string('err_start_time_past', 'zoom');
}
// Make sure duration is positive and no more than 150 hours.
if ($data['duration'] <= 0) {
$errors['duration'] = get_string('err_duration_nonpositive', 'zoom');
} else if ($data['duration'] > 150 * 60 * 60) {
$errors['duration'] = get_string('err_duration_too_long', 'zoom');
}
}
return $errors;
}
}
/**
* Form to search for meeting reports.
*
* @package mod_zoom
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_zoom_report_form extends moodleform {
/**
* Define form elements.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('date_selector', 'from', get_string('from'));
$mform->addElement('date_selector', 'to', get_string('to'));
$mform->addElement('submit', 'submit', get_string('go'));
}
}