You are here

function opigno_learning_path_best_attempt in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 opigno_learning_path.module \opigno_learning_path_best_attempt()

Select best attempt from list.

Parameters

array $attempts: List of attempts.

Return value

object Best Attempt.

5 calls to opigno_learning_path_best_attempt()
LearningPathAchievementController::getTargetAttempt in src/Controller/LearningPathAchievementController.php
Get last or best user attempt for Module.
LearningPathAchievementTrait::getTargetAttempt in src/Traits/LearningPathAchievementTrait.php
Get last or best user attempt for Module.
LearningPathStepsController::getTargetAttempt in src/Controller/LearningPathStepsController.php
Get last or best user attempt for Module.
opigno_learning_path_get_all_steps in ./opigno_learning_path.module
Builds up a full list of all the steps in a group for a user.
opigno_learning_path_get_steps in ./opigno_learning_path.module
Builds up a list of steps in a group for a user.

File

./opigno_learning_path.module, line 2722
Contains opigno_learning_path.module.

Code

function opigno_learning_path_best_attempt(array $attempts) {
  usort($attempts, function ($a, $b) {

    /** @var \Drupal\opigno_module\Entity\UserModuleStatus $a */

    /** @var \Drupal\opigno_module\Entity\UserModuleStatus $b */
    $b_score = $b
      ->getAttemptScore();
    $a_score = $a
      ->getAttemptScore();
    return $b_score - $a_score;
  });
  return reset($attempts);
}