Skip to content

Commit

Permalink
improvements to generation of html from xml:
Browse files Browse the repository at this point in the history
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;
  • Loading branch information
gbateson committed Jul 13, 2008
1 parent 9652995 commit 249de4f
Showing 1 changed file with 62 additions and 22 deletions.
84 changes: 62 additions & 22 deletions mod/hotpot/template/v6.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,43 +711,66 @@ function v6_expand_FixedArray() {
$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;
}
function v6_expand_DragArray() {
$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) {
Expand Down Expand Up @@ -897,7 +920,9 @@ function v6_expand_ClozeBody() {
$gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';
} 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;
Expand Down Expand Up @@ -1258,8 +1283,23 @@ function v6_expand_QuestionOutput() {
$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 .= '<div class="ShortAnswer" id="Q_'.$q.'_SA"><form method="post" action="" onsubmit="return false;"><div>';
$str .= '<input type="text" id="Q_'.$q.'_Guess" onfocus="TrackFocus('."'".'Q_'.$q.'_Guess'."'".')" onblur="LeaveGap()" class="ShortAnswerBox" size="9"></input><br /><br />';
if ($size<=25) { // text box
$str .= '<input type="text" id="Q_'.$q.'_Guess" onfocus="TrackFocus('."'".'Q_'.$q.'_Guess'."'".')" onblur="LeaveGap()" class="ShortAnswerBox" size="'.$size.'"></input>';
} else { // textarea (29 cols wide)
$str .= '<textarea id="Q_'.$q.'_Guess" onfocus="TrackFocus('."'".'Q_'.$q.'_Guess'."'".')" onblur="LeaveGap()" class="ShortAnswerBox" cols="29" rows="'.ceil($size/25).'"></textarea>';
}
$str .= '<br /><br />';

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

0 comments on commit 249de4f

Please sign in to comment.