You are here

function _opigno_tincan_api_send_statement in Opigno TinCan API 7

Parameters

\TinCan\Statement $statement The statement to send.:

The variables 'opigno_tincan_api_*' will be used to send the statement to the LRS

8 calls to _opigno_tincan_api_send_statement()
opigno_tincan_api_h5p_statements_page in modules/opigno_tincan_api_h5p_statements/opigno_tincan_api_h5p_statements.module
Menu callback for JavaScript event relay.
opigno_tincan_api_in_house_training_statements_opigno_in_house_training_finished in modules/opigno_tincan_api_in_house_training_statements/opigno_tincan_api_in_house_training_statements.module
Implements hook_opigno_in_house_training_finished().
opigno_tincan_api_node_views_statements_node_view in modules/opigno_tincan_api_node_views_statements/opigno_tincan_api_node_views_statements.module
Implements hook_node_view(). This implementation will track every node that are viewed to the LRS
opigno_tincan_api_openbadges_statements_opigno_openbadge_assertion_created in modules/opigno_tincan_api_openbadges_statements/opigno_tincan_api_openbadges_statements.module
Implements hook_opigno_openbadge_assertion_created().
opigno_tincan_api_opigno_statements_opigno_course_passed in modules/opigno_tincan_api_opigno_statements/opigno_tincan_api_opigno_statements.module

... See full list

File

includes/opigno_tincan_api.statements_func.inc, line 199

Code

function _opigno_tincan_api_send_statement(TinCan\Statement $statement) {
  if (!_opigno_tincan_api_tincanphp_is_installed()) {
    return false;
  }
  $endpoint = variable_get('opigno_tincan_api_endpoint', '');
  $username = variable_get('opigno_tincan_api_username', '');
  $password = variable_get('opigno_tincan_api_password', '');
  if (empty($endpoint) || empty($username) || empty($password)) {
    return false;
  }
  $lrs = new TinCan\RemoteLRS($endpoint, '1.0.1', $username, $password);
  $response = $lrs
    ->saveStatement($statement);
  if ($response->success === false) {
    watchdog('Opigno Tincan API', 'The following statement could not be sent :<br />' . '<pre>' . print_r($statement
      ->asVersion('1.0.1'), true) . '</pre><br/>' . 'The response :<br />' . '<pre>' . print_r(json_decode($response->content), true) . '</pre>', array(), WATCHDOG_ERROR);
    return false;
  }
  return true;
}