|
|
|
|
@ -16,9 +16,7 @@ class ScormAnswerFillInBlanks extends Answer |
|
|
|
|
*/ |
|
|
|
|
public function export() |
|
|
|
|
{ |
|
|
|
|
global $charset; |
|
|
|
|
$js = ''; |
|
|
|
|
$html = '<tr><td colspan="2"><table width="100%">'; |
|
|
|
|
// get all enclosed answers |
|
|
|
|
$blankList = []; |
|
|
|
|
foreach ($this->answer as $i => $answer) { |
|
|
|
|
@ -26,64 +24,54 @@ class ScormAnswerFillInBlanks extends Answer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// splits text and weightings that are joined with the character '::' |
|
|
|
|
list($answer, $weight) = explode('::', $answer); |
|
|
|
|
$listAnswerInfo = FillBlanks::getAnswerInfo($answer); |
|
|
|
|
//$switchableAnswerSet = $listAnswerInfo['switchable']; |
|
|
|
|
|
|
|
|
|
$switchable = explode('@', $weight); |
|
|
|
|
$isSetSwitchable = false; |
|
|
|
|
if (isset($switchable[1]) && $switchable[1] == 1) { |
|
|
|
|
$isSetSwitchable = true; |
|
|
|
|
// display empty [input] with the right width for student to fill it |
|
|
|
|
$answer = ''; |
|
|
|
|
$answerList = []; |
|
|
|
|
for ($i = 0; $i < count($listAnswerInfo['common_words']) - 1; $i++) { |
|
|
|
|
// display the common words |
|
|
|
|
$answer .= $listAnswerInfo['common_words'][$i]; |
|
|
|
|
// display the blank word |
|
|
|
|
$attributes['style'] = 'width:'.$listAnswerInfo['input_size'][$i].'px'; |
|
|
|
|
$answer .= FillBlanks::getFillTheBlankHtml( |
|
|
|
|
$this->questionJSId, |
|
|
|
|
$this->questionJSId+1, |
|
|
|
|
'', |
|
|
|
|
$attributes, |
|
|
|
|
$answer, |
|
|
|
|
$listAnswerInfo, |
|
|
|
|
true, |
|
|
|
|
$i, |
|
|
|
|
'question_'.$this->questionJSId.'_fib_'.($i + 1) |
|
|
|
|
); |
|
|
|
|
$answerList[] = $i + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$weights = explode(',', $switchable[0]); |
|
|
|
|
// display the last common word |
|
|
|
|
$answer .= $listAnswerInfo['common_words'][$i]; |
|
|
|
|
|
|
|
|
|
// because [] is parsed here we follow this procedure: |
|
|
|
|
// 1. find everything between the [ and ] tags |
|
|
|
|
$i = 1; |
|
|
|
|
$jstmp = ''; |
|
|
|
|
$jstmpc = ''; |
|
|
|
|
$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; |
|
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; |
|
|
|
|
$startlocations = api_strpos($answer, '['); |
|
|
|
|
$endlocations = api_strpos($answer, ']'); |
|
|
|
|
while ($startlocations !== false && $endlocations !== false) { |
|
|
|
|
$texstring = api_substr($answer, $startlocations, ($endlocations - $startlocations) + 1); |
|
|
|
|
$replaceText = '<input |
|
|
|
|
type="text" |
|
|
|
|
name="question_'.$this->questionJSId.'_fib_'.$i.'" |
|
|
|
|
id = "question_'.$this->questionJSId.'_fib_'.$i.'" |
|
|
|
|
size="10" value="" |
|
|
|
|
/>'; |
|
|
|
|
$answer = api_substr_replace( |
|
|
|
|
$answer, |
|
|
|
|
$replaceText, |
|
|
|
|
$startlocations, |
|
|
|
|
($endlocations - $startlocations) + 1 |
|
|
|
|
); |
|
|
|
|
$jstmp .= $i.','; |
|
|
|
|
if (!empty($texstring)) { |
|
|
|
|
$sub = api_substr($texstring, 1, -1); |
|
|
|
|
if (!empty($sub)) { |
|
|
|
|
$jstmpc .= "'".api_htmlentities($sub, ENT_QUOTES, $charset)."',"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$my_weight = explode('@', $weights[$i - 1]); |
|
|
|
|
if (count($my_weight) == 2) { |
|
|
|
|
$weight_db = $my_weight[0]; |
|
|
|
|
} else { |
|
|
|
|
$weight_db = $my_weight[0]; |
|
|
|
|
} |
|
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$weight_db.";\n"; |
|
|
|
|
$i++; |
|
|
|
|
$startlocations = api_strpos($answer, '['); |
|
|
|
|
$endlocations = api_strpos($answer, ']'); |
|
|
|
|
|
|
|
|
|
foreach ($listAnswerInfo['weighting'] as $key => $weight) { |
|
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.($key + 1).'] = '.$weight.";\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$wordList = "'".implode("', '", $listAnswerInfo['words'])."'"; |
|
|
|
|
$answerList = "'".implode("', '", $answerList)."'"; |
|
|
|
|
|
|
|
|
|
$html = '<tr><td colspan="2"><table width="100%">'; |
|
|
|
|
$html .= '<tr> |
|
|
|
|
<td> |
|
|
|
|
'.$answer.' |
|
|
|
|
</td> |
|
|
|
|
</tr></table></td></tr>'; |
|
|
|
|
$js .= 'questions_answers['.$this->questionJSId.'] = new Array('.api_substr($jstmp, 0, -1).');'."\n"; |
|
|
|
|
$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.api_substr($jstmpc, 0, -1).');'."\n"; |
|
|
|
|
$js .= 'questions_answers['.$this->questionJSId.'] = new Array('.$answerList.');'."\n"; |
|
|
|
|
$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.$wordList.');'."\n"; |
|
|
|
|
$js .= 'questions_types['.$this->questionJSId.'] = \'fib\';'."\n"; |
|
|
|
|
$js .= $jstmpw; |
|
|
|
|
|
|
|
|
|
|