You are here

protected function LearningPathAchievementController::build_course_steps in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/Controller/LearningPathAchievementController.php \Drupal\opigno_learning_path\Controller\LearningPathAchievementController::build_course_steps()

Returns course steps renderable array.

Parameters

\Drupal\group\Entity\GroupInterface $training: Parent training group entity.

\Drupal\group\Entity\GroupInterface $course: Course group entity.

Return value

array Course steps renderable array.

1 call to LearningPathAchievementController::build_course_steps()
LearningPathAchievementController::trainingStepCourseBuild in src/Controller/LearningPathAchievementController.php
If step is course prepares a render array of content.

File

src/Controller/LearningPathAchievementController.php, line 526

Class

LearningPathAchievementController
Class LearningPathAchievementController.

Namespace

Drupal\opigno_learning_path\Controller

Code

protected function build_course_steps(GroupInterface $training, GroupInterface $course) {
  $user = $this
    ->currentUser();
  $steps = opigno_learning_path_get_steps($course
    ->id(), $user
    ->id());

  // Get training latest certification timestamp.
  $latest_cert_date = LPStatus::getTrainingStartDate($training, $user
    ->id());
  $steps = array_map(static function ($step) use ($user, $latest_cert_date) {
    $step['status'] = opigno_learning_path_get_step_status($step, $user
      ->id(), TRUE, $latest_cert_date);
    $step['attempted'] = opigno_learning_path_is_attempted($step, $user
      ->id());
    $step['progress'] = opigno_learning_path_get_step_progress($step, $user
      ->id(), FALSE, $latest_cert_date);
    return $step;
  }, $steps);
  $course_steps = array_map(function ($step) use ($training, $course, $user, $latest_cert_date) {
    $time_spent = $this
      ->getTimeSpentByStep($step);
    $completed = $this
      ->getComplitedByStep($step);
    $time_spent = $time_spent ? $this->dateFormatter
      ->formatInterval($time_spent) : 0;
    $completed = $completed ? $this->dateFormatter
      ->format($completed, 'custom', 'm/d/Y') : '';
    list($approved, $approved_percent) = $this
      ->getApprovedModuleByStep($step, $user, $latest_cert_date, $training);
    $badges = $this
      ->getModulesStatusBadges($step, $training, $user
      ->id());

    /** @var \Drupal\opigno_module\Entity\OpignoModule $module */
    $module = OpignoModule::load($step['id']);
    return [
      '#theme' => 'opigno_learning_path_training_module',
      '#status' => $this
        ->mapStatusToTemplateClasses($step['status']),
      '#group_id' => $course
        ->id(),
      '#step' => $step,
      '#time_spent' => $time_spent,
      '#completed' => $completed,
      '#badges' => $badges,
      '#approved' => [
        'value' => $approved,
        'percent' => $approved_percent,
      ],
      '#activities' => $this
        ->build_module_panel($training, $course, $module),
    ];
  }, $steps);
  return [
    '#theme' => 'opigno_learning_path_training_course_content',
    '#course_id' => $course
      ->id(),
    $course_steps,
  ];
}