// Includes Communicator #include "as_scripts/clx_AICC_communicator.as" #include "as_scripts/clx_SCORM_communicator.as" #include "as_scripts/clx_LOCAL_communicator.as" #include "as_scripts/clx_XML_communicator.as" #include "as_scripts/clx_CUSTOM_communicator.as" // //----------------------- // WBT Translator Class // by Caspar Noetzli / Andy Haeberli // www.crealogix.com // vs. 0.3 2006-02-21 // ---------------------- // //--------------------------- // WBT_translator Constructor //--------------------------- WBT_translator = function (objRef) { // objRef ist eine Referenz zum CLX_Translator bzw. zum aufrufenden Object this.refController = objRef; this.version = "v2006-02-21-003_clx"; this._timer = 0; }; //--------------------------- // WBT_translator getVersion //--------------------------- WBT_translator.prototype.getVersion = function() { return ("WBT Translator Class Version: "+this.version); }; //--------------------------- // WBT_translator init //--------------------------- WBT_translator.prototype.init = function(refUser, communicationStandard, communicationDebugMode) { this.refUser = refUser; this.communicationStandard = communicationStandard; this.communicationDebugMode = communicationDebugMode; if (this.communicationStandard == "AICC") { this.communicator = new CLX_aicc_communicator(this, this.communicationDebugMode); this.communicator.init(); } if (this.communicationStandard == "SCORM") { this.communicator = new CLX_scorm_communicator(this, this.communicationDebugMode); this.communicator.init(); } if (this.communicationStandard == "LOCAL") { this.communicator = new CLX_local_communicator(this, this.communicationDebugMode, this.refUser); this.communicator.init(); } if (this.communicationStandard == "XML") { this.communicator = new CLX_xml_communicator(this, this.communicationDebugMode); this.communicator.init(); } if (this.communicationStandard == "CUSTOM") { this.communicator = new CLX_custom_communicator(this, this.communicationDebugMode); this.communicator.init(); } }; //--------------------------- // WBT_translator initCallback //--------------------------- WBT_translator.prototype.initCallback = function(error) { if (error == 0) { this.refController.translatorLoaded(); } else { // trace("Init Error: "+error); this.refController.displayError("Schnittstelle konnte nicht initialisiert werden. Es wurde keine Verbindung zum LMS hergestellt"); } }; //--------------------------- // WBT_translator getUserData //--------------------------- WBT_translator.prototype.getUserData = function() { this.communicator.getUserData(); }; //--------------------------- // WBT_translator getUserDataCallback //--------------------------- WBT_translator.prototype.getUserDataCallback = function(error) { if (error == 0) { this.refController.userDataLoaded(); } else { // trace("getUserData Error: "+error); this.refController.displayError("Benutzerdaten konnten nicht vom LMS geladen werden."); } }; //--------------------------- // WBT_translator setUserData //--------------------------- WBT_translator.prototype.setUserData = function() { this.getLesson_location(); this.getLesson_status(); this.getAttempt(); this.getScore(); this.getTime(); this.getLesson_data(); // this.communicator.setUserData(); }; //--------------------------- // WBT_translator setUserDataCallback //--------------------------- WBT_translator.prototype.setUserDataCallback = function(error) { if (error == 0) { this.refController.userDataSaved(); } else { // trace("setUserData Error: "+error); this.refController.displayError("Benutzerdaten konnten nicht ins LMS gespeichert werden."); } }; //--------------------------- // WBT_translator exit //--------------------------- WBT_translator.prototype.connectionExit = function() { this.communicator.connectionExit(); }; //--------------------------- // WBT_translator connectionExitCallback //--------------------------- WBT_translator.prototype.connectionExitCallback = function(error) { if (error == 0) { this.refController.connectionExitCallback(); } else { // trace("Exit Error: "+error); this.refController.displayError("Die Verbindung zum LMS konnte nicht beendet werden"); } }; // //======================================== // Translator zum User Data (Textfelder) // set -> Communicator zum User Data (Textfelder) // get -> User Data (Textfelder) zum Communicator //======================================== // // WBT_translator updateUserData //--------------------------- WBT_translator.prototype.updateUserData = function() { this.setStudent_id(); this.setStudent_name(); if (this.communicationStandard == "LOCAL") { if(this.communicator.getLesson_data()!= undefined && this.communicator.getLesson_data()!=""&&this.communicator.getLesson_data()!=null){ this.refUser.trackingData = this.communicator.getLesson_data() } } else { this.setLesson_status(); this.setAttempt(); this.setScore(); this.setTime(); this.setLesson_data(); } }; //--------------------------- // WBT_translator updateTrackingUserData //--------------------------- WBT_translator.prototype.updateTrackingUserData = function() { if (this.communicationStandard == "LOCAL") { var tLocation = this.communicator.getLesson_location() if(tLocation!= undefined && tLocation!=""&&tLocation!=null){ this.refUser.setLocation(tLocation.chapter,tLocation.subchapter,tLocation.item) } } else { this.setLesson_location(); } }; //--------------------------- // WBT_translator setStudent_id //--------------------------- WBT_translator.prototype.setStudent_id = function() { this.refUser.setID(this.communicator.getStudent_id()); }; //--------------------------- // WBT_translator setStudent_name //--------------------------- WBT_translator.prototype.setStudent_name = function() { tName_array = this.communicator.getStudent_name().split(","); this.refUser.setName(tName_array[0]); this.refUser.setVorname(tName_array[1]); }; //--------------------------- // WBT_translator setLesson_location //--------------------------- WBT_translator.prototype.setLesson_location = function() { tLocation_array = this.communicator.getLesson_location().split(","); this.refUser.setLocation(Number(tLocation_array[0]), Number(tLocation_array[1]), Number(tLocation_array[2])); }; //--------------------------- // WBT_translator getLesson_location //--------------------------- WBT_translator.prototype.getLesson_location = function() { var tLocation = this.refUser.getLocation(); this.communicator.setLesson_location(tLocation.chapter+","+tLocation.subchapter+","+tLocation.item); }; //--------------------------- // WBT_translator setLesson_status //--------------------------- WBT_translator.prototype.setLesson_status = function() { this.refUser.setStatus(this.communicator.getLesson_status()); }; //--------------------------- // WBT_translator getLesson_status //--------------------------- WBT_translator.prototype.getLesson_status = function() { var tStatus = this.refUser.getTotalStatus(); if (Math.round(100/tStatus.anzahlItemTotal*tStatus.anzahlItemVisited)>=100) { if(this.refController.test_mode.isTestmodul == "true") { var tScore = this.refController.user.getTotalTestmodusScore(); if (tScore.scoreTotalPercent>=tScore.scoreCutvaluePercent) { this.communicator.setLesson_status("passed"); } else { this.communicator.setLesson_status("failed"); } } else { this.communicator.setLesson_status("completed"); } } else { this.communicator.setLesson_status("incomplete"); } }; //--------------------------- // WBT_translator setAttempt //--------------------------- WBT_translator.prototype.setAttempt = function() { this.refUser.setAttempt(this.communicator.getAttempt()); }; //--------------------------- // WBT_translator getAttempt //--------------------------- WBT_translator.prototype.getAttempt = function() { this.communicator.setAttempt(this.refUser.getAttempt()); } //--------------------------- // WBT_translator setScore //--------------------------- WBT_translator.prototype.setScore = function() { // not avaible }; //--------------------------- // WBT_translator getScore //--------------------------- WBT_translator.prototype.getScore = function() { var tScore = this.refUser.getTotalTestmodusScore(); this.communicator.setScore(tScore.scoreTotalPercent); }; //--------------------------- // WBT_translator getTime //--------------------------- WBT_translator.prototype.getTime = function() { if (this.communicationStandard == "CUSTOM") { this.communicator.setTime(this.convertTime(this.refUser.getTotalTime()*1000)); } else { if(this.communicator.comVersion == '1.0') { this.communicator.setTime(this.refUser.getTotalTime()); } else { this.communicator.setTime(this.convertTime(getTimer()-this._timer)); } this._timer = getTimer(); } }; //--------------------------- // WBT_translator setTime //--------------------------- WBT_translator.prototype.setTime = function() { if(this.refController.modultype != "testmodul") { if(this.communicator.getTime() == "noValue") { this.refUser.setTime(0); } else { this.refUser.setTime(this.reconvertTime(this.communicator.getTime())); } } }; //--------------------------- // WBT_translator setLesson_data //--------------------------- WBT_translator.prototype.setLesson_data = function() { this.deserializeTrackingData(this.communicator.getLesson_data()); }; //--------------------------- // WBT_translator getLesson_data //--------------------------- WBT_translator.prototype.getLesson_data = function() { this.communicator.setLesson_data(this.serializeTrackingData("status", "time", "score")); }; // //======================================== // Check Communicator Daten //======================================== // // WBT_translator checkUserDataLoaded //--------------------------- WBT_translator.prototype.checkUserDataLoaded = function() { var tLocation = this.communicator.getLesson_location(); var tData = this.communicator.getLesson_data(); if (tLocation != "noValue" && tLocation != 0 && tLocation != "" && tLocation != null && tData != "noValue" && tData != 0 && tData != "" && tData != null) { return true; } else { return false; } }; // //======================================== // Help Functions //======================================== // //--------------------------- // WBT_translator convertTime //--------------------------- WBT_translator.prototype.convertTime = function(whichTime) { // von Millisekunden in Sekunden umwandeln var tTime = Math.round(whichTime/1000); // Anzahl Sekunden var tTimeSec = tTime%60; // Anzahl Minuten in Sekunden var tTimeMin = (tTime-tTimeSec)%3600; // Anzahl Stunden in Sekunden var tTimeHour = (tTime-tTimeMin-tTimeSec); // Sekunden var tSec = tTimeSec; // Minuten var tMin = tTimeMin/60; // Stunden var tHour = tTimeHour/3600; // // Formatierung if (tSec<10) { tSec = "0"+tSec; } if (this.communicationStandard == "SCORM" || this.communicationStandard == "CUSTOM") { tSec = tSec+".00"; } if (tMin<10) { tMin = "0"+tMin; } if (tHour<10) { tHour = "0"+tHour; } if (this.communicationStandard == "SCORM" || this.communicationStandard == "CUSTOM") { if (tHour<100) { tHour = "0"+tHour; } if (tHour<1000) { tHour = "0"+tHour; } } return tHour+":"+tMin+":"+tSec; // xtrace(tHour+":"+tMin+":"+tSec); }; //--------------------------- // WBT_translator reconvertTime //--------------------------- WBT_translator.prototype.reconvertTime = function(whichTime) { var tTime = 0; var tTime_array = whichTime.split(":"); // Anzahl Stunden in Millisekunden var tHour = tTime_array[0]; for (var i = 0; i