You are here

protected function OpignoTincanLiveMeeting::createAndSendTincanStatementsForMeeting in Opigno TinCan API 8

Same name and namespace in other branches
  1. 3.x modules/opigno_tincan_live_meeting/src/EventSubscriber/OpignoTincanLiveMeeting.php \Drupal\opigno_tincan_live_meeting\EventSubscriber\OpignoTincanLiveMeeting::createAndSendTincanStatementsForMeeting()

Sends tincan statements for Live meeting.

Parameters

\Drupal\opigno_moxtra\Entity\Meeting $meeting: Meeting.

array $response_data: Response data.

Throws

\Exception

1 call to OpignoTincanLiveMeeting::createAndSendTincanStatementsForMeeting()
OpignoTincanLiveMeeting::tincanLiveMeeting in modules/opigno_tincan_live_meeting/src/EventSubscriber/OpignoTincanLiveMeeting.php
Called whenever the tincanLiveMeeting event is dispatched.

File

modules/opigno_tincan_live_meeting/src/EventSubscriber/OpignoTincanLiveMeeting.php, line 140

Class

OpignoTincanLiveMeeting
Class OpignoTincanLiveMeeting.

Namespace

Drupal\opigno_tincan_live_meeting\EventSubscriber

Code

protected function createAndSendTincanStatementsForMeeting(Meeting $meeting, array $response_data) {

  /****
   * - When user attended a live meeting
   * Actor: user
   * Verb: xAPI/attended
   * Object: xAPI/meeting
   * Context: Training
   */

  // Statement creation.
  $statement = OpignoTinCanApiStatements::statementBaseCreation(OpignoTincanApiTinCanVerbs::$attended, OpignoTincanApiTinCanActivityDefinitionTypes::$meeting, $meeting);
  if ($statement === FALSE) {
    return;
  }

  // Context creation.
  $context = new Context();

  // Get group.
  $group = $meeting
    ->getTraining();
  $parent_ids = [
    $group
      ->id(),
  ];
  OpignoTinCanApiStatements::contextSetGrouping($context, $parent_ids);

  // Set language in context.
  OpignoTinCanApiStatements::contextSetLanguage($context, $meeting
    ->language()
    ->getId());

  // Get duration.
  $start_date = $response_data['data']['starts'];
  $end_date = $response_data['data']['ends'];
  $duration_s = strtotime($end_date) - strtotime($start_date);

  // Set result.
  OpignoTinCanApiStatements::setResult($statement, NULL, NULL, NULL, NULL, NULL, abs($duration_s));

  // Set statement context.
  $statement
    ->setContext($context);

  // Sending statement.
  $result = OpignoTinCanApiStatements::sendStatement($statement);
  if ($result) {

    // Save data about statement sending in database.
    $this
      ->saveSendingStatement($meeting);
  }
}