You are here

function opigno_learning_path_is_passed in Opigno Learning path 3.x

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

Returns LP passed flag.

Parameters

array|\Drupal\group\Entity\GroupInterface $step: Learning Path or Course Group entity, or step array, returned by opigno_learning_path_get_steps()

int $uid: User ID.

bool $current_attempt: Current attempt flag.

Return value

bool LP passed flag.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

5 calls to opigno_learning_path_is_passed()
DefaultTwigExtension::get_start_link in src/TwigExtension/DefaultTwigExtension.php
Returns group start link.
LearningPathAchievementController::build_training_timeline in src/Controller/LearningPathAchievementController.php
Returns training timeline.
Progress::buildSummary in src/Progress.php
Progress::getProgressBuildAchievementsPage in src/Progress.php
Get get progress for achievements page.
Progress::getProgressBuildGroupPage in src/Progress.php
Get get progress for group page.

File

./opigno_learning_path.module, line 3183
Contains opigno_learning_path.module.

Code

function opigno_learning_path_is_passed($step, $uid, $current_attempt = FALSE) {
  if (is_array($step)) {
    if ($step['typology'] === 'Course') {
      $steps = !$current_attempt ? opigno_learning_path_get_steps($step['id'], $uid) : opigno_learning_path_get_steps_current_attempt($step['id'], $uid);
    }
    else {
      return opigno_learning_path_is_attempted($step, $uid) && $step['completed on'] > 0 && $step['best score'] >= $step['required score'];
    }
  }
  else {
    $steps = !$current_attempt ? opigno_learning_path_get_steps($step
      ->id(), $uid) : opigno_learning_path_get_steps_current_attempt($step
      ->id(), $uid);

    // Check only mandatory steps.
    $steps = array_filter($steps, function ($step) {
      return $step['mandatory'];
    });
  }

  // Not passed, if haven't steps.
  if (empty($steps)) {
    return FALSE;
  }
  $steps = array_filter($steps, function ($step) use ($uid, $current_attempt) {
    return !opigno_learning_path_is_passed($step, $uid, $current_attempt);
  });

  // If all steps has passed.
  return empty($steps);
}