You are here

public static function OpignoTinCanApiStatements::setActor in Opigno TinCan API 8

Same name and namespace in other branches
  1. 3.x src/OpignoTinCanApiStatements.php \Drupal\opigno_tincan_api\OpignoTinCanApiStatements::setActor()

Add the current user as the actor of this statement.

Parameters

\TinCan\Statement $statement: The statement to add the actor.

null|mixed $user: User.

Throws

\Exception

3 calls to OpignoTinCanApiStatements::setActor()
OpignoTinCanApiStatements::statementBaseCreation in src/OpignoTinCanApiStatements.php
Adds the current user as the actor.
_opigno_tincan_badges_create_and_send_statements in modules/opigno_tincan_badges/opigno_tincan_badges.module
Function for creating and sending tincan statemens when user get a badge.
_opigno_tincan_learning_path_send_statemets_certificate in modules/opigno_tincan_learning_path/opigno_tincan_learning_path.module
Sends statements certificate.

File

src/OpignoTinCanApiStatements.php, line 310

Class

OpignoTinCanApiStatements
Class OpignoTinCanApiStatements.

Namespace

Drupal\opigno_tincan_api

Code

public static function setActor(Statement &$statement, $user = NULL) {

  // _opigno_tincan_api_set_actor.
  if ($user === NULL) {
    $user = \Drupal::currentUser();
  }
  else {
    if (empty($user) || empty($user
      ->getAccountName()) || empty($user
      ->getEmail())) {
      throw new Exception('The user given was not loaded');
    }
  }
  $actor = new Agent([
    'name' => $user
      ->getAccountName(),
    'mbox_sha1sum' => sha1('mailto:' . $user
      ->getEmail()),
  ]);
  $statement
    ->setActor($actor);
}