You are here

protected function OpignoTincanQuestionTypeResponse::getScoreFromStatement in Opigno TinCan Question Type 7

This method calculate the score using a statement.

Parameters

Statement $statement: The statement that contains the score.

Return value

float|int The final score ready to be returned for the Quiz module. Can returns 0 if the score is not found in the statement.

1 call to OpignoTincanQuestionTypeResponse::getScoreFromStatement()
OpignoTincanQuestionTypeResponse::getScoreFromLrs in includes/opigno_tincan_question_type.response.inc
This method will return the score from the LRS system for this response.

File

includes/opigno_tincan_question_type.response.inc, line 337
This file contains the class OpignoTincanQuestionTypeResponse.

Class

OpignoTincanQuestionTypeResponse
This class goal is to manage the user's answer(s).

Code

protected function getScoreFromStatement(Statement $statement) {
  $result = $statement
    ->getResult();
  if (!isset($result)) {
    return 0;
  }
  $score = $result
    ->getScore();
  if (isset($score)) {
    $scaled = $score
      ->getScaled();
    if (isset($scaled) && $scaled >= 0) {
      return $scaled * OpignoTincanQuestionTypeQuestion::SCORE_MAX;
    }
    $raw = $score
      ->getRaw();
    $max = $score
      ->getMax();
    $min = $score
      ->getMin();
    if (!isset($min)) {
      $min = 0;
    }
    if (isset($raw) && isset($max)) {
      return (double) ($raw - $min) / ($max - $min) * OpignoTincanQuestionTypeQuestion::SCORE_MAX;
    }
  }
  $success = $result
    ->getSuccess();
  if (isset($success)) {
    return OpignoTincanQuestionTypeQuestion::SCORE_MAX;
  }
  return 0;
}