public function LpSteps::stepIsComplated in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/LpSteps.php \Drupal\opigno_learning_path\LpSteps::stepIsComplated()
Get list of passed attempts.
Parameters
array $options: List of options.
numeric $last_attempt_score: Last Score
Return value
numeric When completed.
1 call to LpSteps::stepIsComplated()
- LpSteps::getModuleStep in src/
LpSteps.php - Get list of module steps.
File
- src/
LpSteps.php, line 509
Class
Namespace
Drupal\opigno_learning_pathCode
public function stepIsComplated(array $options, &$last_attempt_score = NULL) {
$passed_attempts = $this
->passedAttempts($options);
$moduleHandler = \Drupal::service('module_handler');
$completed_on = 0;
if ($options['module']
->getKeepResultsOption() == 'newest') {
// Get finish date of the last attempt if passed.
$last_passed_attempt = end($passed_attempts);
$last_attempt = end($options['attempts']);
if (!empty($last_attempt) && $last_passed_attempt == $last_attempt) {
$completed_on = $last_attempt
->get('finished')
->getString();
}
}
elseif ($moduleHandler
->moduleExists('opigno_skills_system') && $options['module']
->getSkillsActive() && !empty($options['last_attempt'])) {
if ($options['last_attempt']
->isFinished()) {
$completed_on = $options['last_attempt']
->get('finished')
->getString();
}
// Add cheat for skills modules to jump to the next module if the user already has needed skills.
if ($options['last_attempt']
->getScore() > $options['last_attempt_score']) {
$last_attempt_score = $options['last_attempt']
->getScore();
if ($completed_on == 0) {
$completed_on = $options['last_attempt']
->get('finished')
->getString();
}
}
}
else {
// Get finish date of the first attempt that has passed.
$completed_on = !empty($passed_attempts) ? min(array_map(function ($attempt) {
/** @var \Drupal\opigno_module\Entity\UserModuleStatus $attempt */
return (int) $attempt
->get('finished')
->getString();
}, $passed_attempts)) : 0;
// Check if the module contains manually evaluated activities.
if (!empty($activities)) {
foreach ($activities as $activity) {
if ($activity
->hasField('opigno_evaluation_method') && $activity
->get('opigno_evaluation_method')->value) {
// Set current attempt score.
$last_attempt_score = $options['actual_score'];
break;
}
}
}
}
return $completed_on;
}