You are here

public function LpSteps::passedAttempts in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/LpSteps.php \Drupal\opigno_learning_path\LpSteps::passedAttempts()

Get list of passed attempts.

1 call to LpSteps::passedAttempts()
LpSteps::stepIsComplated in src/LpSteps.php
Get list of passed attempts.

File

src/LpSteps.php, line 467

Class

LpSteps

Namespace

Drupal\opigno_learning_path

Code

public function passedAttempts($options) {
  return array_filter($options['attempts'], function ($attempt) use ($options) {

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

    // Check that all actual module activities is evaluated.
    $evaluated = TRUE;
    $answered_count = 0;
    foreach ($options['activities'] as $activity) {
      $answer = $activity
        ->getUserAnswer($options['module'], $attempt, $options['user'], $options['latest_cert_date']);
      if ($answer === NULL) {
        $evaluated = FALSE;
      }
      else {
        $answered_count++;
      }
    }

    // For random Module option the number of answered activities
    // should be greater than number of random.
    if ($options['module']
      ->getRandomization() == 2) {
      if ($answered_count >= $options['module']
        ->getRandomActivitiesCount()) {
        $evaluated = TRUE;
      }
    }
    $score = $attempt
      ->getAttemptScore();
    return $evaluated && $score >= $options['required_score'];
  });
}