Skip to content

Commit

Permalink
Merge pull request #18 from deltanet/issue/#16
Browse files Browse the repository at this point in the history
Add custom statement listener and function
  • Loading branch information
deltanetdan authored Jul 30, 2020
2 parents a7adb65 + 8d6a4a4 commit 308eba1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapt-contrib-xapi",
"version": "0.8.4",
"version": "0.8.5",
"framework": ">=3",
"homepage": "https://github.com/deltanet/adapt-contrib-xapi",
"authors": [
Expand Down
3 changes: 2 additions & 1 deletion example.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"router:menu": true,
"router:page": true,
"questionView:recordInteraction": true,
"assessments:complete": true
"assessments:complete": true,
"plugin:customStatement": true
},
"contentObjects": {
"change:_isComplete": true
Expand Down
57 changes: 56 additions & 1 deletion js/adapt-contrib-xapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ define([
'router:page': false,
'router:menu': false,
'assessments:complete': true,
'questionView:recordInteraction': true
'questionView:recordInteraction': true,
"plugin:customStatement": true
},
contentObjects: {
'change:_isComplete': false
Expand Down Expand Up @@ -478,6 +479,11 @@ define([
this.listenTo(Adapt, 'assessments:complete', this.onAssessmentComplete);
}

// Listen out for custom statements.
if (this.coreEvents['Adapt']['plugin:customStatement']) {
this.listenTo(Adapt, 'plugin:customStatement', this.onCustomStatement);
}

// Standard completion events for the various collection types, i.e.
// course, contentobjects, articles, blocks and components.
_.each(_.keys(this.coreEvents), function(key) {
Expand Down Expand Up @@ -593,6 +599,10 @@ define([
type = ADL.activityTypes.lesson;
break;
}
default: {
type = ADL.activityTypes[model.get('_type')];
break;
}
}

return type;
Expand Down Expand Up @@ -732,6 +742,51 @@ define([
this.sendStatement(statement);
},

/**
* Sends an xAPI statement when plugin triggers a custom statement.
* @param {AdaptModel} model - An instance of AdaptModel, i.e. ContentObjectModel, etc.
*/

onCustomStatement: function(statementModel) {
var customResult = {};
var customContext = {};
// get the verb
var statement;
var customVerb = ADL.verbs[statementModel.get('verb')];

// get the object
var customIri = '';
if (statementModel.get('generateIri')) {
customIri = this.getUniqueIri(statementModel);
} else {
customIri = statementModel.get('_id');
}
var object = new ADL.XAPIStatement.Activity(customIri);
object.definition = {
name: this.getNameObject(statementModel),
type: this.getActivityType(statementModel)
};

// get result
// TODO

// get custom context
// TODO

statement = this.getStatement(this.getVerb(customVerb), object, customResult, customContext);

// add parent activity if part of assessment
if (statementModel && statementModel.get('_isPartOfAssessment')) {
var assessment = statementModel.assessment;
if (typeof assessment === 'object') {
statement.addParentActivity(this.getAssessmentObject(assessment));
}
}

this.addGroupingActivity(statementModel, statement)
this.sendStatement(statement);
},

/**
* Checks if a given component is blacklisted from sending statements.
* @param {string} component - The name of the component.
Expand Down
9 changes: 9 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@
"title": "assessments:complete",
"validators": [],
"help": "Triggered when an individual assessment is completed."
},
"plugin:customStatement": {
"type": "boolean",
"required": false,
"inputType": "Checkbox",
"default": true,
"title": "plugin:customStatement",
"validators": [],
"help": "Custom xAPI statement triggered by an individual plugin."
}
}
},
Expand Down

0 comments on commit 308eba1

Please sign in to comment.