public function OpignoModule::getBestScore in Opigno module 8
Same name and namespace in other branches
- 3.x src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::getBestScore()
Get module attempt if user didn't finish training.
Parameters
\Drupal\user\Entity\User $user: User entity.
Return value
numeric Best score result.
File
- src/
Entity/ OpignoModule.php, line 533
Class
- OpignoModule
- Defines the Module entity.
Namespace
Drupal\opigno_module\EntityCode
public function getBestScore(User $user) {
// For each attempt, check the score and save the best one.
$user_attempts = $this
->getModuleAttempts($user, 'best');
$best_score = 0;
/* @var \Drupal\opigno_module\Entity\UserModuleStatus $user_attempt */
foreach ($user_attempts as $user_attempt) {
// Get the scores.
$actual_score = $user_attempt
->getAttemptScore();
// Save the best score.
if ($actual_score > $best_score) {
$best_score = $actual_score;
}
}
return $best_score;
}