You are here

public function LearningPathStepsController::finish 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::finish()

Show the finish page and save the score.

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

File

src/Controller/LearningPathStepsController.php, line 640

Class

LearningPathStepsController
Class LearningPathStepsController.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function finish(Group $group) {

  // Get the "user passed" status.
  $current_uid = \Drupal::currentUser()
    ->id();
  $user_passed = LearningPathValidator::userHasPassed($current_uid, $group);
  if ($user_passed) {

    // Store the result in database.
    $current_result_attempt = LPResult::getCurrentLPAttempt($group, \Drupal::currentUser());
    if ($current_result_attempt) {
      $current_result_attempt
        ->setHasPassed($user_passed);
      $current_result_attempt
        ->setFinished(\Drupal::time()
        ->getRequestTime());
      $current_result_attempt
        ->save();
    }
    else {

      // Store the result in database.
      $result = LPResult::createWithValues($group
        ->id(), $current_uid, $user_passed, \Drupal::time()
        ->getRequestTime());
      $result
        ->save();
    }
    return $this
      ->failedStep('passed');
  }
  else {
    return $this
      ->failedStep('failed');
  }
}