From 64820d6ed55e5ebc6e39a5624765a8258d563f3e Mon Sep 17 00:00:00 2001 From: Wolford Date: Wed, 3 May 2017 10:27:00 -0400 Subject: [PATCH 1/5] started updating scorm 1.2 resources --- README.md | 23 +++++++++--------- SCORM1.2/APIWrapper.js | 24 ++++++------------- SCORM2004/APIWrapper.js | 7 +----- SCORMToXAPIFunctions.js | 52 ++++++----------------------------------- 4 files changed, 27 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 487d87d..7c889c9 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,6 @@ This javascript file is typically used in SCORM 2004 courses. If the ADL-provid Note: The updated APIWrapper.js file does not stand-alone and MUST be used with the SCORMToXAPIFunctions.js file. ## SCORM1.2/APIWrapper.js -NOTE - THIS VERSION IS CURRENTLY OUT OF DATE. PLEASE SEE THE 2004 WRAPPER UNTIL THIS ISSUE IS ADDRESSED. - Javascript SCORM 1.2 API wrapper with new xAPI object (Implemented in SCORMToXAPIFunctions.js). This javascript file is typically used in SCORM 1.2 courses. If the ADL-provided ADLWrapper.js file is used in your SCORM courses, it can be replaced with this file. @@ -57,15 +55,18 @@ var activity = ; Finally, several configuration values must be set in the updated APIWrapper.js file (init method). Instructions are also included in the header at the top of the JavaScript file. Near the top of the file, configure the following lines of code: ```JavaScript - var config = { - lrs:{ - endpoint:"https://lrs.adlnet.gov/xapi/", - user:"", - password:"" - }, - courseId:"", - lmsHomePage:"" - }; + var config = { + lrs: { + endpoint: "https://lrs.adlnet.gov/xapi/", + user: "", + password: "" + }, + courseId: "", + lmsHomePage: "", + isScorm2004: true, + activityId: "", + groupingContextActivity: {} + }; ``` ### Limitations diff --git a/SCORM1.2/APIWrapper.js b/SCORM1.2/APIWrapper.js index 1d835aa..e40acb5 100755 --- a/SCORM1.2/APIWrapper.js +++ b/SCORM1.2/APIWrapper.js @@ -141,6 +141,7 @@ function doLMSInitialize() } var result = api.LMSInitialize(""); + if (result.toString() != "true") { var err = ErrorHandler(); @@ -148,21 +149,10 @@ function doLMSInitialize() } else { - initialized = true; - - // xAPI Extensions - var config = { - lrs:{ - endpoint:"", - user:"", - password:"" - }, - courseId:"", - lmsHomePage:"", - isScorm2004:false - }; // isSCORM2004:true above - to convert SCORM 2004 courses - xapi.setConfig(config); - xapi.initializeAttempt(); + initialized = true; + + //xAPI Extension + xapi.initializeAttempt(); } @@ -271,7 +261,7 @@ function doLMSSetValue(name, value) { message("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful."); } - else if (! initialized && ! doLMSInitialize()) + else if (!initialized && !doLMSInitialize()) { var err = ErrorHandler(); // get why doLMSInitialize() returned false message("LMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code); @@ -311,7 +301,7 @@ function doLMSCommit() { message("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful."); } - else if (! initialized && ! doLMSInitialize()) + else if (!initialized && ! doLMSInitialize()) { var err = ErrorHandler(); // get why doLMSInitialize() returned false message("LMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code); diff --git a/SCORM2004/APIWrapper.js b/SCORM2004/APIWrapper.js index f9ed1d0..d90223a 100644 --- a/SCORM2004/APIWrapper.js +++ b/SCORM2004/APIWrapper.js @@ -149,12 +149,9 @@ function doInitialize() } else { - // todo remove - message("Initialize succeeded"); - initialized = true; - // xAPI Extension + // xAPI Extension xapi.initializeAttempt(); } @@ -162,7 +159,6 @@ function doInitialize() return result.toString(); } - /******************************************************************************* ** ** Function doTerminate() @@ -232,7 +228,6 @@ function doGetValue(name) } else { - result = api.GetValue(name); var error = ErrorHandler(); diff --git a/SCORMToXAPIFunctions.js b/SCORMToXAPIFunctions.js index 9582ce3..ac99dbc 100644 --- a/SCORMToXAPIFunctions.js +++ b/SCORMToXAPIFunctions.js @@ -73,18 +73,8 @@ xapi = function () { ** *******************************************************************************/ var getBaseStatement = function () { - if (window.localStorage.learnerId == null) { - window.localStorage.learnerId = retrieveDataValue(scormVersionConfig.learnerIdElement); - } - return { - actor: { - objectType: "Agent", - account: { - homePage: config.lmsHomePage, - name: window.localStorage.learnerId - } - }, + actor: getAgent(), verb: {}, object: { id: config.activityId, @@ -129,18 +119,8 @@ xapi = function () { ** *******************************************************************************/ var getInteractionsBaseStatement = function () { - if (window.localStorage.learnerId == null) { - window.localStorage.learnerId = retrieveDataValue(scormVersionConfig.learnerIdElement); - } - return { - actor: { - objectType: "Agent", - account: { - homePage: config.lmsHomePage, - name: window.localStorage.learnerId - } - }, + actor: getAgent(), verb: ADL.verbs.responded, object: { objectType: "Activity", @@ -199,18 +179,8 @@ xapi = function () { ** *******************************************************************************/ var getVoidedBaseStatement = function () { - if (window.localStorage.learnerId == null) { - window.localStorage.learnerId = retrieveDataValue(scormVersionConfig.learnerIdElement); - } - return { - actor: { - objectType: "Agent", - account: { - homePage: config.lmsHomePage, - name: window.localStorage.learnerId - } - }, + actor: getAgent()}, verb: {}, object: { objectType: "StatementRef", @@ -235,7 +205,8 @@ xapi = function () { account: { homePage: config.lmsHomePage, name: window.localStorage.learnerId - } + }, + objectType: "Agent" }; return agent; @@ -476,11 +447,6 @@ xapi = function () { ** *******************************************************************************/ var setAgentProfile = function () { - - if (window.localStorage.learnerId == null) { - window.localStorage.learnerId = retrieveDataValue(scormVersionConfig.learnerIdElement); - } - var lang = retrieveDataValue(scormVersionConfig.languageElement); var audioLevel = retrieveDataValue(scormVersionConfig.audioLevelElement); var deliverySpeed = retrieveDataValue(scormVersionConfig.deliverySpeedElement); @@ -493,12 +459,8 @@ xapi = function () { audio_captioning: audioCaptioning }; - ADL.XAPIWrapper.sendAgentProfile({ - account: { - homePage: config.lmsHomePage, - name: window.localStorage.learnerId - } - }, + ADL.XAPIWrapper.sendAgentProfile( + getAgent(), config.activityId, profile, null, From 714bd7ca541cb8d105e1de089e5108ec82d33ddf Mon Sep 17 00:00:00 2001 From: Wolford Date: Mon, 15 May 2017 14:00:24 -0400 Subject: [PATCH 2/5] removed extra bracket --- SCORMToXAPIFunctions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCORMToXAPIFunctions.js b/SCORMToXAPIFunctions.js index ac99dbc..bf31792 100644 --- a/SCORMToXAPIFunctions.js +++ b/SCORMToXAPIFunctions.js @@ -180,7 +180,7 @@ xapi = function () { *******************************************************************************/ var getVoidedBaseStatement = function () { return { - actor: getAgent()}, + actor: getAgent(), verb: {}, object: { objectType: "StatementRef", From 64f31cfef7d031131c8aac87ae460dbf8641cabb Mon Sep 17 00:00:00 2001 From: Wolford Date: Wed, 31 May 2017 13:41:12 -0400 Subject: [PATCH 3/5] remove cmi_completion_threshold getValue for scorm1.2 --- SCORM1.2/APIWrapper.js | 63 +++++++++++++++++++++-------------------- SCORMToXAPIFunctions.js | 9 ++++-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/SCORM1.2/APIWrapper.js b/SCORM1.2/APIWrapper.js index e40acb5..88c8725 100755 --- a/SCORM1.2/APIWrapper.js +++ b/SCORM1.2/APIWrapper.js @@ -81,17 +81,17 @@ With the understanding that: ** functions as follows: ** ** javascript: -** var result = doLMSInitialize(); +** var result = LMSInitialize(); ** if (result != true) ** { ** // handle error ** } ** ** authorware: -** result := ReadURL("javascript:doLMSInitialize()", 100) +** result := ReadURL("javascript:LMSInitialize()", 100) ** ** director: -** result = externalEvent("javascript:doLMSInitialize()") +** result = externalEvent("javascript:LMSInitialize()") ** ** *******************************************************************************/ @@ -112,14 +112,14 @@ var apiHandle = null; // xAPI Extention helper > // Pass-throughs to handle other common SCORM 1.2 wrapper versions. -initializeCommunication = doLMSInitialize; -terminateCommunication = doLMSFinish; -storeDataValue = doLMSSetValue; -retrieveDataValue = doLMSGetValue; +initializeCommunication = LMSInitialize; +terminateCommunication = LMSFinish; +storeDataValue = LMSSetValue; +retrieveDataValue = LMSGetValue; /******************************************************************************* ** -** Function: doLMSInitialize() +** Function: LMSInitialize() ** Inputs: None ** Return: true if the initialization was successful, or ** false if the initialization failed. @@ -129,7 +129,7 @@ retrieveDataValue = doLMSGetValue; ** function which will be implemented by the LMS. ** *******************************************************************************/ -function doLMSInitialize() +function LMSInitialize() { if (initialized) return "true"; @@ -161,7 +161,7 @@ function doLMSInitialize() /******************************************************************************* ** -** Function doLMSFinish() +** Function LMSFinish() ** Inputs: None ** Return: true if successful ** false if failed. @@ -171,7 +171,7 @@ function doLMSInitialize() ** function which will be implemented by the LMS ** *******************************************************************************/ -function doLMSFinish() +function LMSFinish() { if (! initialized) return "true"; @@ -202,7 +202,7 @@ function doLMSFinish() /******************************************************************************* ** -** Function doLMSGetValue(name) +** Function LMSGetValue(name) ** Inputs: name - string representing the cmi data model defined category or ** element (e.g. cmi.core.student_id) ** Return: The value presently assigned by the LMS to the cmi data model @@ -213,17 +213,18 @@ function doLMSFinish() ** Wraps the call to the LMS LMSGetValue method ** *******************************************************************************/ -function doLMSGetValue(name) +function LMSGetValue(name) { + var api = getAPIHandle(); var result = ""; if (api == null) { message("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful."); } - else if (! initialized && ! doLMSInitialize()) + else if (! initialized && ! LMSInitialize()) { - var err = ErrorHandler(); // get why doLMSInitialize() returned false + var err = ErrorHandler(); // get why LMSInitialize() returned false message("LMSGetValue failed - Could not initialize communication with the LMS - error code: " + err.code); } else @@ -243,7 +244,7 @@ function doLMSGetValue(name) /******************************************************************************* ** -** Function doLMSSetValue(name, value) +** Function LMSSetValue(name, value) ** Inputs: name -string representing the data model defined category or element ** value -the value that the named element or category will be assigned ** Return: true if successful @@ -253,7 +254,7 @@ function doLMSGetValue(name) ** Wraps the call to the LMS LMSSetValue function ** *******************************************************************************/ -function doLMSSetValue(name, value) +function LMSSetValue(name, value) { var api = getAPIHandle(); var result = "false"; @@ -261,9 +262,9 @@ function doLMSSetValue(name, value) { message("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful."); } - else if (!initialized && !doLMSInitialize()) + else if (!initialized && !LMSInitialize()) { - var err = ErrorHandler(); // get why doLMSInitialize() returned false + var err = ErrorHandler(); // get why LMSInitialize() returned false message("LMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code); } else @@ -284,7 +285,7 @@ function doLMSSetValue(name, value) /******************************************************************************* ** -** Function doLMSCommit() +** Function LMSCommit() ** Inputs: None ** Return: true if successful ** false if failed. @@ -293,7 +294,7 @@ function doLMSSetValue(name, value) ** Commits the data to the LMS. ** *******************************************************************************/ -function doLMSCommit() +function LMSCommit() { var api = getAPIHandle(); var result = "false"; @@ -301,9 +302,9 @@ function doLMSCommit() { message("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful."); } - else if (!initialized && ! doLMSInitialize()) + else if (!initialized && ! LMSInitialize()) { - var err = ErrorHandler(); // get why doLMSInitialize() returned false + var err = ErrorHandler(); // get why LMSInitialize() returned false message("LMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code); } else @@ -321,7 +322,7 @@ function doLMSCommit() /******************************************************************************* ** -** Function doLMSGetLastError() +** Function LMSGetLastError() ** Inputs: None ** Return: The error code that was set by the last LMS function call ** @@ -329,7 +330,7 @@ function doLMSCommit() ** Call the LMSGetLastError function ** *******************************************************************************/ -function doLMSGetLastError() +function LMSGetLastError() { var api = getAPIHandle(); if (api == null) @@ -344,7 +345,7 @@ function doLMSGetLastError() /******************************************************************************* ** -** Function doLMSGetErrorString(errorCode) +** Function LMSGetErrorString(errorCode) ** Inputs: errorCode - Error Code ** Return: The textual description that corresponds to the input error code ** @@ -352,7 +353,7 @@ function doLMSGetLastError() ** Call the LMSGetErrorString function ** ********************************************************************************/ -function doLMSGetErrorString(errorCode) +function LMSGetErrorString(errorCode) { var api = getAPIHandle(); if (api == null) @@ -366,7 +367,7 @@ function doLMSGetErrorString(errorCode) /******************************************************************************* ** -** Function doLMSGetDiagnostic(errorCode) +** Function LMSGetDiagnostic(errorCode) ** Inputs: errorCode - Error Code(integer format), or null ** Return: The vendor specific textual description that corresponds to the ** input error code @@ -375,7 +376,7 @@ function doLMSGetErrorString(errorCode) ** Call the LMSGetDiagnostic function ** *******************************************************************************/ -function doLMSGetDiagnostic(errorCode) +function LMSGetDiagnostic(errorCode) { var api = getAPIHandle(); if (api == null) @@ -465,7 +466,7 @@ function getAPIHandle() *******************************************************************************/ function findAPI(win) { - var findAPITries = 0; + var findAPITries = 0; while ((win.API == null) && (win.parent != null) && (win.parent != win)) { findAPITries++; @@ -527,4 +528,4 @@ function message(str) { output.log(str); } -} +} \ No newline at end of file diff --git a/SCORMToXAPIFunctions.js b/SCORMToXAPIFunctions.js index bf31792..df60c54 100644 --- a/SCORMToXAPIFunctions.js +++ b/SCORMToXAPIFunctions.js @@ -484,8 +484,11 @@ xapi = function () { //var cmi_num_comments_from_lms_count = retrieveDataValue("cmi.comments_from_lms._count"); // todo: get the comments, if any and add to array - // get completion threshold (if supplied in manifest) - var cmi_completion_threshold = retrieveDataValue(scormVersionConfig.completionThresholdElement); + // get completion threshold (if supplied in manifest, only valid in SCORM2004) + var cmi_completion_threshold = ""; + if (config.isScorm2004){ + cmi_completion_threshold = retrieveDataValue(scormVersionConfig.completionThresholdElement); + } var cmi_launch_data = retrieveDataValue(scormVersionConfig.launchDataElement); var cmi_max_time_allowed = retrieveDataValue(scormVersionConfig.maxTimeAllowedElement); var cmi_scaled_passing_score = retrieveDataValue(scormVersionConfig.scaledPassingScoreElement); @@ -565,7 +568,7 @@ xapi = function () { // location, preferences object, credit, lesson_mode, suspend_data, // total_time, adl_data var cmi_location = retrieveDataValue(scormVersionConfig.locationElement); - + var cmi_language = retrieveDataValue(scormVersionConfig.languageElement); var cmi_audio_level = retrieveDataValue(scormVersionConfig.audioLevelElement); var cmi_delivery_speed = retrieveDataValue(scormVersionConfig.deliverySpeedElement); From 637dde9749f531c1e7370a756dffcdf6e2925925 Mon Sep 17 00:00:00 2001 From: Wolford Date: Wed, 31 May 2017 14:34:04 -0400 Subject: [PATCH 4/5] undid the do- function change --- SCORM1.2/APIWrapper.js | 130 ++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/SCORM1.2/APIWrapper.js b/SCORM1.2/APIWrapper.js index 88c8725..11a7361 100755 --- a/SCORM1.2/APIWrapper.js +++ b/SCORM1.2/APIWrapper.js @@ -81,17 +81,17 @@ With the understanding that: ** functions as follows: ** ** javascript: -** var result = LMSInitialize(); +** var result = doLMSInitialize(); ** if (result != true) ** { ** // handle error ** } ** ** authorware: -** result := ReadURL("javascript:LMSInitialize()", 100) +** result := ReadURL("javascript:doLMSInitialize()", 100) ** ** director: -** result = externalEvent("javascript:LMSInitialize()") +** result = externalEvent("javascript:doLMSInitialize()") ** ** *******************************************************************************/ @@ -112,40 +112,40 @@ var apiHandle = null; // xAPI Extention helper > // Pass-throughs to handle other common SCORM 1.2 wrapper versions. -initializeCommunication = LMSInitialize; -terminateCommunication = LMSFinish; -storeDataValue = LMSSetValue; -retrieveDataValue = LMSGetValue; +initializeCommunication = doLMSInitialize; +terminateCommunication = doLMSFinish; +storeDataValue = doLMSSetValue; +retrieveDataValue = doLMSGetValue; /******************************************************************************* ** -** Function: LMSInitialize() +** Function: doLMSInitialize() ** Inputs: None ** Return: true if the initialization was successful, or ** false if the initialization failed. ** ** Description: -** Initialize communication with LMS by calling the LMSInitialize +** Initialize communication with LMS by calling the doLMSInitialize ** function which will be implemented by the LMS. ** *******************************************************************************/ -function LMSInitialize() +function doLMSInitialize() { if (initialized) return "true"; var api = getAPIHandle(); if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSInitialize was not successful."); return "false"; } - var result = api.LMSInitialize(""); + var result = api.doLMSInitialize(""); if (result.toString() != "true") { var err = ErrorHandler(); - message("LMSInitialize failed with error code: " + err.code); + message("doLMSInitialize failed with error code: " + err.code); } else { @@ -161,24 +161,24 @@ function LMSInitialize() /******************************************************************************* ** -** Function LMSFinish() +** Function doLMSFinish() ** Inputs: None ** Return: true if successful ** false if failed. ** ** Description: -** Close communication with LMS by calling the LMSFinish +** Close communication with LMS by calling the doLMSFinish ** function which will be implemented by the LMS ** *******************************************************************************/ -function LMSFinish() +function doLMSFinish() { if (! initialized) return "true"; var api = getAPIHandle(); if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSFinish was not successful."); return "false"; } else @@ -186,12 +186,12 @@ function LMSFinish() // xAPI Extension xapi.terminateAttempt(); - // call the LMSFinish function that should be implemented by the API - var result = api.LMSFinish(""); + // call the doLMSFinish function that should be implemented by the API + var result = api.doLMSFinish(""); if (result.toString() != "true") { var err = ErrorHandler(); - message("LMSFinish failed with error code: " + err.code); + message("doLMSFinish failed with error code: " + err.code); } } @@ -202,7 +202,7 @@ function LMSFinish() /******************************************************************************* ** -** Function LMSGetValue(name) +** Function doLMSGetValue(name) ** Inputs: name - string representing the cmi data model defined category or ** element (e.g. cmi.core.student_id) ** Return: The value presently assigned by the LMS to the cmi data model @@ -210,32 +210,32 @@ function LMSFinish() ** input value. ** ** Description: -** Wraps the call to the LMS LMSGetValue method +** Wraps the call to the LMS doLMSGetValue method ** *******************************************************************************/ -function LMSGetValue(name) +function doLMSGetValue(name) { var api = getAPIHandle(); var result = ""; if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSGetValue was not successful."); } - else if (! initialized && ! LMSInitialize()) + else if (! initialized && ! doLMSInitialize()) { - var err = ErrorHandler(); // get why LMSInitialize() returned false - message("LMSGetValue failed - Could not initialize communication with the LMS - error code: " + err.code); + var err = ErrorHandler(); // get why doLMSInitialize() returned false + message("doLMSGetValue failed - Could not initialize communication with the LMS - error code: " + err.code); } else { - result = api.LMSGetValue(name); + result = api.doLMSGetValue(name); var error = ErrorHandler(); if (error.code != _NoError.code) { // an error was encountered so display the error description - message("LMSGetValue("+name+") failed. \n"+ error.code + ": " + error.string); + message("doLMSGetValue("+name+") failed. \n"+ error.code + ": " + error.string); result = ""; } } @@ -244,39 +244,39 @@ function LMSGetValue(name) /******************************************************************************* ** -** Function LMSSetValue(name, value) +** Function doLMSSetValue(name, value) ** Inputs: name -string representing the data model defined category or element ** value -the value that the named element or category will be assigned ** Return: true if successful ** false if failed. ** ** Description: -** Wraps the call to the LMS LMSSetValue function +** Wraps the call to the LMS doLMSSetValue function ** *******************************************************************************/ -function LMSSetValue(name, value) +function doLMSSetValue(name, value) { var api = getAPIHandle(); var result = "false"; if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSSetValue was not successful."); } - else if (!initialized && !LMSInitialize()) + else if (!initialized && !doLMSInitialize()) { - var err = ErrorHandler(); // get why LMSInitialize() returned false - message("LMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code); + var err = ErrorHandler(); // get why doLMSInitialize() returned false + message("doLMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code); } else { // xAPI Extension xapi.saveDataValue(name, value); - result = api.LMSSetValue(name, value); + result = api.doLMSSetValue(name, value); if (result.toString() != "true") { var err = ErrorHandler(); - message("LMSSetValue("+name+", "+value+") failed. \n"+ err.code + ": " + err.string); + message("doLMSSetValue("+name+", "+value+") failed. \n"+ err.code + ": " + err.string); } } @@ -285,7 +285,7 @@ function LMSSetValue(name, value) /******************************************************************************* ** -** Function LMSCommit() +** Function doLMSCommit() ** Inputs: None ** Return: true if successful ** false if failed. @@ -294,26 +294,26 @@ function LMSSetValue(name, value) ** Commits the data to the LMS. ** *******************************************************************************/ -function LMSCommit() +function doLMSCommit() { var api = getAPIHandle(); var result = "false"; if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSCommit was not successful."); } - else if (!initialized && ! LMSInitialize()) + else if (!initialized && ! doLMSInitialize()) { - var err = ErrorHandler(); // get why LMSInitialize() returned false - message("LMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code); + var err = ErrorHandler(); // get why doLMSInitialize() returned false + message("doLMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code); } else { - result = api.LMSCommit(""); + result = api.doLMSCommit(""); if (result != "true") { var err = ErrorHandler(); - message("LMSCommit failed - error code: " + err.code); + message("doLMSCommit failed - error code: " + err.code); } } @@ -322,70 +322,70 @@ function LMSCommit() /******************************************************************************* ** -** Function LMSGetLastError() +** Function doLMSGetLastError() ** Inputs: None ** Return: The error code that was set by the last LMS function call ** ** Description: -** Call the LMSGetLastError function +** Call the doLMSGetLastError function ** *******************************************************************************/ -function LMSGetLastError() +function doLMSGetLastError() { var api = getAPIHandle(); if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSGetLastError was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSGetLastError was not successful."); //since we can't get the error code from the LMS, return a general error return _GeneralException.code; //General Exception } - return api.LMSGetLastError().toString(); + return api.doLMSGetLastError().toString(); } /******************************************************************************* ** -** Function LMSGetErrorString(errorCode) +** Function doLMSGetErrorString(errorCode) ** Inputs: errorCode - Error Code ** Return: The textual description that corresponds to the input error code ** ** Description: -** Call the LMSGetErrorString function +** Call the doLMSGetErrorString function ** ********************************************************************************/ -function LMSGetErrorString(errorCode) +function doLMSGetErrorString(errorCode) { var api = getAPIHandle(); if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSGetErrorString was not successful."); + message("Unable to locate the LMS's API Implementation.\ndoLMSGetErrorString was not successful."); return _GeneralException.string; } - return api.LMSGetErrorString(errorCode).toString(); + return api.doLMSGetErrorString(errorCode).toString(); } /******************************************************************************* ** -** Function LMSGetDiagnostic(errorCode) +** Function doLMSGetDiagnostic(errorCode) ** Inputs: errorCode - Error Code(integer format), or null ** Return: The vendor specific textual description that corresponds to the ** input error code ** ** Description: -** Call the LMSGetDiagnostic function +** Call the doLMSGetDiagnostic function ** *******************************************************************************/ -function LMSGetDiagnostic(errorCode) +function doLMSGetDiagnostic(errorCode) { var api = getAPIHandle(); if (api == null) { - message("Unable to locate the LMS's API Implementation.\nLMSGetDiagnostic was not successful."); - return "Unable to locate the LMS's API Implementation. LMSGetDiagnostic was not successful."; + message("Unable to locate the LMS's API Implementation.\ndoLMSGetDiagnostic was not successful."); + return "Unable to locate the LMS's API Implementation. doLMSGetDiagnostic was not successful."; } - return api.LMSGetDiagnostic(errorCode).toString(); + return api.doLMSGetDiagnostic(errorCode).toString(); } /******************************************************************************* @@ -421,12 +421,12 @@ function ErrorHandler() } // check for errors caused by or from the LMS - error.code = api.LMSGetLastError().toString(); + error.code = api.doLMSGetLastError().toString(); if (error.code != _NoError.code) { // an error was encountered so display the error description - error.string = api.LMSGetErrorString(error.code); - error.diagnostic = api.LMSGetDiagnostic(""); + error.string = api.doLMSGetErrorString(error.code); + error.diagnostic = api.doLMSGetDiagnostic(""); } return error; From 79bfb889b2ba9537591ff8911972c3a1a31757fc Mon Sep 17 00:00:00 2001 From: Wolford Date: Thu, 17 Aug 2017 13:56:58 -0400 Subject: [PATCH 5/5] in middle of fixes --- SCORM2004/APIWrapper.js | 7 ++++- SCORMToXAPIFunctions.js | 60 ++++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/SCORM2004/APIWrapper.js b/SCORM2004/APIWrapper.js index d90223a..e0fc2ae 100644 --- a/SCORM2004/APIWrapper.js +++ b/SCORM2004/APIWrapper.js @@ -153,6 +153,7 @@ function doInitialize() // xAPI Extension xapi.initializeAttempt(); + doSetValue("cmi.progress_measure", 0.0); } @@ -185,7 +186,8 @@ function doTerminate() { // xAPI Extension xapi.terminateAttempt(); - + doSetValue("cmi.progress_measure", 0.99); + xapi.measureProgress(); // call the Terminate function that should be implemented by the API var result = api.Terminate(""); if (result.toString() != "true") @@ -200,6 +202,9 @@ function doTerminate() return result.toString(); } + + + /******************************************************************************* ** ** Function doGetValue(name) diff --git a/SCORMToXAPIFunctions.js b/SCORMToXAPIFunctions.js index df60c54..834d67a 100644 --- a/SCORMToXAPIFunctions.js +++ b/SCORMToXAPIFunctions.js @@ -318,7 +318,7 @@ xapi = function () { // window.localStorage[activity] uses activity id to return the most recent // attempt stmt.context.contextActivities.grouping[0].id = window.localStorage[config.activityId]; - + // set the context activity from the manifest/launch_data to group together // for an event stmt.context.contextActivities.grouping.push(config.groupingContextActivity); @@ -344,7 +344,7 @@ xapi = function () { // window.localStorage[activity] uses activity id to return the most recent // attempt stmt.context.contextActivities.grouping[0].id = window.localStorage[config.activityId]; - + // set the context activity from the manifest/launch_data to group together // for an event stmt.context.contextActivities.grouping.push(config.groupingContextActivity); @@ -367,6 +367,7 @@ xapi = function () { var scoreRaw = retrieveDataValue(scormVersionConfig.scoreRawElement); var scoreMin = retrieveDataValue(scormVersionConfig.scoreMinElement); var scoreMax = retrieveDataValue(scormVersionConfig.scoreMaxElement); + var sessionTime = retrieveDataValue(scormVersionConfig.sessionTimeElement); var resultSet = false; var resultJson = {}; @@ -426,6 +427,12 @@ xapi = function () { scoreJson.max = parseFloat(scoreMax); } + // include sessionTime if set by sco + if (sessionTime != undefined && sessionTime != ""){ + resultSet = true; + resultJson.duration = sessionTime; + } + // set the score object in with the rest of the result object if (scoreSet) { resultJson.score = scoreJson; @@ -480,10 +487,6 @@ xapi = function () { var ap = ADL.XAPIWrapper.getActivityProfile(config.activityId, constants.activityProfileIri); if (ap == null) { - // get comments from lms (if any) - //var cmi_num_comments_from_lms_count = retrieveDataValue("cmi.comments_from_lms._count"); - // todo: get the comments, if any and add to array - // get completion threshold (if supplied in manifest, only valid in SCORM2004) var cmi_completion_threshold = ""; if (config.isScorm2004){ @@ -807,6 +810,10 @@ xapi = function () { var setScore = function (value) { // For scorm 1.2, must divide raw by 100 var score = (config.isScorm2004) ? parseFloat(value) : parseFloat(value) / 100; + // Can't send statement if score is not a proper float + if (isNaN(score)){ + return; + } var stmt = getBaseStatement(); stmt.verb = ADL.verbs.scored; @@ -816,7 +823,6 @@ xapi = function () { // for an event stmt.context.contextActivities.grouping.push(config.groupingContextActivity); - // todo: add error handling if value is not a valid scaled score stmt.result = { score: { scaled: score @@ -837,6 +843,34 @@ xapi = function () { } } + + /******************************************************************************* + ** + ** This function is used to measure progress in an activity + ** + *******************************************************************************/ + var measureProgress = function () { + if (config.isScorm2004) { + var stmt = getBaseStatement(); + stmt.verb = ADL.verbs.progressed; + stmt.context.contextActivities.grouping[0].id = window.localStorage[config.activityId]; + var progressMeasure = parseFloat(retrieveDataValue(scormVersionConfig.progressMeasureElement)); + if (!isNaN(progressMeasure)){ + stmt.result = { + score: { + scaled: progressMeasure + } + }; + } + + // set the context activity from the manifest/launch_data to group together + // for an event + stmt.context.contextActivities.grouping.push(config.groupingContextActivity); + var response = ADL.XAPIWrapper.sendStatement(stmt); + } + } + + /******************************************************************************* ** ** This function is used to set pass/failed on an activity @@ -938,7 +972,14 @@ xapi = function () { creditElement: (config.isScorm2004) ? "cmi.credit" : "cmi.core.credit", modeElement: (config.isScorm2004) ? "cmi.mode" : "cmi.core.lesson_mode", suspendDataElement: "cmi.suspend_data", - totalTimeElement: (config.isScorm2004) ? "cmi.total_time" : "cmi.core.total_time" + totalTimeElement: (config.isScorm2004) ? "cmi.total_time" : "cmi.core.total_time", + //new stuff here + sessionTimeElement: (config.isScorm2004) ? "cmi.session_time" : "cmi.core.session_time", + progressMeasureElement: (config.isScorm2004) ? "cmi.progress_measure" : "", + interactionsElement: "cmi.interactions", + objectivesElement: "cmi.objectives", + learnerCommentsElement: (config.isScorm2004) ? "cmi.comments_from_learner" : "cmi.comments", + LMSCommentsElement: "cmi.comments_from_lms", } } @@ -1035,7 +1076,8 @@ xapi = function () { setScore: setScore, setComplete: setComplete, setSuccess: setSuccess, - configureLRS: configureLRS + configureLRS: configureLRS, + measureProgress:measureProgress } //