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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 25 Sep 2007 23:58:33 -0000


albertel		Tue Sep 25 19:58:33 2007 EDT

  Modified files:              
    /loncom/homework	imageresponse.pm 
  Log:
  - support use of mutliple foils at once
  
  
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.87 loncom/homework/imageresponse.pm:1.88
--- loncom/homework/imageresponse.pm:1.87	Tue Sep 25 19:47:59 2007
+++ loncom/homework/imageresponse.pm	Tue Sep 25 19:58:32 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.87 2007/09/25 23:47:59 albertel Exp $
+# $Id: imageresponse.pm,v 1.88 2007/09/25 23:58:32 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,6 +62,16 @@
 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
 	push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} },
 	      1);
+    } elsif ( $target eq 'edit' ) {
+	$result .= &Apache::edit::tag_start($target,$token).
+	    &Apache::edit::text_arg('Max Number Of Shown Foils:',
+				    'max',$token,'4').
+	    &Apache::edit::end_row().
+	    &Apache::edit::start_spanning_row();
+    } elsif ( $target eq 'modified' ) {
+	my $constructtag=
+	    &Apache::edit::get_new_args($token,$parstack,$safeeval,'max');
+	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     }
     return $result;
 }
@@ -105,27 +115,27 @@
     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
     # +1 since instructors will count from 1
     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
-    #if (&Apache::response::showallfoils()) { $max=$count; }
+    if (&Apache::response::showallfoils()) { $max=$count; }
     return ($count,$max);
 }
 
 sub whichfoils {
     my ($max)=@_;
-    if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
+    return if (!defined(@{ $Apache::response::foilgroup{'names'} }));
     my @names = @{ $Apache::response::foilgroup{'names'} };
-    my @whichopt =();
+    my @whichopt;
     while ((($#whichopt+1) < $max) && ($#names > -1)) {
 	&Apache::lonxml::debug("Have $#whichopt max is $max");
 	my $aopt;
-#	if (&Apache::response::showallfoils()) {
-#	    $aopt=0;
-#	} else {
+	if (&Apache::response::showallfoils()) {
+	    $aopt=0;
+	} else {
 	    $aopt=int(&Math::Random::random_uniform() * ($#names+1));
-#	}
+	}
 	&Apache::lonxml::debug("From $#names elms, picking $aopt");
 	$aopt=splice(@names,$aopt,1);
 	&Apache::lonxml::debug("Picked $aopt");
-	push (@whichopt,$aopt);
+	push(@whichopt,$aopt);
     }
     return @whichopt;
 }
@@ -280,7 +290,7 @@
 sub display_answers {
     my ($target,$whichopt)=@_;
 
-    my $result;
+    my $result=&Apache::response::answer_header('imageresponse');
     foreach my $name (@$whichopt) {
 	my $image=$Apache::response::foilgroup{"$name.image"};
 	&Apache::lonxml::debug("image is $image");
@@ -289,10 +299,9 @@
 	} 
 	my $token=&prep_image($image,'answeronly',$name);
 
-	$result.=&Apache::response::answer_header('imageresponse');
 	$result.=&Apache::response::answer_part('imageresponse',"<img src=\"/adm/randomlabel.png?token=$token\" /><br />\n");
-	$result.=&Apache::response::answer_footer('imageresponse');
     }
+    $result.=&Apache::response::answer_footer('imageresponse');
     return $result;
 }
 
@@ -482,7 +491,7 @@
 	}
 	$Apache::response::foilnames{$name}++;
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    push(@{ $Apache::response::conceptgroup{'names'} }, $name);
 	} else {
@@ -535,7 +544,7 @@
 	|| $target eq 'answer') {
 	my $name = $Apache::imageresponse::curname;
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    $Apache::response::conceptgroup{"$name.text"} = &Apache::lonxml::endredirection;
 	} else {
@@ -578,7 +587,7 @@
 	my $image = &Apache::lonxml::endredirection();
 	&Apache::lonxml::debug("original image is $image");
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    $Apache::response::conceptgroup{"$name.image"} = $image;
 	} else {
@@ -587,7 +596,7 @@
     } elsif ($target eq 'analyze') {
 	my $image = &Apache::lonxml::endredirection();
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    $Apache::response::conceptgroup{"$name.image"} = $image;
 	} else {
@@ -667,7 +676,7 @@
 	$area=~s/\s//g;
 	&Apache::lonxml::debug("out is $area for $name");
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    push @{ $Apache::response::conceptgroup{"$name.area"} },"rectangle:$area";
 	} else {
@@ -748,7 +757,7 @@
 	$area=~s/\s*//g;
 	&Apache::lonxml::debug("out is $area for $name");
 	if ( $Apache::imageresponse::conceptgroup
-	     #&& !&Apache::response::showallfoils()
+	     && !&Apache::response::showallfoils()
 	     ) {
 	    push @{ $Apache::response::conceptgroup{"$name.area"} },"polygon:$area";
 	} else {