]> git.mjollnir.org Git - moodle.git/commitdiff
increase gap size for long answers in JCloze
authorgbateson <gbateson>
Sat, 18 Mar 2006 23:47:56 +0000 (23:47 +0000)
committergbateson <gbateson>
Sat, 18 Mar 2006 23:47:56 +0000 (23:47 +0000)
mod/hotpot/template/v6.php

index e639cc526987786dd244710c9c499fdc060bda26..75d93f75a3b747ec6974539b2cfa30456bf00c66 100644 (file)
@@ -866,20 +866,33 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
                // initialize loop values\r
                $q = 0;\r
                $tags = 'data,gap-fill';\r
+               $question_record = "$tags,question-record";\r
 \r
                // loop through text and gaps\r
                do {\r
                        $text = $this->parent->xml_value($tags, "[0]['#'][$q]");\r
                        $gap = '';\r
-                       if (($question="[$q]['#']") && $this->parent->xml_value("$tags,question-record", $question)) {\r
+                       if (($question="[$q]['#']") && $this->parent->xml_value($question_record, $question)) {\r
                                $gap .= '<span class="GapSpan" id="GapSpan'.$q.'">';\r
                                if ($this->v6_use_DropDownList()) {\r
                                        $gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';\r
                                } else {\r
-                                       $gap .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="6"></input>';\r
+                                       // minimum gap size\r
+                                       $gapsize = 6;\r
+\r
+                                       // increase gap size to length of longest answer for this gap\r
+                                       $a = 0;\r
+                                       while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($question_record, $answer)) {\r
+                                               $answertext = $this->parent->xml_value($question_record,  $answer."['text'][0]['#']");\r
+                                               $answertext = preg_replace('|&[#a-zA-Z0-9]+;|', 'x', $answertext);\r
+                                               $gapsize = max($gapsize, strlen($answertext));\r
+                                               $a++;\r
+                                       }\r
+\r
+                                       $gap .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="'.$gapsize.'"></input>';\r
                                }\r
                                if ($includeclues) {\r
-                                       $clue = $this->parent->xml_value("$tags,question-record", $question."['clue'][0]['#']");\r
+                                       $clue = $this->parent->xml_value($question_record, $question."['clue'][0]['#']");\r
                                        if (strlen($clue)) {\r
                                                $gap .= '<button style="line-height: 1.0" class="FuncButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowClue('.$q.')">'.$cluecaption.'</button>';\r
                                        }\r