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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 14 Dec 2006 04:59:51 -0000


albertel		Wed Dec 13 23:59:51 2006 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - exam mode works with single element non-vector numerical probelms detect and throw error on other usages
  - exam mode picks the INTERNAL answer if it exists otherwise it picks the first one sorted alphabetically
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.200 loncom/homework/caparesponse/caparesponse.pm:1.201
--- loncom/homework/caparesponse/caparesponse.pm:1.200	Wed Dec 13 17:48:10 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Dec 13 23:59:51 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.200 2006/12/13 22:48:10 albertel Exp $
+# $Id: caparesponse.pm,v 1.201 2006/12/14 04:59:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -776,7 +776,18 @@
 	&Apache::response::get_response_param($part.'_'.$id,'numbubbles',8);
 
     my ($format)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
-    my ($answer)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+    my $name = (exists($answer{$tag_internal_answer_name}) 
+		? $tag_internal_answer_name
+		: (sort(keys(%answer)))[0]);
+
+    if ( scalar(@{$answer{$name}{'answers'}}) > 1) {
+	&Apache::lonxml::error("Only answers with 1 component are supported in exam mode");
+    }
+    if (scalar(@{$answer{$name}{'answers'}[0]}) > 1) {
+	&Apache::lonxml::error("Vector answers are unsupported in exam mode.");
+    }
+
+    my $answer = $answer{$name}{'answers'}[0][0];
     my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,
 						   $safeeval);
     if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }