You are here

function opigno_learning_path_is_passed in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x 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()
LearningPathAchievementController::build_training_timeline in src/Controller/LearningPathAchievementController.php
Returns training timeline.
opigno_learning_path_save_achievements in ./opigno_learning_path.module
Stores training achievements data.
Progress::getProgressBuildAchievementsPage in src/Progress.php
Get get progress for achievements page.
Progress::getProgressBuildGroupPage in src/Progress.php
Get get progress for group page.
StepsBlock::build in src/Plugin/Block/StepsBlock.php
Builds and returns the renderable array for this block plugin.

File

./opigno_learning_path.module, line 3274
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);
}