示例#1
0
 /**
  * Make sure that we can handle the case if a user exists.
  */
 public function test_user_autocreate_existing()
 {
     // Force webservice to return existing user error.
     $this->makecallreturn = new moodle_exception('errorwebservice', 'mod_zoom', '', 'User already in the account: ' . $this->user->email);
     $result = $this->mockwebservice->user_autocreate($this->user);
     $this->assertTrue($result);
 }
 /**
  * Process the given restore path element data
  *
  * @param array $data parsed element data
  */
 protected function process_zoom($data)
 {
     global $DB;
     $data = (object) $data;
     $oldid = $data->id;
     $data->course = $this->get_courseid();
     if (empty($data->timemodified)) {
         $data->timemodified = time();
     }
     if ($data->grade < 0) {
         // Scale found, get mapping.
         $data->grade = -$this->get_mappingid('scale', abs($data->grade));
     }
     $service = new mod_zoom_webservice();
     // Either get updated info, create a new meeting, or set meeting as expired, whichever comes first.
     if ($service->get_meeting_info($data) || $service->meeting_create($data)) {
         $data = $service->lastresponse;
     } else {
         $data->status = ZOOM_MEETING_EXPIRED;
     }
     // Create the zoom instance.
     $newitemid = $DB->insert_record('zoom', $data);
     $this->apply_activity_instance($newitemid);
 }
示例#3
0
$event->add_record_snapshot($PAGE->cm->modname, $zoom);
$event->trigger();
// Print the page header.
$PAGE->set_url('/mod/zoom/view.php', array('id' => $cm->id));
$PAGE->set_title(format_string($zoom->name));
$PAGE->set_heading(format_string($course->fullname));
/*
 * Other things you may want to set - remove if not needed.
 * $PAGE->set_cacheable(false);
 * $PAGE->set_focuscontrol('some-html-id');
 * $PAGE->add_body_class('zoom-'.$somevar);
 */
$cache = cache::make('mod_zoom', 'zoomid');
if (!($zoomuserid = $cache->get($USER->id))) {
    $zoomuserid = false;
    $service = new mod_zoom_webservice();
    // Not an error if this fails, since people don't need a Zoom account to view/join meetings.
    if ($service->user_getbyemail($USER->email)) {
        $zoomuserid = $service->lastresponse->id;
    }
    $cache->set($USER->id, $zoomuserid);
}
$userishost = $zoomuserid == $zoom->host_id;
$stryes = get_string('yes');
$strno = get_string('no');
$strstart = get_string('start_meeting', 'mod_zoom');
$strjoin = get_string('join_meeting', 'mod_zoom');
$strunavailable = get_string('unavailable', 'mod_zoom');
$strtime = get_string('meeting_time', 'mod_zoom');
$strduration = get_string('duration', 'mod_zoom');
$strpassprotect = get_string('passwordprotected', 'mod_zoom');
示例#4
0
 /**
  * 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();
 }
示例#5
0
/**
 * 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;
}
示例#6
0
/**
 * Update local copy of zoom meetings by getting the latest Zoom data through the API.
 *
 * @param Traversable $zooms Traversable collection of zoom objects, perhaps from a recordset
 * (although this function does not close the recordset).
 */
function zoom_update_records(Traversable $zooms)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/course/lib.php';
    require_once $CFG->dirroot . '/lib/modinfolib.php';
    $service = new mod_zoom_webservice();
    $coursestoupdate = array();
    $calendar_fields = array('intro', 'introformat', 'start_time', 'duration', 'recurring');
    foreach ($zooms as $z) {
        if ($service->get_meeting_info($z)) {
            $response =& $service->lastresponse;
            // Check for changes.
            $changed = false;
            foreach ($z as $field => $value) {
                // The start_url has a parameter that always changes, so it doesn't really count as a change.
                if ($field != 'start_url' && $response->{$field} != $value) {
                    $changed = true;
                    break;
                }
            }
            if ($changed) {
                // Save in database.
                $response->timemodified = time();
                $DB->update_record('zoom', $response);
                // If the topic/title was changed, mark this course for cache clearing.
                if ($z->name != $response->name) {
                    $coursestoupdate[$z->course] = 1;
                }
                // Check if calendar needs updating.
                $calendar_changed = false;
                foreach ($calendar_fields as $field) {
                    if ($z->{$field} != $response->{$field}) {
                        $calendar_changed = true;
                    }
                }
                if ($calendar_changed) {
                    // Update calendar.
                    zoom_calendar_item_update($response);
                }
            }
        } else {
            $z->status = ZOOM_MEETING_EXPIRED;
            $DB->update_record('zoom', $z);
        }
    }
    // Clear caches for meetings whose topic/title changed (and rebuild as needed).
    foreach (array_flip($coursestoupdate) as $course) {
        rebuild_course_cache($course, true);
    }
}