Skip to content

Commit

Permalink
JCloze improvements: allow gap at start of cloze and allow "0" for a …
Browse files Browse the repository at this point in the history
…gap value
  • Loading branch information
gbateson committed Mar 8, 2006
1 parent 00e648c commit 330388c
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions mod/hotpot/template/v6.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,15 @@ function v6_expand_ItemArray() {
$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";
}
Expand All @@ -794,7 +794,7 @@ function v6_expand_ItemArray() {
// 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++;
}
Expand All @@ -818,15 +818,16 @@ function v6_expand_ItemArray() {
$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++;
Expand Down Expand Up @@ -854,30 +855,44 @@ function v6_expand_ClozeBody() {
$includeclues = $this->v6_expand_Clues();
$cluecaption = $this->v6_expand_ClueCaption();

// detect if cloze starts with gap
$strpos = strpos($this->parent->source, '<gap-fill><question-record>');
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 .= '<span class="GapSpan" id="GapSpan'.$q.'">';
$gap .= '<span class="GapSpan" id="GapSpan'.$q.'">';
if ($this->v6_use_DropDownList()) {
$str .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';
$gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';
} else {
$str .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="6"></input>';
$gap .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="6"></input>';
}
if ($includeclues) {
$clue = $this->parent->xml_value("$tags,question-record", $question."['clue'][0]['#']");
if (strlen($clue)) {
$str .= '<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>';
$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>';
}
}
$str .= '</span>';
$gap .= '</span>';
}
if ($startwithgap) {
$str .= "$gap$text";
} else {
$str .= "$text$gap";
}
$q++;
}
} while (strlen($text) || strlen($gap));

return $str;
}
Expand Down

0 comments on commit 330388c

Please sign in to comment.