You are here

function zoomapi_track_meeting in Zoom API 7

Same name and namespace in other branches
  1. 7.2 zoomapi.module \zoomapi_track_meeting()

Track meeting information.

Parameters

array $meeting: The meeting array provided by Zoom.

3 calls to zoomapi_track_meeting()
zoomapi_meeting_create in ./zoomapi.module
Create Meeting.
zoomapi_meeting_create_for_entity in ./zoomapi.module
Create Meeting for Entity.
zoomapi_meeting_create_instant_meeting in ./zoomapi.module
Create Instant Meeting for Account.

File

./zoomapi.module, line 667
Main file for the Zoom API module.

Code

function zoomapi_track_meeting(array $meeting) {
  $record = [
    'uuid' => $meeting['uuid'],
    'meeting_id' => $meeting['id'],
    'host_zoom_user_id' => $meeting['host_id'],
    'topic' => $meeting['topic'],
    'meeting_type' => $meeting['type'],
    'start_time' => !empty($meeting['start_time']) ? strtotime($meeting['start_time']) : 0,
    'duration' => !empty($meeting['duration']) ? $meeting['duration'] : 0,
    'timezone' => !empty($meeting['timezone']) ? $meeting['timezone'] : '',
    'start_url' => $meeting['start_url'],
    'join_url' => $meeting['join_url'],
    'created' => time(),
    'entity_type' => !empty($meeting['entity_type']) ? $meeting['entity_type'] : '',
    'entity_id' => !empty($meeting['entity_id']) ? $meeting['entity_id'] : 0,
    // Default record expires after 24 hrs.
    'expires' => strtotime('+24 hours'),
    'data' => serialize($meeting),
  ];

  // If the start time and duration is found, then expire the record several
  // hours after the meeting is set to end.
  if (!empty($record['start_time']) && !empty($record['duration'])) {
    $record['expires'] = $record['start_time'] + $record['duration'] + 2 * 60 * 60;
  }

  // There should not be multiple instant meetings for the same host account.
  // While not performing a logic check here to stop that, we do want to at
  // least eliminate any existing instant records for that host. This will avoid
  // any potential look ups later to find an account's instant meeting.
  if ($record['meeting_type'] == ZOOMAPI_MEETING_TYPE_INSTANT) {
    $num_deleted = db_delete('zoomapi_meeting_tracker')
      ->condition('host_zoom_user_id', $record['host_zoom_user_id'])
      ->condition('meeting_type', ZOOMAPI_MEETING_TYPE_INSTANT)
      ->execute();
    if ($num_deleted && variable_get('zoomapi_debug', FALSE)) {
      watchdog('zoomapi_debug', 'Removed !count existing instant meeting tracker for host_id !host_id', [
        '!count' => $num_deleted,
        '!host_id' => $record['host_zoom_user_id'],
      ], WATCHDOG_DEBUG);
    }
  }

  // There should only be one meeting per entity_type/entity_id. While not
  // performing logic check here, at least make sure table only has one record.
  if (!empty($record['entity_type']) && !empty($record['entity_id'])) {

    // At this time do not delete the record and instead check to see if one
    // already exists.
    if (variable_get('zoomapi_debug', FALSE)) {
      $count = db_query('SELECT count(uuid) FROM {zoomapi_meeting_tracker} WHERE entity_type = :entity_type AND entity_id = :entity_id', [
        ':entity_type' => $record['entity_type'],
        ':entity_id' => $record['entity_id'],
      ])
        ->rowCount();
      if ($count) {
        watchdog('zoomapi_debug', '!count zoomapi_meeting_tracker records already exist for entity_type !entity_type entity_id !entity_id', [
          '!count' => $count,
          '!entity_type' => $record['entity_type'],
          '!entity_id' => $record['entity_id'],
        ], WATCHDOG_DEBUG);
      }
    }

    // @todo
    // Do we need to do this?
    if (FALSE) {
      db_delete('zoomapi_meeting_tracker')
        ->condition('entity_type', $record['entity_type'])
        ->condition('entity_id', $record['entity_id'])
        ->execute();
    }
  }
  db_merge('zoomapi_meeting_tracker')
    ->key([
    'uuid' => $record['uuid'],
  ])
    ->fields($record)
    ->execute();
}