/** * Removes an instance of the zoom from the database * * Given an ID of an instance of this module, * this function will permanently delete the instance * and any data that depends on it. * * @param int $id Id of the module instance * @return boolean Success/Failure * @throws moodle_exception if failed to delete and zoom * did not issue a not found/expired error */ function zoom_delete_instance($id) { global $CFG, $DB; require_once $CFG->dirroot . '/mod/zoom/classes/webservice.php'; if (!($zoom = $DB->get_record('zoom', array('id' => $id)))) { return false; } // Include locallib.php for constants. require_once $CFG->dirroot . '/mod/zoom/locallib.php'; // Delete any dependent records here. // Status -1 means expired and missing from zoom. // So don't bother with the webservice in this case. if ($zoom->status !== ZOOM_MEETING_EXPIRED) { $service = new mod_zoom_webservice(); if (!$service->meeting_delete($zoom)) { zoom_print_error('meeting/delete', $service->lasterror); } } $DB->delete_records('zoom', array('id' => $zoom->id)); zoom_calendar_item_delete($zoom); zoom_grade_item_delete($zoom); return true; }
/** * Defines forms elements */ public function definition() { global $USER; $service = new mod_zoom_webservice(); if (!$service->user_getbyemail($USER->email)) { zoom_print_error('user/getbyemail', $service->lasterror); } $zoomuser = $service->lastresponse; $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($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(); }
/** * Get the Zoom id of the currently logged-in user. * * @return string */ function zoom_get_user_id() { global $USER; $service = new mod_zoom_webservice(); if (!$service->user_getbyemail($USER->email)) { zoom_print_error('user/getbyemail', $service->lasterror); } return $service->lastresponse->id; }