From 858db1daee169f25d7ece7a1ad7acb2749ac3198 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 26 Sep 2007 06:05:19 +0200 Subject: [PATCH] [svn r13251] More improvements to the quiz SCORM export: - removed Hotspot temporarily (with warning message) - added score-max-min management - fixed scoring for matching questions - fixed weight of answers --- main/exercice/export/scorm/scorm_classes.php | 57 ++++++++++++++--- main/newscorm/js/api_wrapper.js | 66 ++++++++++++++++---- 2 files changed, 103 insertions(+), 20 deletions(-) diff --git a/main/exercice/export/scorm/scorm_classes.php b/main/exercice/export/scorm/scorm_classes.php index f9f5857055..e6a5692b84 100755 --- a/main/exercice/export/scorm/scorm_classes.php +++ b/main/exercice/export/scorm/scorm_classes.php @@ -127,7 +127,14 @@ class ScormQuestion extends Question function getQuestionJS() { //$id = $this->id; + $w = $this->selectWeighting(); $s = 'questions.push('.$this->id.');'."\n"; + if($this->type == FREE_ANSWER or $this->type == HOTSPOT) + { //put the max score to 0 to avoid discounting the points of + //non-exported quiz types in the SCORM + $w=0; + } + $s .= 'questions_score_max['.$this->id.'] = '.$w.";\n"; return $s; } } @@ -147,6 +154,8 @@ class ScormAnswerMultipleChoice extends Answer $js = ''; $html = '' . "\n"; $type = $this->getQuestionType(); + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; if ($type == MCMA) { //$questionTypeLang = get_lang('MultipleChoiceMultipleAnswers'); @@ -170,11 +179,13 @@ class ScormAnswerMultipleChoice extends Answer { $jstmpc .= $i.','; } + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.']['.$i.'] = '.$this->weighting[$i].";\n"; $id++; } $js .= 'questions_answers['.$this->questionId.'] = new Array('.substr($jstmp,0,-1).');'."\n"; $js .= 'questions_answers_correct['.$this->questionId.'] = new Array('.substr($jstmpc,0,-1).');'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'mcma\';'."\n"; + $js .= $jstmpw; } else { @@ -199,11 +210,13 @@ class ScormAnswerMultipleChoice extends Answer { $jstmpc .= $i; } + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.']['.$i.'] = '.$this->weighting[$i].";\n"; $id++; } $js .= 'questions_answers['.$this->questionId.'] = new Array('.substr($jstmp,0,-1).');'."\n"; $js .= 'questions_answers_correct['.$this->questionId.'] = '.$jstmpc.';'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'mcua\';'."\n"; + $js .= $jstmpw; } $html .= '
' . "\n"; return array($js,$html); @@ -247,9 +260,8 @@ class ScormAnswerTrueFalse extends Answer . '' . "\n" . '' . "\n" . '' . "\n" - . '' . "\n\n" - - . '' . "\n"; + . '' . "\n\n"; + $html .= '' . "\n"; $js .= 'questions_answers['.$this->questionId.'] = new Array(\'true\',\'false\');'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'tf\';'."\n"; if($this->response == 'TRUE') @@ -260,7 +272,10 @@ class ScormAnswerTrueFalse extends Answer { $js .= 'questions_answers_correct['.$this->questionId.'] = new Array(\'false\');'."\n"; } - $html .= '' . "\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][1] = '.$this->weighting[1].";\n"; + $js .= $jstmpw; return array($js,$html); } } @@ -292,13 +307,15 @@ class ScormAnswerFillInBlanks extends Answer // splits text and weightings that are joined with the character '::' - list($answer)=explode('::',$answer); - + list($answer,$weight)=explode('::',$answer); + $weights = explode(',',$weight); // because [] is parsed here we follow this procedure: // 1. find everything between the [ and ] tags $i=1; $jstmp = ''; $jstmpc = ''; + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; $startlocations=strpos($answer,'['); $endlocations=strpos($answer,']'); while($startlocations !== false && $endlocations !== false) @@ -307,6 +324,7 @@ class ScormAnswerFillInBlanks extends Answer $answer = substr_replace($answer,'',$startlocations,($endlocations-$startlocations)+1); $jstmp .= $i.','; $jstmpc .= "'".htmlentities(substr($texstring,1,-1),ENT_QUOTES)."',"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.']['.$i.'] = '.$weights[$i-1].";\n"; $i++; $startlocations=strpos($answer,'['); $endlocations=strpos($answer,']'); @@ -321,6 +339,7 @@ class ScormAnswerFillInBlanks extends Answer $js .= 'questions_answers['.$this->questionId.'] = new Array('.substr($jstmp,0,-1).');'."\n"; $js .= 'questions_answers_correct['.$this->questionId.'] = new Array('.substr($jstmpc,0,-1).');'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'fib\';'."\n"; + $js .= $jstmpw; return array($js,$html); } @@ -356,12 +375,15 @@ class ScormAnswerMatching extends Answer $s = ''; $jstmp = ''; $jstmpc = ''; + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $identifier = 'question_'.$qId.'_matching_'; $answer=$this->selectAnswer($answerId); $answerCorrect=$this->isCorrect($answerId); $weight=$this->selectWeighting($answerId); + $jstmp .= $answerId.','; if(!$answerCorrect) { @@ -390,8 +412,8 @@ class ScormAnswerMatching extends Answer else $s.=' '; $s.="\n\n"; - $jstmp .= $cpt2.','; - $jstmpc .= '['.$cpt2.',\''.$cpt2.'\'],'; + $jstmpc .= '['.$answerCorrect.','.$cpt2.'],'; + $jstmpw .= 'questions_answers_ponderation['.$qId.']['.$cpt2.'] = '.$weight.";\n"; $cpt2++; // if the left side of the "matching" has been completely shown @@ -416,6 +438,7 @@ class ScormAnswerMatching extends Answer $js .= 'questions_answers['.$this->questionId.'] = new Array('.substr($jstmp,0,-1).');'."\n"; $js .= 'questions_answers_correct['.$this->questionId.'] = new Array('.substr($jstmpc,0,-1).');'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'matching\';'."\n"; + $js .= $jstmpw; $html .= $s; $html .= '' . "\n"; return array($js,$html); @@ -446,9 +469,15 @@ class ScormAnswerFree extends Answer . '' . "\n" . '' . "\n"; $html .= '' . "\n"; + // currently the free answers cannot be displayed, so ignore the textarea + $html = ''.get_lang('CannotExportToScorm').''; $js .= 'questions_answers['.$this->questionId.'] = new Array();'."\n"; $js .= 'questions_answers_correct['.$this->questionId.'] = new Array();'."\n"; $js .= 'questions_types['.$this->questionId.'] = \'free\';'."\n"; + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][1] = 0'.";\n"; + $js .= $jstmpw; return array($js,$html); } } @@ -586,7 +615,10 @@ class ScormAnswerHotspot extends Answer $header .= 'questions_answers['.$this->questionId.'] = new Array();'."\n"; $header .= 'questions_answers_correct['.$this->questionId.'] = new Array();'."\n"; $header .= 'questions_types['.$this->questionId.'] = \'hotspot\';'."\n"; - + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][1] = 0'.";\n"; + $header .= $jstmpw; } else { @@ -594,6 +626,10 @@ class ScormAnswerHotspot extends Answer $header .= 'questions_answers['.$this->questionId.'] = new Array();'."\n"; $header .= 'questions_answers_correct['.$this->questionId.'] = new Array();'."\n"; $header .= 'questions_types['.$this->questionId.'] = \'hotspot\';'."\n"; + $jstmpw = 'questions_answers_ponderation['.$this->questionId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][0] = 0;'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionId.'][1] = 0;'."\n"; + $header .= $jstmpw; } return $header; } @@ -668,6 +704,9 @@ class ScormAnswerHotspot extends Answer $answer_list"; $html .= '' . "\n"; + + // currently the free answers cannot be displayed, so ignore the textarea + $html = ''.get_lang('CannotExportToScorm').''; return array($js,$html); } } diff --git a/main/newscorm/js/api_wrapper.js b/main/newscorm/js/api_wrapper.js index cf6cf6f2e1..1ca099b31f 100644 --- a/main/newscorm/js/api_wrapper.js +++ b/main/newscorm/js/api_wrapper.js @@ -406,7 +406,8 @@ var questions = new Array(); var questions_answers = new Array(); var questions_answers_correct = new Array(); var questions_types = new Array(); - +var questions_score_max = new Array(); +var questions_answers_ponderation = new Array(); /** * Checks the answers on the test formular page */ @@ -414,6 +415,7 @@ function checkAnswers(interrupted) { var tmpScore = 0; var status = 'not attempted'; + var scoreMax = 0; for(var i=0; i mastery_score) {