|
|
|
@ -11,11 +11,10 @@ |
|
|
|
|
* Find the SCO functions (startTimer, computeTime, etc in the second section) |
|
|
|
|
* Find the Chamilo-proper functions (checkAnswers, etc in the third section) |
|
|
|
|
*/ |
|
|
|
|
var _debug = false; |
|
|
|
|
var _debug = true; |
|
|
|
|
var findAPITries = 0; |
|
|
|
|
var _apiHandle = null; //private variable
|
|
|
|
|
var errMsgLocate = "Unable to locate the LMS's API implementation" |
|
|
|
|
|
|
|
|
|
var errMsgLocate = "Unable to locate the LMS's API implementation"; |
|
|
|
|
var _NoError = 0; |
|
|
|
|
var _GeneralException = 101; |
|
|
|
|
var _ServerBusy = 102; |
|
|
|
@ -34,11 +33,12 @@ var _IncorrectDataType = 405; |
|
|
|
|
* Using the singleton pattern to ensure there's only one API object. |
|
|
|
|
* @return object The API object as given by the LMS |
|
|
|
|
*/ |
|
|
|
|
var API = new function () |
|
|
|
|
var API = new function() |
|
|
|
|
{ |
|
|
|
|
if (_apiHandle == null) { |
|
|
|
|
_apiHandle = getAPI(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return _apiHandle; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -96,14 +96,14 @@ function ErrorHandler() |
|
|
|
|
errDescription += "\n"; |
|
|
|
|
errDescription += api.LMSGetDiagnostic(null); |
|
|
|
|
} |
|
|
|
|
alert(errDescription); |
|
|
|
|
console.log(errDescription); |
|
|
|
|
} else { |
|
|
|
|
var errDescription = API.LMSGetErrorString(errCode); |
|
|
|
|
if (_debug) { |
|
|
|
|
errDescription += "\n"; |
|
|
|
|
errDescription += api.LMSGetDiagnostic(null); |
|
|
|
|
} |
|
|
|
|
alert(errDescription); |
|
|
|
|
console.log(errDescription); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return errCode; |
|
|
|
@ -161,7 +161,6 @@ function doLMSGetValue(name) |
|
|
|
|
var errDescription = API.LMSGetErrorString(errCode); |
|
|
|
|
alert("LMSGetValue(" + name + ") failed. \n" + errDescription); |
|
|
|
|
return ""; |
|
|
|
|
return value.toString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -400,8 +399,14 @@ function checkAnswers(interrupted) |
|
|
|
|
var tmpScore = 0; |
|
|
|
|
var status = 'not attempted'; |
|
|
|
|
var scoreMax = 0; |
|
|
|
|
for (var i=0; i<questions.length;i++) { |
|
|
|
|
if(questions[i] != undefined && questions[i] != null){ |
|
|
|
|
|
|
|
|
|
if (_debug) { |
|
|
|
|
console.log('questions_answers_correct:'); |
|
|
|
|
console.log(questions_answers_correct); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (var i=0; i < questions.length; i++) { |
|
|
|
|
if (questions[i] != undefined && questions[i] != null){ |
|
|
|
|
var idQuestion = questions[i]; |
|
|
|
|
var type = questions_types[idQuestion]; |
|
|
|
|
var interactionScore = 0; |
|
|
|
@ -409,28 +414,46 @@ function checkAnswers(interrupted) |
|
|
|
|
var interactionCorrectResponses = ''; |
|
|
|
|
var interactionType = ''; |
|
|
|
|
|
|
|
|
|
if (_debug) { |
|
|
|
|
console.log('Type: ' +type); |
|
|
|
|
console.log('idQuestion: ' +idQuestion); |
|
|
|
|
console.log('questions_answers: '); |
|
|
|
|
console.log(questions_answers[idQuestion]); |
|
|
|
|
console.log('questions_answers_ponderation: '); |
|
|
|
|
console.log(questions_answers_ponderation[idQuestion]); |
|
|
|
|
console.log('questions_answers_correct: '); |
|
|
|
|
console.log(questions_answers_correct[idQuestion]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (type == 'mcma') { |
|
|
|
|
var interactionType = 'choice'; |
|
|
|
|
interactionType = 'choice'; |
|
|
|
|
var myScore = 0; |
|
|
|
|
for(var j=0; j<questions_answers[idQuestion].length;j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
|
var answer = document.getElementById('question_'+(idQuestion)+'_multiple_'+(idAnswer)); |
|
|
|
|
if (answer.checked) { |
|
|
|
|
interactionAnswers += idAnswer+'__|';// changed by isaac flores
|
|
|
|
|
myScore +=questions_answers_ponderation[idQuestion][idAnswer]; |
|
|
|
|
myScore += questions_answers_ponderation[idQuestion][idAnswer]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
interactionScore = myScore; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+myScore); |
|
|
|
|
} |
|
|
|
|
} else if (type == 'mcua') { |
|
|
|
|
var interactionType = 'choice'; |
|
|
|
|
interactionType = 'choice'; |
|
|
|
|
var myScore = 0; |
|
|
|
|
for (var j=0; j<questions_answers[idQuestion].length;j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
|
var answer = document.getElementById('question_'+(idQuestion)+'_unique_'+(idAnswer)); |
|
|
|
|
if (answer.checked) { |
|
|
|
|
interactionAnswers += idAnswer; |
|
|
|
|
if (questions_answers_correct[idQuestion] == idAnswer) { |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("idAnswer: "+idAnswer); |
|
|
|
|
console.log("questions_answers_correct: "+questions_answers_correct[idQuestion][idAnswer]); |
|
|
|
|
} |
|
|
|
|
if (questions_answers_correct[idQuestion][idAnswer] == idAnswer) { |
|
|
|
|
if (questions_answers_ponderation[idQuestion][idAnswer]) { |
|
|
|
|
myScore += questions_answers_ponderation[idQuestion][idAnswer]; |
|
|
|
|
} else { |
|
|
|
@ -439,10 +462,13 @@ function checkAnswers(interrupted) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+myScore); |
|
|
|
|
} |
|
|
|
|
interactionScore = myScore; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
} else if (type == 'tf') { |
|
|
|
|
var interactionType = 'true-false'; |
|
|
|
|
interactionType = 'true-false'; |
|
|
|
|
var myScore = 0; |
|
|
|
|
for (var j = 0; j < questions_answers[idQuestion].length; j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
@ -460,10 +486,13 @@ function checkAnswers(interrupted) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+myScore); |
|
|
|
|
} |
|
|
|
|
interactionScore = myScore; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
} else if (type == 'fib') { |
|
|
|
|
var interactionType = 'fill-in'; |
|
|
|
|
interactionType = 'fill-in'; |
|
|
|
|
var myScore = 0; |
|
|
|
|
for (var j = 0; j < questions_answers[idQuestion].length; j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
@ -481,10 +510,13 @@ function checkAnswers(interrupted) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+myScore); |
|
|
|
|
} |
|
|
|
|
interactionScore = myScore; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
} else if (type == 'matching') { |
|
|
|
|
var interactionType = 'matching'; |
|
|
|
|
interactionType = 'matching'; |
|
|
|
|
var myScore = 0; |
|
|
|
|
for (var j = 0; j < questions_answers[idQuestion].length; j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
@ -504,24 +536,28 @@ function checkAnswers(interrupted) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+myScore); |
|
|
|
|
} |
|
|
|
|
interactionScore = myScore; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
} else if (type == 'free') { |
|
|
|
|
//ignore for now as a score cannot be given
|
|
|
|
|
var interactionType = 'free'; |
|
|
|
|
interactionType = 'free'; |
|
|
|
|
var answer = document.getElementById('question_'+(idQuestion)+'_free'); |
|
|
|
|
if (answer && answer.value) { |
|
|
|
|
interactionAnswers += answer.value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interactionScore = questions_score_max[idQuestion]; |
|
|
|
|
//interactionScore = questions_score_max[idQuestion];
|
|
|
|
|
interactionScore = 0; |
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
|
|
|
|
|
//interactionAnswers = document.getElementById('question_'+(idQuestion)+'_free').value;
|
|
|
|
|
//correct responses work by pattern, see SCORM Runtime Env Doc
|
|
|
|
|
//interactionCorrectResponses += questions_answers_correct[idQuestion].toString();
|
|
|
|
|
} else if (type == 'hotspot') { |
|
|
|
|
var interactionType = 'sequencing'; |
|
|
|
|
interactionType = 'sequencing'; |
|
|
|
|
interactionScore = 0; |
|
|
|
|
//if(question_score && question_score[idQuestion]){
|
|
|
|
|
// interactionScore = question_score[idQuestion];
|
|
|
|
@ -533,65 +569,58 @@ function checkAnswers(interrupted) |
|
|
|
|
// interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+',';
|
|
|
|
|
//}
|
|
|
|
|
} else if (type == 'exact') { |
|
|
|
|
var interactionType = 'exact'; |
|
|
|
|
interactionType = 'exact'; |
|
|
|
|
interactionScore = 0; |
|
|
|
|
// not yet implemented see scorm_classes.php ScormAnswerMultipleChoice::export() function
|
|
|
|
|
/* |
|
|
|
|
|
|
|
|
|
var myScore = 0; |
|
|
|
|
var real_answers = new Array(); |
|
|
|
|
|
|
|
|
|
for(var j=0; j<questions_answers[idQuestion].length;j++) { |
|
|
|
|
for (var j = 0; j < questions_answers[idQuestion].length; j++) { |
|
|
|
|
var idAnswer = questions_answers[idQuestion][j]; |
|
|
|
|
var answer = document.getElementById('question_'+(idQuestion)+'_multiple_'+(idAnswer)); |
|
|
|
|
if (answer.checked) { |
|
|
|
|
if(questions_answers_ponderation[idQuestion][idAnswer] != 0 ) { |
|
|
|
|
var answer = document.getElementById('question_' + (idQuestion) + '_exact_' + (idAnswer)); |
|
|
|
|
|
|
|
|
|
if (answer.checked == true) { |
|
|
|
|
interactionAnswers += idAnswer+', '; |
|
|
|
|
if (questions_answers_correct[idQuestion][idAnswer] != 0) { |
|
|
|
|
real_answers[j] = true; |
|
|
|
|
} else { |
|
|
|
|
real_answers[j] = false; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if(questions_answers_ponderation[idQuestion][idAnswer] != 0) { |
|
|
|
|
if (questions_answers_correct[idQuestion][idAnswer] != 0) { |
|
|
|
|
real_answers[j] = false; |
|
|
|
|
} else { |
|
|
|
|
real_answers[j] = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//alert(real_answers[j] +' ' + answer.checked + ' ' + questions_answers_ponderation[idQuestion][idAnswer]);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var final_answer = true; |
|
|
|
|
for(var z=0; z<real_answers.length ;z++) { |
|
|
|
|
if (!real_answers[z]) { |
|
|
|
|
final_answer = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (final_answer) { |
|
|
|
|
for (var z = 0; z < real_answers.length; z++) { |
|
|
|
|
if (real_answers[z] == false) { |
|
|
|
|
final_answer = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
interactionScore = 0; |
|
|
|
|
console.log(real_answers); |
|
|
|
|
if (final_answer) { |
|
|
|
|
//getting only the first score where we save the weight of all the question
|
|
|
|
|
myScore += questions_answers_ponderation[idQuestion][1]; |
|
|
|
|
interactionScore = questions_answers_ponderation[idQuestion][1]; |
|
|
|
|
} |
|
|
|
|
if (_debug) { |
|
|
|
|
console.log("Score: "+interactionScore); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interactionScore = myScore; |
|
|
|
|
//correct responses work by pattern, see SCORM Runtime Env Doc
|
|
|
|
|
//for(k=0;k<questions_answers_correct[idQuestion].length;k++)
|
|
|
|
|
//{
|
|
|
|
|
// interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+',';
|
|
|
|
|
//}
|
|
|
|
|
scoreMax += questions_score_max[idQuestion]; |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
tmpScore += interactionScore; |
|
|
|
|
|
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.id','Q'+idQuestion); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.type',interactionType); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.student_response',interactionAnswers); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.result',interactionScore); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.id', 'Q'+idQuestion); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.type', interactionType); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.student_response', interactionAnswers); |
|
|
|
|
doLMSSetValue('cmi.interactions.'+idQuestion+'.result', interactionScore); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
doLMSSetValue('cmi.core.score.min', 0); |
|
|
|
|
doLMSSetValue('cmi.core.score.max', scoreMax); |
|
|
|
|
doLMSSetValue('cmi.core.score.raw', tmpScore); |
|
|
|
|
|
|
|
|
|
//get status
|
|
|
|
|
var mastery_score = doLMSGetValue('cmi.student_data.mastery_score'); |
|
|
|
|
if (mastery_score <= 0) { |
|
|
|
@ -602,6 +631,14 @@ function checkAnswers(interrupted) |
|
|
|
|
} else { |
|
|
|
|
status = 'failed'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_debug) { |
|
|
|
|
console.log('student_score: ' + tmpScore); |
|
|
|
|
console.log('mastery_score: ' + mastery_score); |
|
|
|
|
console.log('cmi.core.score.max: ' + scoreMax); |
|
|
|
|
console.log('cmi.core.lesson_status: ' + status); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
doLMSSetValue('cmi.core.lesson_status', status); |
|
|
|
|
|
|
|
|
|
if (interrupted && (status != 'completed') && (status != 'passed')) { |