[LON-CAPA-cvs] cvs: loncom /homework optionresponse.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Tue, 01 Oct 2002 20:17:04 -0000


sakharuk		Tue Oct  1 16:17:04 2002 EDT

  Modified files:              
    /loncom/homework	optionresponse.pm 
  Log:
  Corrections + cleanuo.
  
  
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.49 loncom/homework/optionresponse.pm:1.50
--- loncom/homework/optionresponse.pm:1.49	Tue Oct  1 10:39:45 2002
+++ loncom/homework/optionresponse.pm	Tue Oct  1 16:17:04 2002
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.49 2002/10/01 14:39:45 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.50 2002/10/01 20:17:04 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -354,33 +354,15 @@
 	  $temp++;
       } else {
 	  if ($displayoptionintex == 0) {
-              my $texoptionlist = $optionlist;
-	      $texoptionlist =~ s/<option><\/option>/\\item \[\] The possible answers are:/;
-	      $texoptionlist =~ s/<option>/{\\bf /g;
-	      $texoptionlist =~ s/<option selected="on">/{\\bf /g;
-	      $texoptionlist =~ s/<\/option>/},/g;
-	      $texoptionlist =~ s/,$/\./g;
-	      $texoptionlist =~ s/>/\$>\$/g;
-	      $texoptionlist =~ s/</\$<\$/g;
-	      $texoptionlist =~ s/=/\$=\$/g;
+              my $texoptionlist = &optionlist_correction($optionlist);
 	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
 		  $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
 	      } else {
 		  $result.= $texoptionlist.'\item '.$Apache::response::foilgroup{$name.'.text'};
 	      }
-		  if ($Apache::lonhomework::type eq 'exam') {
-		      my $number_of_bubbles = $#opt + 1;
-		      $result.= '\vskip 2 mm \noindent \begin{tabular}{|';
-		      for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-			  $result.='lr|';
-		      }
-		      $result.='}\hline ';
-		      for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-			  $result.=' '.$alphabet[$ind].': & '.$opt[$ind].' ';
-			  if ($ind != $number_of_bubbles - 1) {$result.=' & ';}
-		      }
-		      $result.='\\\\\hline\end{tabular}\vskip 0 mm ';
-		  }
+	      if ($Apache::lonhomework::type eq 'exam') {
+		  $result.=&bubbles(\@alphabet,\@opt);
+	      }
 	      $displayoptionintex=1;
 	  } else {
 	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
@@ -388,19 +370,9 @@
 	      } else {
 		  $result.= '\item '.$Apache::response::foilgroup{$name.'.text'};
 	      }
-		  if ($Apache::lonhomework::type eq 'exam') {
-		      my $number_of_bubbles = $#opt + 1;
-		      $result.= '\vskip 2 mm \noindent \begin{tabular}{|';
-		      for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-			  $result.='lr|';
-		      }
-		      $result.='}\hline ';
-		      for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-			  $result.=' '.$alphabet[$ind].': & '.$opt[$ind].' ';
-			  if ($ind != $number_of_bubbles - 1) {$result.=' & ';}
-		      }
-		      $result.='\\\\\hline\end{tabular}\vskip 0 mm ';
-		  }
+	      if ($Apache::lonhomework::type eq 'exam') {
+		  $result.=&bubbles(\@alphabet,\@opt);
+	      }
 	  }
       } 
     }
@@ -411,6 +383,42 @@
   else {
       return $result;
   }
+}
+
+
+sub optionlist_correction {
+
+    my $texoptionlist = shift;
+    $texoptionlist =~ s/<option><\/option>/\\item \[\] The possible answers are:/;
+    $texoptionlist =~ s/<option>/\{\\bf /g;
+    $texoptionlist =~ s/<option selected="on">/\{\\bf /g;
+    $texoptionlist =~ s/<\/option>/\},/g;
+    $texoptionlist =~ s/,$/\./g;
+    $texoptionlist =~ s/>/\$>\$/g;
+    $texoptionlist =~ s/</\$<\$/g;
+    $texoptionlist =~ s/=/\$=\$/g;
+    return $texoptionlist;
+}
+
+
+sub bubbles {
+
+    my ($ralphabit,$ropt) = @_;
+    my @alphabet = @$ralphabit;
+    my @opt = @$ropt;
+    my $result='';
+    my $number_of_bubbles = $#opt + 1;
+    $result.= '\vskip 2 mm \noindent \begin{tabular}{|';
+    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+	$result.='lr|';
+    }
+    $result.='}\hline ';
+    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+	$result.=' '.$alphabet[$ind].': & '.$opt[$ind].' ';
+	if ($ind != $number_of_bubbles - 1) {$result.=' & ';}
+    }
+    $result.='\\\\\hline\end{tabular}\vskip 0 mm ';
+    return $result;
 }