From 33e0f22e19f58f807e3a069e1d8e57f528bc717b Mon Sep 17 00:00:00 2001 From: gbateson Date: Fri, 20 Jun 2008 22:29:02 +0000 Subject: [PATCH] replace get_jmatch_items by set_jmatch_items --- mod/hotpot/template/v6.php | 73 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/mod/hotpot/template/v6.php b/mod/hotpot/template/v6.php index 56ed581cbd..603b73cbcb 100644 --- a/mod/hotpot/template/v6.php +++ b/mod/hotpot/template/v6.php @@ -1,6 +1,9 @@ get_jmatch_items($l_items, $r_items); + $this->set_jmatch_items(); - $l_keys = $this->shuffle_jmatch_items($l_items); - $r_keys = $this->shuffle_jmatch_items($r_items); + $l_keys = $this->shuffle_jmatch_items($this->l_items); + $r_keys = $this->shuffle_jmatch_items($this->r_items); $options = ''; foreach ($r_keys as $key) { - if (empty($r_items[$key]['fixed'])) { - $options .= ''."\n"; + if (! $this->r_items[$key]['fixed']) { + $options .= ''."\n"; } } $str = ''; foreach ($l_keys as $key) { - $str .= ''.$l_items[$key]['text'].''; + $str .= ''.$this->l_items[$key]['text'].''; $str .= ''; - if (empty($r_items[$key]['fixed'])) { - $str .= ''; + if ($this->r_items[$key]['fixed']) { + $str .= $this->r_items[$key]['text']; } else { - $str .= $r_items[$key]['text']; + $str .= ''; } $str .= ''; } @@ -711,12 +712,9 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { // specials (JMatch) function v6_expand_FixedArray() { - $l_items = array(); - $r_items = array(); - $this->get_jmatch_items($l_items, $r_items); - + $this->set_jmatch_items(); $str = ''; - foreach ($l_items as $i=>$item) { + foreach ($this->l_items as $i=>$item) { $str .= "F[$i] = new Array();\n"; $str .= "F[$i][0] = '".$this->js_safe($item['text'], true)."';\n"; $str .= "F[$i][1] = ".($i+1).";\n"; @@ -724,37 +722,36 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { return $str; } function v6_expand_DragArray() { - $l_items = array(); - $r_items = array(); - $this->get_jmatch_items($l_items, $r_items); - + $this->set_jmatch_items(); $str = ''; - foreach ($r_items as $i=>$item) { + foreach ($this->r_items as $i=>$item) { $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] = '".(empty($item['fixed']) ? 0 : 1)."';\n"; + $str .= "D[$i][2] = '".$item['fixed']."';\n"; } return $str; } - function get_jmatch_items(&$l_items, &$r_items) { - $tags = 'data,matching-exercise,pair'; - $i = 0; - while($this->parent->xml_value($tags,"[$i]['#']['left-item'][0]['#']")) { - if ($text = $this->parent->xml_value($tags,"[$i]['#']['left-item'][0]['#']['text'][0]['#']")) { - $fixed = $this->parent->xml_value($tags,"[$i]['#']['left-item'][0]['#']['fixed'][0]['#']"); - $l_items[] = array('text'=>$text, 'fixed'=>$fixed); - } - $i++; - } - $i = 0; - while($this->parent->xml_value($tags,"[$i]['#']['right-item'][0]['#']")) { - if ($text = $this->parent->xml_value($tags,"[$i]['#']['right-item'][0]['#']['text'][0]['#']")) { - $fixed = $this->parent->xml_value($tags,"[$i]['#']['right-item'][0]['#']['fixed'][0]['#']"); - $r_items[] = array('text'=>$text, 'fixed'=>$fixed); + 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++; } - $i++; } } function shuffle_jmatch_items(&$items) { -- 2.39.5