You are here

public static function OpignoTinCanApiStatements::setResult in Opigno TinCan API 3.x

Same name and namespace in other branches
  1. 8 src/OpignoTinCanApiStatements.php \Drupal\opigno_tincan_api\OpignoTinCanApiStatements::setResult()

Sets result.

6 calls to OpignoTinCanApiStatements::setResult()
OpignoTincanLiveMeeting::createAndSendTincanStatementsForMeeting in modules/opigno_tincan_live_meeting/src/EventSubscriber/OpignoTincanLiveMeeting.php
Sends tincan statements for Live meeting.
opigno_tincan_modules_user_module_status_presave in modules/opigno_tincan_modules/opigno_tincan_modules.module
Implements hook_ENTITY_TYPE_presave().
_opigno_tincan_activities_set_results in modules/opigno_tincan_activities/opigno_tincan_activities.module
Set answer result to tincan statement.
_opigno_tincan_courses_create_and_send_course_statements in modules/opigno_tincan_courses/opigno_tincan_courses.module
Creates and sends course statements.
_opigno_tincan_ilt_create_and_send_tincan_statement in modules/opigno_tincan_ilt/opigno_tincan_ilt.module
Creates and sends tincan statement.

... See full list

File

src/OpignoTinCanApiStatements.php, line 201

Class

OpignoTinCanApiStatements
Class OpignoTinCanApiStatements.

Namespace

Drupal\opigno_tincan_api

Code

public static function setResult(Statement &$statement, $user_score = NULL, $score_max = NULL, $score_min = NULL, $is_success = NULL, $response = NULL, $duration_s = NULL) {

  // _opigno_tincan_api_set_result.
  $result = new Result();
  if ($user_score !== NULL) {
    self::setScore($result, $user_score, $score_max, $score_min);
  }
  if ($is_success !== NULL) {
    $result
      ->setSuccess($is_success);
  }
  $result
    ->setCompletion(TRUE);
  if ($response !== NULL) {
    $result
      ->setResponse($response);
  }
  if ($duration_s !== NULL) {
    $time_now = new DateTime();
    $time_more = new DateTime();
    $time_more
      ->add(new DateInterval('PT' . (int) $duration_s . 'S'));
    $time = $time_now
      ->diff($time_more);

    // Remove all the 0 in the formatted duration.
    $duration_string = $time
      ->format('P%yY%mM%dDT%hH%iM%sS');
    $duration_string = preg_replace('/(\\D)0{1}\\D/i', '$1', $duration_string);
    if (strpos($duration_string, 'P0M') !== FALSE) {

      // Need twice same replacement for deleting 0M before T.
      $duration_string = preg_replace('/(\\D)0{1}\\D/i', '$1', $duration_string);
    }
    $duration_string == 'PT' ? $duration_string = 'PT0S' : NULL;
    $result
      ->setDuration($duration_string);
  }
  $statement
    ->setResult($result);
  return $statement;
}