public function ContentTypeILT::getUserScore in Opigno Instructor-led Trainings 8
Same name and namespace in other branches
- 3.x src/Plugin/OpignoGroupManagerContentType/ContentTypeILT.php \Drupal\opigno_ilt\Plugin\OpignoGroupManagerContentType\ContentTypeILT::getUserScore()
Get the score of the user for a specific entity.
Parameters
int $user_id: The user ID.
int $entity_id: The entity ID.
Return value
float|false The score between 0 and 1. FALSE if no score found.
Overrides ContentTypeInterface::getUserScore
File
- src/
Plugin/ OpignoGroupManagerContentType/ ContentTypeILT.php, line 38
Class
- ContentTypeILT
- Class ContentTypeILT.
Namespace
Drupal\opigno_ilt\Plugin\OpignoGroupManagerContentTypeCode
public function getUserScore($user_id, $entity_id) {
/** @var \Drupal\opigno_ilt\ILTResultInterface[] $results */
$results = \Drupal::entityTypeManager()
->getStorage('opigno_ilt_result')
->loadByProperties([
'user_id' => $user_id,
'opigno_ilt' => $entity_id,
]);
$best_score = 0;
foreach ($results as $result) {
$score = $result
->getScore();
if ($score > $best_score) {
$best_score = $score;
}
}
return $best_score / 100;
}