You are here

protected function TincanContentAnswerAssistant::getScoreFromLrs in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_tincan_activity/src/TincanContentAnswerAssistant.php \Drupal\opigno_tincan_activity\TincanContentAnswerAssistant::getScoreFromLrs()

This method will return the score from the LRS system for this response.

Parameters

string $activity_id: Tincan activity id.

string $registration: UUID registration.

int $max_score: Max score for activity.

Return value

int The score not weighted.

1 call to TincanContentAnswerAssistant::getScoreFromLrs()
TincanContentAnswerAssistant::score in ActivityTypes/opigno_tincan_activity/src/TincanContentAnswerAssistant.php

File

ActivityTypes/opigno_tincan_activity/src/TincanContentAnswerAssistant.php, line 132

Class

TincanContentAnswerAssistant
Class TincanContentAnswerAssistant.

Namespace

Drupal\opigno_tincan_activity

Code

protected function getScoreFromLrs($activity_id, $registration, $max_score) {
  $messenger = \Drupal::messenger();

  // First, try to get the connection.
  $lrs = $this
    ->getLrsConnection();
  if (!$lrs) {
    $messenger
      ->addWarning(t('Connection to the LRS failed'));
    return 0;
  }

  // If we have the connection, get the statement.
  if (empty($registration)) {
    $messenger
      ->addWarning(t('There was an error while answering the question, please go back and try again.'));
    return 0;
  }
  if (empty($activity_id)) {
    $messenger
      ->addWarning(t('Error while obtaining the activity ID. Maybe a malformed TinCan package.'));
    return 0;
  }
  $score_statement = $this
    ->getStatementFinalScore($lrs, $registration, $activity_id);
  if (!$score_statement) {
    $messenger
      ->addWarning(t('Can not get score from LRS. Check your LRS settings.'));
    return 0;
  }

  // If we have the statement, extract the score and returns it.
  return $this
    ->getScoreFromStatement($score_statement, $max_score);
}