You are here

public function Progress::getProgressAjaxContainer in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Progress.php \Drupal\opigno_learning_path\Progress::getProgressAjaxContainer()

Get html container where progress will be loaded via ajax.

Parameters

int $group_id: Group ID.

int $uid: User ID.

int $latest_cert_date: Latest certification date.

string $class: identifier for progress bar.

Return value

array Renderable array.

File

src/Progress.php, line 128

Class

Progress
Class JoinService.

Namespace

Drupal\opigno_learning_path

Code

public function getProgressAjaxContainer($group_id, $account_id, $latest_cert_date = '', $class = 'basic') {
  if (!$latest_cert_date) {
    $group = Group::load($group_id);
    $latest_cert_date = LPStatus::getTrainingStartDate($group, $account_id);
  }

  // If latest_cert_date is empty we just set 0 to avoid any errors for empty args.
  if (!$latest_cert_date) {
    $latest_cert_date = 0;
  }

  // Maybe in some cases we need to have pre-loaded progress bar without ajax.
  // An example unit tests or so.
  $preload = $this->requestStack
    ->getCurrentRequest()->query
    ->get('preload-progress');
  if ($preload) {
    return $this
      ->getProgressBuild($group_id, $account_id, $latest_cert_date, $class);
  }

  // HTML structure for ajax comntainer.
  return [
    '#theme' => 'opigno_learning_path_progress_ajax_container',
    '#group_id' => $group_id,
    '#account_id' => $account_id,
    '#latest_cert_date' => $latest_cert_date,
    '#class' => $class,
    '#attached' => [
      'library' => [
        'opigno_learning_path/progress',
      ],
    ],
  ];
}