You are here

public static function LearningPathValidator::userHasPassed in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/LearningPathValidator.php \Drupal\opigno_learning_path\LearningPathValidator::userHasPassed()

Check if the user has passed all the conditions of a learning path.

1 call to LearningPathValidator::userHasPassed()
LearningPathStepsController::finish in src/Controller/LearningPathStepsController.php
Show the finish page and save the score.

File

src/LearningPathValidator.php, line 20

Class

LearningPathValidator
Class LearningPathValidator.

Namespace

Drupal\opigno_learning_path

Code

public static function userHasPassed($uid, Group $learning_path) {

  // Check if all the mandatory contents are okay
  // and if all the minimum score of the mandatories are good.
  $contents = LPManagedContent::loadByLearningPathId($learning_path
    ->id());
  foreach ($contents as $content) {

    // Get the minimum score required.
    $min_score = $content
      ->getSuccessScoreMin() / 100;

    // Compare the user score with the minimum score required.
    $content_type = $content
      ->getLearningPathContentType();
    $user_score = $content_type
      ->getUserScore($uid, $content
      ->getEntityId());

    // If the minimum score is no good, return FALSE.
    if ($user_score < $min_score) {
      return FALSE;
    }
  }

  // If all the scores are okay, return TRUE.
  return TRUE;
}