From 330388c3acb9f25a15c964c85218eb99283bb150 Mon Sep 17 00:00:00 2001 From: gbateson Date: Wed, 8 Mar 2006 17:54:11 +0000 Subject: [PATCH] JCloze improvements: allow gap at start of cloze and allow "0" for a gap value --- mod/hotpot/template/v6.php | 51 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/mod/hotpot/template/v6.php b/mod/hotpot/template/v6.php index 842a64e9bf..e639cc5269 100644 --- a/mod/hotpot/template/v6.php +++ b/mod/hotpot/template/v6.php @@ -773,15 +773,15 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $str = ''; switch ($this->parent->quiztype) { case 'jcloze': - $str .= "I = new Array();\n"; $tags = 'data,gap-fill,question-record'; while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { $a = 0; $aa = 0; while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { $text = $this->js_value($tags, $answer."['text'][0]['#']", true); - if ($text) { + if (strlen($text)) { if ($aa==0) { // first time only + $str .= "\n"; $str .= "I[$q] = new Array();\n"; $str .= "I[$q][1] = new Array();\n"; } @@ -794,7 +794,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { // add clue, if any answers were found if ($aa) { $clue = $this->js_value($tags, $question."['clue'][0]['#']", true); - $str .= "I[$q][2]='$clue';\n"; + $str .= "I[$q][2] = '$clue';\n"; } $q++; } @@ -818,15 +818,16 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $correct = $this->int_value($tags, $answer."['correct'][0]['#']"); $percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']"); $include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']"); - if ($text) { + if (strlen($text)) { if ($aa==0) { // first time only - $str .= "I[$q]=new Array();\n"; - $str .= "I[$q][0]=$weighting;\n"; - $str .= "I[$q][1]='$clue';\n"; - $str .= "I[$q][2]='".($question_type-1)."';\n"; - $str .= "I[$q][3]=new Array();\n"; + $str .= "\n"; + $str .= "I[$q] = new Array();\n"; + $str .= "I[$q][0] = $weighting;\n"; + $str .= "I[$q][1] = '$clue';\n"; + $str .= "I[$q][2] = '".($question_type-1)."';\n"; + $str .= "I[$q][3] = new Array();\n"; } - $str .= "I[$q][3][$aa]=new Array('$text','$feedback',$correct,$percent,$include);\n"; + $str .= "I[$q][3][$aa] = new Array('$text','$feedback',$correct,$percent,$include);\n"; $aa++; } $a++; @@ -854,30 +855,44 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $includeclues = $this->v6_expand_Clues(); $cluecaption = $this->v6_expand_ClueCaption(); + // detect if cloze starts with gap + $strpos = strpos($this->parent->source, ''); + if (is_numeric($strpos)) { + $startwithgap = true; + } else { + $startwithgap = false; + } + // initialize loop values $q = 0; $tags = 'data,gap-fill'; // loop through text and gaps - while ($text = $this->parent->xml_value($tags, "[0]['#'][$q]")) { - $str .= $text; + do { + $text = $this->parent->xml_value($tags, "[0]['#'][$q]"); + $gap = ''; if (($question="[$q]['#']") && $this->parent->xml_value("$tags,question-record", $question)) { - $str .= ''; + $gap .= ''; if ($this->v6_use_DropDownList()) { - $str .= ''; + $gap .= ''; } else { - $str .= ''; + $gap .= ''; } if ($includeclues) { $clue = $this->parent->xml_value("$tags,question-record", $question."['clue'][0]['#']"); if (strlen($clue)) { - $str .= ''; + $gap .= ''; } } - $str .= ''; + $gap .= ''; + } + if ($startwithgap) { + $str .= "$gap$text"; + } else { + $str .= "$text$gap"; } $q++; - } + } while (strlen($text) || strlen($gap)); return $str; } -- 2.39.5