/**
  * 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);
 }
Example #2
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);
    }
}