From 2109fc9591040cc627a94dfb2d70fd1fdcfb86bd Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 1 Aug 2018 11:20:13 +0200 Subject: [PATCH] WIP - Fix FillInBlank question export from LP to SCORM see BT#14644 - TODO: Fix issue with special characters (cyrillic, accents, etc) --- .../export/scorm/ScormAnswerFillInBlanks.php | 80 ++++++++----------- 1 file changed, 34 insertions(+), 46 deletions(-) diff --git a/main/exercise/export/scorm/ScormAnswerFillInBlanks.php b/main/exercise/export/scorm/ScormAnswerFillInBlanks.php index c1119b5d53..69567b0b08 100644 --- a/main/exercise/export/scorm/ScormAnswerFillInBlanks.php +++ b/main/exercise/export/scorm/ScormAnswerFillInBlanks.php @@ -16,9 +16,7 @@ class ScormAnswerFillInBlanks extends Answer */ public function export() { - global $charset; $js = ''; - $html = ''; // 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 = ''; - $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 = ''; - $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;
'; $html .= '
'.$answer.'