You are here

public function DefaultTwigExtension::get_progress in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/TwigExtension/DefaultTwigExtension.php \Drupal\opigno_learning_path\TwigExtension\DefaultTwigExtension::get_progress()

Returns current user progress.

Return value

array|mixed|null Current user progress.

File

src/TwigExtension/DefaultTwigExtension.php, line 441

Class

DefaultTwigExtension
Class DefaultTwigExtension.

Namespace

Drupal\opigno_learning_path\TwigExtension

Code

public function get_progress($ajax = TRUE, $class = 'group-page', ?GroupInterface $group = NULL) {
  $group = $group ?: \Drupal::routeMatch()
    ->getParameter('group');
  if (!$group instanceof GroupInterface) {
    return [];
  }
  $account = \Drupal::currentUser();
  $member_pending = !LearningPathAccess::statusGroupValidation($group, $account);
  $required_trainings = LearningPathAccess::hasUncompletedRequiredTrainings($group, $account);

  // Don't display the progress not all required trainings completed or the
  // membership approval is needed.
  if ($member_pending || $required_trainings) {
    return [];
  }

  /** @var \Drupal\opigno_learning_path\Progress $progress_service */
  $progress_service = \Drupal::service('opigno_learning_path.progress');
  if ($ajax) {
    $content = $progress_service
      ->getProgressAjaxContainer($group
      ->id(), $account
      ->id(), '', $class);
  }
  else {
    $content = $progress_service
      ->getProgressBuild($group
      ->id(), $account
      ->id(), '', $class);
  }
  return $content;
}