opigno_tincan_api_openbadges_statements.module in Opigno TinCan API 7
File
modules/opigno_tincan_api_openbadges_statements/opigno_tincan_api_openbadges_statements.module
View source
<?php
module_load_include('inc', 'opigno_tincan_api', 'includes/opigno_tincan_api.statements_func');
module_load_include('inc', 'opigno_tincan_api', 'includes/opigno_tincan_api.tincan_activity_definition_types');
module_load_include('inc', 'opigno_tincan_api', 'includes/opigno_tincan_api.tincan_verbs');
function opigno_tincan_api_openbadges_statements_opigno_openbadge_assertion_created($nid, $badgeClassFileURI, $assertFileURI) {
if (_opigno_tincan_api_tincanphp_is_installed() === false) {
return;
}
$badge_data = json_decode(file_get_contents(drupal_realpath($badgeClassFileURI)));
$statement = new TinCan\Statement();
_opigno_tincan_api_set_actor($statement);
_opigno_tincan_api_set_verb($statement, OpignoTincanApiTinCanVerbs::$earned);
$statement
->stamp();
$statement
->setResult(array(
'extensions' => array(
'http://specification.openbadges.org/xapi/extensions/badgeassertion' => array(
'@id' => file_create_url($assertFileURI),
),
),
));
$uri_class_file = file_create_url($badgeClassFileURI);
$statement
->setObject(array(
'id' => $uri_class_file,
'objectType' => 'Activity',
'definition' => array(
'extensions' => array(
'http://specification.openbadges.org/xapi/extensions/badgeclass' => array(
'@id' => $uri_class_file,
'image' => $badge_data->image,
'criteria' => $badge_data->criteria,
'issuer' => $badge_data->issuer,
),
),
'name' => array(
'en-US' => $badge_data->name,
),
'description' => array(
'en-US' => $badge_data->description,
),
'type' => OpignoTincanApiTinCanActivityDefinitionTypes::$badge,
),
));
_opigno_tincan_api_send_statement($statement);
}