You are here

function _opigno_moxtra_upcoming_live_meetings in Opigno Moxtra 8

Same name and namespace in other branches
  1. 3.x opigno_moxtra.module \_opigno_moxtra_upcoming_live_meetings()

Returns upcoming live meetings.

Parameters

\Drupal\user\UserInterface $user: User.

Return value

\Drupal\opigno_moxtra\MeetingInterface[] Upcoming live meetings.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

./opigno_moxtra.module, line 210
Contains opigno_moxtra.module.

Code

function _opigno_moxtra_upcoming_live_meetings(UserInterface $user) {
  if (!_opigno_moxtra_is_active() || $user
    ->isAnonymous()) {
    return [];
  }
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $now = DrupalDateTime::createFromTimestamp($timestamp);
  $now_str = $now
    ->format(DrupalDateTime::FORMAT);
  $moxtra_api = _opigno_moxtra_get_moxtra_api();
  $user_id = $user
    ->id();
  $meetings_list = [];

  // Load upcoming meeting.
  $meetings_ids = \Drupal::entityTypeManager()
    ->getStorage('opigno_moxtra_meeting')
    ->getQuery()
    ->condition('date__value', $now_str, '>')
    ->execute();
  $meetings = Meeting::loadMultiple($meetings_ids);
  foreach ($meetings as $meeting) {
    $group_id = $meeting
      ->getTrainingId();
    if (!empty($group_id)) {
      $group = Group::load($meeting
        ->getTrainingId());
      $members_ids = $meeting
        ->getMembersIds();
      $owner_id = $meeting
        ->getOwnerId();
      $session_key = $meeting
        ->getSessionKey();
    }
    if (isset($session_key)) {
      $info = $moxtra_api
        ->getMeetingInfo($owner_id, $session_key);
      $status = !empty($info['data']) ? $info['data']['status'] : FALSE;
    }
    if (!empty($group) && $group instanceof Group && $group
      ->getMember($user) && isset($session_key) && (empty($members_ids) || in_array($user_id, $members_ids)) && $status != 'SESSION_ENDED') {
      $meetings_list[$meeting
        ->id()] = $meeting;
    }
  }
  return $meetings_list;
}