You are here

public function LearningPathStepsController::contentSteps in Opigno Learning path 3.x

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

Steps.

1 string reference to 'LearningPathStepsController::contentSteps'
opigno_learning_path.routing.yml in ./opigno_learning_path.routing.yml
opigno_learning_path.routing.yml

File

src/Controller/LearningPathStepsController.php, line 670

Class

LearningPathStepsController
Class LearningPathStepsController.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function contentSteps(Group $group, $current) {

  // Check if user has uncompleted steps.
  LearningPathValidator::stepsValidate($group);

  // Get group type.
  $type = opigno_learning_path_get_group_type();

  // Get all steps.
  $all_steps = opigno_learning_path_get_routes_steps();

  // Get unique steps numbers.
  $unique_steps = array_unique($all_steps);

  // Get next step.
  $next_step = $current < count($unique_steps) ? $current + 1 : NULL;

  // If last step.
  if (!$next_step) {
    if ($type == 'learning_path') {
      return $this
        ->redirect('opigno_learning_path.manager.publish', [
        'group' => $group
          ->id(),
      ]);
    }
    else {

      // For courses and classes.
      return $this
        ->redirect('entity.group.canonical', [
        'group' => $group
          ->id(),
      ]);
    }
  }
  else {
    if ($type == 'learning_path') {

      // Check for existing courses in the LP.
      // If there are no courses - skip courses step.
      $group_courses = $group
        ->getContent('subgroup:opigno_course');
      if ($current == 2 && empty($group_courses)) {
        $next_step++;
      }
    }

    // For all group types.
    $route = array_search($next_step, opigno_learning_path_get_routes_steps());
    return $this
      ->redirect($route, [
      'group' => $group
        ->id(),
    ]);
  }
}