You are here

function _opigno_ilt_upcoming in Opigno Instructor-led Trainings 8

Same name and namespace in other branches
  1. 3.x opigno_ilt.module \_opigno_ilt_upcoming()

Returns upcoming ILTs.

Parameters

\Drupal\user\UserInterface $user: User.

Return value

\Drupal\opigno_ilt\ILTInterface[] Upcoming ILTs.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

./opigno_ilt.module, line 53
Contains opigno_ilt.module.

Code

function _opigno_ilt_upcoming(UserInterface $user) {
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $now = DrupalDateTime::createFromTimestamp($timestamp);
  $now_str = $now
    ->format(DrupalDateTime::FORMAT);
  $user_id = $user
    ->id();

  // Load upcoming meeting.
  $ilts_ids = \Drupal::entityTypeManager()
    ->getStorage('opigno_ilt')
    ->getQuery()
    ->condition('date__value', $now_str, '>')
    ->execute();
  $ilts_list = ILT::loadMultiple($ilts_ids);
  foreach ($ilts_list as $ilt) {
    $group = Group::load($ilt
      ->getTrainingId());
    if ($group instanceof Group && $group
      ->getMember($user) && $ilt
      ->isMember($user_id)) {
      $ilts[$ilt
        ->id()] = $ilt;
    }
  }
  return $ilts ?? [];
}