From accb4c04eb7e6521c9a543a13b34a394474a92ff Mon Sep 17 00:00:00 2001 From: gbateson Date: Sun, 13 Jul 2008 12:22:32 +0000 Subject: [PATCH] improvements to generation of html from xml: JCloze: set textbox size allowing for minimum gap size setting and longest answer; JMatch: allow for duplicates and distractors in RHS items; JQuiz: set textbox size allowing for longest answer, and use textarea if answer longer than 29 chars; --- mod/hotpot/template/v6.php | 84 ++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/mod/hotpot/template/v6.php b/mod/hotpot/template/v6.php index 603b73cbcb..69d177c208 100644 --- a/mod/hotpot/template/v6.php +++ b/mod/hotpot/template/v6.php @@ -715,9 +715,14 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $this->set_jmatch_items(); $str = ''; foreach ($this->l_items as $i=>$item) { + for ($ii=0; $ii<$i; $ii++) { + if ($this->r_items[$ii]['text']==$this->r_items[$i]['text']) { + break; + } + } $str .= "F[$i] = new Array();\n"; $str .= "F[$i][0] = '".$this->js_safe($item['text'], true)."';\n"; - $str .= "F[$i][1] = ".($i+1).";\n"; + $str .= "F[$i][1] = ".($ii+1).";\n"; } return $str; } @@ -725,33 +730,51 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $this->set_jmatch_items(); $str = ''; foreach ($this->r_items as $i=>$item) { + for ($ii=0; $ii<$i; $ii++) { + if ($this->r_items[$ii]['text']==$this->r_items[$i]['text']) { + break; + } + } $str .= "D[$i] = new Array();\n"; $str .= "D[$i][0] = '".$this->js_safe($item['text'], true)."';\n"; - $str .= "D[$i][1] = ".($i+1).";\n"; - $str .= "D[$i][2] = '".$item['fixed']."';\n"; + $str .= "D[$i][1] = ".($ii+1).";\n"; + $str .= "D[$i][2] = ".$item['fixed'].";\n"; } return $str; } function set_jmatch_items() { - if (empty($this->l_items)) { - $tags = 'data,matching-exercise,pair'; - $i = 0; - while (($leftitem = "[$i]['#']['left-item'][0]['#']") && $this->parent->xml_value($tags, $leftitem)) { - $lefttext = $this->parent->xml_value($tags, $leftitem."['text'][0]['#']"); - if (strlen($lefttext)) { - $this->l_items[] = array( - 'text' => $lefttext, - 'fixed' => $this->int_value($tags, $leftitem."['fixed'][0]['#']") - ); - $rightitem = "[$i]['#']['right-item'][0]['#']"; - $this->r_items[] = array( - 'text' => $this->parent->xml_value($tags, $rightitem."['text'][0]['#']"), - 'fixed' => $this->int_value($tags, $rightitem."['fixed'][0]['#']") - ); - } - $i++; + if (count($this->l_items)) { + return; + } + $tags = 'data,matching-exercise,pair'; + $i = 0; + while (($item = "[$i]['#']") && $this->parent->xml_value($tags, $item)) { + $leftitem = $item."['left-item'][0]['#']"; + $lefttext = $this->parent->xml_value($tags, $leftitem."['text'][0]['#']"); + + $rightitem = $item."['right-item'][0]['#']"; + $righttext = $this->parent->xml_value($tags, $rightitem."['text'][0]['#']"); + + if (strlen($righttext)) { + $addright = true; + } else { + $addright = false; } + if (strlen($lefttext)) { + $this->l_items[] = array( + 'text' => $lefttext, + 'fixed' => $this->int_value($tags, $leftitem."['fixed'][0]['#']") + ); + $addright = true; // force right item to be added + } + if ($addright) { + $this->r_items[] = array( + 'text' => $righttext, + 'fixed' => $this->int_value($tags, $rightitem."['fixed'][0]['#']") + ); + } + $i++; } } function shuffle_jmatch_items(&$items) { @@ -901,7 +924,9 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $gap .= ''; } else { // minimum gap size - $gapsize = 6; + if (! $gapsize = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',minimum-gap-size')) { + $gapsize = 6; + } // increase gap size to length of longest answer for this gap $a = 0; @@ -1262,8 +1287,23 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { $question_type==HOTPOT_JQUIZ_SHORTANSWER || $question_type==HOTPOT_JQUIZ_HYBRID ) { + $size = 9; // default size + $a = 0; + $answers = $question."['answers'][0]['#']"; + while (($answer = $answers."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { + $text = $this->parent->xml_value($tags, $answer."['text'][0]['#']"); + $text = preg_replace('/&[#a-zA-Z0-9]+;/', 'x', $text); + $size = max($size, strlen($text)); + $a++; + } + $str .= '
'; - $str .= '

'; + if ($size<=25) { // text box + $str .= ''; + } else { // textarea (29 cols wide) + $str .= ''; + } + $str .= '

'; $caption = $this->v6_expand_CheckCaption(); $str .= $this->v6_expand_jquiz_button($caption, "CheckShortAnswer($q)"); -- 2.39.5