Skip to content

xAPI Statements

Phil edited this page Oct 3, 2026 · 1 revision

The xAPI facade builds statements and sends them to Learning Locker's xAPI endpoint, /data/xAPI/statements. It sends X-Experience-API-Version: 1.0.3 with every request. Each call to the facade starts a new statement, so nothing carries over from one to the next.

The client needs an xAPI scope: xAPI All, or xAPI write to send and xAPI read to read.

Sending a statement

use xAPI;

$id = xAPI::actor(['name' => 'Jane Doe', 'email' => 'jane@example.com'])
    ->did('completed')
    ->what('https://example.com/courses/intro', 'Introduction', 'http://adlnet.gov/expapi/activities/course')
    ->scored(['score' => ['scaled' => 0.9], 'success' => true, 'completion' => true])
    ->context(['platform' => 'My app'])
    ->send();

send() returns the statement's xAPI id. store() is an alias kept from earlier versions.

Actor: actor()

You pass You get
['name' => 'Jane', 'email' => 'jane@example.com'] an mbox agent
['name' => 'Jane', 'account' => $user->id] an account agent on the configured home page (LEARNING_LOCKER_ACTOR_HOMEPAGE, else APP_URL)
a full xAPI agent (mbox, mbox_sha1sum, openid or an account array) that agent, unchanged

Verb: did()

  • an ADL verb name: answered, asked, attempted, attended, commented, completed, exited, experienced, failed, imported, initialized, interacted, launched, mastered, passed, preferred, progressed, registered, responded, resumed, satisfied, scored, shared, suspended, terminated, voided, waived;
  • a verb IRI, e.g. did('https://w3id.org/xapi/video/verbs/played', 'played');
  • a full xAPI verb array.

Object: what()

what($iri, $name = null, $type = null, $description = null) builds an Activity. You can also pass a full xAPI object, for example an Agent or a StatementRef.

The rest

  • scored(array $result) sets the result.
  • context(array $context) sets the context.
  • at($timestamp) sets the time. It defaults to now.
  • make() returns the statement as an array without sending it.

To send statements you have already built, use Statements: LearningLocker::statements()->send([...]).

Reading statements

$page = xAPI::statements([
    'agent' => ['email' => 'jane@example.com'],   // an array is turned into an xAPI agent
    'verb' => 'http://adlnet.gov/expapi/verbs/completed',
    'since' => now()->subWeek()->toIso8601String(),
    'limit' => 50,
]);

foreach ($page['statements'] as $statement) {
    // ...
}

if ($page['more']) {
    $next = xAPI::more($page['more']);
}

xAPI::statement($uuid);   // one statement by its xAPI id

The filters are the xAPI ones: agent, verb, activity, registration, related_activities, related_agents, since, until, limit, format, attachments, ascending.

For MongoDB queries over stored statements, use LearningLocker::statements()->where(...) or LearningLocker::aggregate(). See Querying.

Clone this wiki locally