function opigno_learning_path_get_score in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 opigno_learning_path.module \opigno_learning_path_get_score()
Calculates learning path score.
Parameters
int $gid: Training group ID.
int $uid: User ID.
bool $current_attempt: Current attempt flag.
int $latest_cert_date: Latest certification date.
Return value
int Score.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
3 calls to opigno_learning_path_get_score()
- opigno_learning_path_save_achievements in ./
opigno_learning_path.module - Stores training achievements data.
- Progress::getProgressBuildAchievementsPage in src/
Progress.php - Get get progress for achievements page.
- Progress::getProgressBuildGroupPage in src/
Progress.php - Get get progress for group page.
File
- ./
opigno_learning_path.module, line 3341 - Contains opigno_learning_path.module.
Code
function opigno_learning_path_get_score($gid, $uid, $current_attempt = FALSE, $latest_cert_date = NULL) {
$steps = !$current_attempt ? opigno_learning_path_get_steps($gid, $uid, NULL, $latest_cert_date) : opigno_learning_path_get_steps_current_attempt($gid, $uid);
$mandatory_steps = array_filter($steps, function ($step) {
return $step['mandatory'];
});
if (!empty($mandatory_steps)) {
$score = round(array_sum(array_map(function ($step) {
return $step['best score'];
}, $mandatory_steps)) / count($mandatory_steps));
}
else {
$score = 0;
}
return $score;
}