You are here

public function UserModuleStatus::getAttemptScore in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Entity/UserModuleStatus.php \Drupal\opigno_module\Entity\UserModuleStatus::getAttemptScore()

Get Attempt Score.

File

src/Entity/UserModuleStatus.php, line 280

Class

UserModuleStatus
Defines the User module status entity.

Namespace

Drupal\opigno_module\Entity

Code

public function getAttemptScore() {
  $score = (int) $this
    ->calculateScore();
  $max_score = (int) $this
    ->calculateMaxScore();
  if ($max_score <= 0) {
    return 0;
  }

  // Clamp score.
  $score = max(0, $score);
  $score = min($max_score, $score);

  // Convert absolute values to percent.
  return round(100 * $score / $max_score);
}