public function LearningPathAchievementTrait::getActivityStatus in Opigno Learning path 3.x
Gets a statuses of activities.
1 call to LearningPathAchievementTrait::getActivityStatus()
- StepsBlock::processActivityList in src/
Plugin/ Block/ StepsBlock.php - Converts a step array to a renderable array.
File
- src/
Traits/ LearningPathAchievementTrait.php, line 188
Class
- LearningPathAchievementTrait
- LearningPathAchievementTrait trait.
Namespace
Drupal\opigno_learning_path\TraitsCode
public function getActivityStatus($activities, $attempts, $module) : array {
if (!empty($attempts)) {
// If "newest" score - get the last attempt,
// else - get the best attempt.
$attempt = $this
->getTargetAttempt($attempts, $module);
}
else {
$attempt = NULL;
}
$user = $this
->currentUser();
/** @var \Drupal\opigno_module\Entity\OpignoActivity $activity */
/** @var \Drupal\opigno_module\Entity\OpignoAnswer $answer */
$array_map = [];
foreach ($activities as $key => $activity) {
$answer = isset($attempt) ? $activity
->getUserAnswer($module, $attempt, $user) : NULL;
if ($answer && $activity
->hasField('opigno_evaluation_method') && $activity
->get('opigno_evaluation_method')->value && !$answer
->isEvaluated()) {
$state_class = 'pending';
}
else {
$state_class = isset($answer) ? $answer
->isEvaluated() ? 'passed' : 'failed' : 'pending';
}
$array_map[$key] = $state_class;
}
return $array_map;
}