[LON-CAPA-cvs] cvs: loncom /imspackages imsprocessor.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 05 Apr 2006 17:33:52 -0000


raeburn		Wed Apr  5 13:33:52 2006 EDT

  Modified files:              
    /loncom/imspackages	imsprocessor.pm 
  Log:
  Support for import of WebCT Vista 4 "Jumbled Sentence" question type.
  
  
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.36 loncom/imspackages/imsprocessor.pm:1.37
--- loncom/imspackages/imsprocessor.pm:1.36	Tue Apr  4 13:42:28 2006
+++ loncom/imspackages/imsprocessor.pm	Wed Apr  5 13:33:51 2006
@@ -2267,6 +2267,7 @@
     my $currindex;
     my %varinfo = ();
     my $formula;
+    my $jumbnum = 0;
     my $p = HTML::Parser->new
     (
      xml_mode => 1,
@@ -2332,6 +2333,8 @@
             %{$$settings{$id}{$list}} = ();
             @{$$allanswers{$id}{$list}} = ();
             @{$$settings{$id}{$list}{correctanswer}} = ();
+            @{$$settings{$id}{$list}{jumbledtext}} = ();
+            @{$$settings{$id}{$list}{jumbledtype}} = ();
             @{$$settings{$id}{$list}{jumbled}} = ();
             $$settings{$id}{$list}{rcardinality} = $attr->{rcardinality};
         }
@@ -2350,6 +2353,13 @@
             $currtexttype = lc($attr->{texttype});
             $$settings{$id}{$list}{$jumble_item}{texttype} = $currtexttype;
         }
+        if ("@state" eq "questestinterop item resprocessing respcondition") { # Jumbled
+            if ($$settings{$id}{class} eq 'jumbled') {
+                $jumbnum ++;
+                @{$$settings{$id}{$list}{jumbled}[$jumbnum]} = (); 
+            }
+        }
+
         if ("@state" eq "questestinterop item resprocessing respcondition conditionvar and varequal") { # Jumbled
             $currindex = $attr->{index};
         }
@@ -2542,11 +2552,13 @@
             $$settings{$id}{$list}{$answer_id}{text} = $text;
         }
         if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object material mattext")  {
-            $$settings{$id}{$list}{text} .= $text;
+            push(@{$$settings{$id}{$list}{jumbledtext}},$text);
+            push(@{$$settings{$id}{$list}{jumbledtype}},'No');
         }
         if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object response_label material mattext")  {
             $$settings{$id}{$list}{$jumble_item}{text} = $text;
-            $$settings{$id}{$list}{text} .= $text;
+            push(@{$$settings{$id}{$list}{jumbledtext}},$text);
+            push(@{$$settings{$id}{$list}{jumbledtype}},'Yes');
         }
         if ("@state" eq "questestinterop item presentation flow material mattext")  {
             $$settings{$id}{text} .= $text;
@@ -2582,8 +2594,9 @@
                 }
             }
         }
+
         if ("@state" eq "questestinterop item resprocessing respcondition conditionvar and varequal") { # Jumbled
-            $$settings{$id}{$list}{jumbled}[$currindex] = $text;
+            $$settings{$id}{$list}{jumbled}[$jumbnum][$currindex] = $text;
         }
         if ("@state" eq "questestinterop item resprocessing respcondition setvar") {
             if ($setvar{varname} eq "SCORE") { # Multiple Choice, String or Match
@@ -3749,6 +3762,62 @@
                 $resourcedata{$symb.'hiddenparts'} = '!essay';
                 $resourcedata{$symb.'questiontype'} = 'essay';
             }
+        } elsif ($$settings{$id}{class} eq 'jumbled') {
+            if ($context eq 'CSTR') {
+                my %foiloptions = ();
+                foreach my $list (@{$$settings{$id}{lists}}) {
+                    @{$foiloptions{$list}} = ();
+                    my $numalternates = @{$$settings{$id}{$list}{jumbled}} - 1;
+                    my $loopstop = 2; #Hard coded for now, so only one permutation of answers is correct; <or> functionality is needed to support the case where multiple permutations are correct.  
+                    for (my $i=1; $i<$loopstop; $i++) {  
+                        $foiloptions{$list}[$i]  = '(';
+                        for (my $j=@{$$settings{$id}{$list}{jumbled}[$i]}-1; $j>0; $j--) {
+                            my $jumble_item = $$settings{$id}{$list}{jumbled}[$i][$j];
+                            $foiloptions{$list}[$i] .= "'".$$settings{$id}{$list}{$jumble_item}{text}."',";
+                        }
+                        $foiloptions{$list}[$i] =~ s/,$//;
+                        $foiloptions{$list}[$i] .= ')';
+                        my $jnum = 0; 
+                        for (my $k=0; $k<@{$$settings{$id}{$list}{jumbledtype}}; $k++) {
+                            if ($$settings{$id}{$list}{jumbledtype}[$k] eq 'No') {
+                                $output .= qq|
+<startouttext />
+$$settings{$id}{$list}{jumbledtext}[$k]
+<endouttext />|;
+                            } elsif ($$settings{$id}{$list}{jumbledtype}[$k] eq 'Yes') {
+                                $jnum ++;
+                                my $jumble_item = $$settings{$id}{$list}{jumbled}[$i][$jnum];
+                                $output .= qq|
+<optionresponse max="1" randomize="yes" TeXlayout="horizontal">
+    <foilgroup options="$foiloptions{$list}[$i]">
+        <foil location="random" value="$$settings{$id}{$list}{$jumble_item}{text}" name="$jumble_item"></foil>
+    </foilgroup>
+</optionresponse>
+|;
+                            }
+                        }
+                    }
+                    if ($numalternates > 0) { # for now alternates are stored in an instructorcomment.  In the future these alternates could be moved into the main response area once <or> functionality is available.
+                        $output .= '<instructorcomment>(Not shown to students) '."\n".'The following alternates were imported from the corresponding WebCT Vista 4 jumbled sentence question, but are not included in the LON-CAPA version, because this style of question does not currently support multiple correct solutions.'."\n";
+                        for (my $i=2; $i<@{$$settings{$id}{$list}{jumbled}}; $i++) {
+                            my $altid = $i-1;
+                            my $jnum = 0;
+                            $output .= $altid.'. '; 
+                            for (my $k=0; $k<@{$$settings{$id}{$list}{jumbledtype}}; $k++) {
+                                if ($$settings{$id}{$list}{jumbledtype}[$k] eq 'No') {
+                                    $output .= "$$settings{$id}{$list}{jumbledtext}[$k]" ;
+                                } elsif ($$settings{$id}{$list}{jumbledtype}[$k] eq 'Yes') {
+                                    $jnum ++;
+                                    my $jumble_item = $$settings{$id}{$list}{jumbled}[$i][$jnum];
+                                    $output .= '['.$$settings{$id}{$list}{$jumble_item}{text}.']';
+                                }
+                            }
+                            $output .= " \n";
+                        }
+                        $output .= '</instructorcomment>';
+                    }  
+                }
+            }
         } else {
             if ($context eq 'CSTR') {
                 $output .= qq|<startouttext /><p>$$settings{$id}{text}</p>$questionimage<endouttext />\n|;