You are here

protected function TincanContentAnswerAssistant::getLrsConnection 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::getLrsConnection()

This method returns the connection to the LRS.

If there is a problem, this method will show an error message and return FALSE.

Return value

bool|\TinCan\RemoteLRS FALSE in case of error. The LRS connection if connection was success.

1 call to TincanContentAnswerAssistant::getLrsConnection()
TincanContentAnswerAssistant::getScoreFromLrs in ActivityTypes/opigno_tincan_activity/src/TincanContentAnswerAssistant.php
This method will return the score from the LRS system for this response.

File

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

Class

TincanContentAnswerAssistant
Class TincanContentAnswerAssistant.

Namespace

Drupal\opigno_tincan_activity

Code

protected function getLrsConnection() {

  // Check first if the TinCanPHP library is installed
  // If not, return FALSE.
  $messenger = \Drupal::messenger();
  if (!class_exists('TinCan\\Version')) {
    $messenger
      ->addError('Please install the @tincanphp_library using Composer, with the command: <em>composer require rusticisoftware/tincan:@stable</em>.', [
      '@tincanphp_library' => Link::fromTextAndUrl('TinCanPHP library', Url::fromUri('https://github.com/RusticiSoftware/TinCanPHP')),
    ]);
    return FALSE;
  }
  $config = \Drupal::config('opigno_tincan_api.settings');
  $endpoint = $config
    ->get('opigno_tincan_api_endpoint');
  $username = $config
    ->get('opigno_tincan_api_username');
  $password = $config
    ->get('opigno_tincan_api_password');
  if (empty($endpoint) || empty($username) || empty($password)) {
    $messenger
      ->addWarning('Please configure first the Opigno TinCan API module. Go to @url', [
      '@url' => Link::createFromRoute(t('the setting page'), 'opigno_tincan_api.settings_form')
        ->toString(),
    ]);
    return FALSE;
  }
  return new RemoteLRS($endpoint, '1.0.1', $username, $password);
}