You are here

public function LearningPathAchievementController::getApprovedModuleByStep in Opigno Learning path 3.x

Gets an approved state by the step.

Copy of legacy code.

2 calls to LearningPathAchievementController::getApprovedModuleByStep()
LearningPathAchievementController::build_course_steps in src/Controller/LearningPathAchievementController.php
Returns course steps renderable array.
LearningPathAchievementController::trainingStepModuleBuild in src/Controller/LearningPathAchievementController.php
If step is module prepares a render array of content.

File

src/Controller/LearningPathAchievementController.php, line 628

Class

LearningPathAchievementController
Class LearningPathAchievementController.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function getApprovedModuleByStep(&$step, $user, $latest_cert_date, $group) : array {
  $module = OpignoModule::load($step['id']);
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('opigno_skills_system') && $module
    ->getSkillsActive()) {
    $attempts = $module
      ->getModuleAttempts($user, NULL, $latest_cert_date);
    $attempt = $this
      ->getTargetAttempt($attempts, $module);
    $account = User::load($attempt
      ->getOwnerId());
    $answers = $module
      ->userAnswers($account, $attempt);
    $count_answers_from_step = count($answers);
    $approved = $count_answers_from_step . '/' . $count_answers_from_step;
    $approved_percent = 100;
    $step['progress'] = 1;
  }
  else {
    $approved_activities = $this
      ->module_approved_activities($group
      ->id(), $step['id'], $latest_cert_date, $user);
    $approved = $approved_activities . '/' . $step['activities'];
    $approved_percent = $approved_activities / $step['activities'] * 100;
  }
  return [
    $approved ?? 0,
    $approved_percent ?? 0,
  ];
}