[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /homework matchresponse.pm

raeburn raeburn at source.lon-capa.org
Mon Nov 7 20:48:52 EST 2011


raeburn		Tue Nov  8 01:48:52 2011 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/homework	matchresponse.pm 
  Log:
  - Backport 1.84.
  
  
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.81 loncom/homework/matchresponse.pm:1.81.2.1
--- loncom/homework/matchresponse.pm:1.81	Sun Dec 19 00:54:20 2010
+++ loncom/homework/matchresponse.pm	Tue Nov  8 01:48:51 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Full matching style response
 #
-# $Id: matchresponse.pm,v 1.81 2010/12/19 00:54:20 raeburn Exp $
+# $Id: matchresponse.pm,v 1.81.2.1 2011/11/08 01:48:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -131,7 +131,11 @@
     my $result;
 
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
-    if (!defined(@{ $Apache::response::itemgroup{'names'} })) { return; }
+    if (ref($Apache::response::itemgroup{'names'}) eq 'ARRAY') {
+        if(!@{ $Apache::response::itemgroup{'names'} }) { return; }
+    } else {
+        return;
+    }
     my @names=@{ $Apache::response::itemgroup{'names'} };
     my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
     if ($randomize ne 'no' ) {
@@ -311,16 +315,22 @@
 
 sub displayanswers {
     my ($max,$randomize, at opt)=@_;
-    if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
+    if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
+        if (!@{ $Apache::response::foilgroup{'names'} }) { return; }
+    } else {
+        return;
+    }
     my @names = @{ $Apache::response::foilgroup{'names'} };
     my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
 						   $randomize,
 					  &Apache::response::showallfoils(),
 					 \%Apache::response::foilgroup);
     my %name_letter_map;
-    if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
-	%name_letter_map=
-	    %{ $Apache::response::itemgroup{'name_letter_map'} };
+    if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
+        if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
+            %name_letter_map=
+                %{ $Apache::response::itemgroup{'name_letter_map'} };
+        }
     }
     my $result;
     if ($Apache::lonhomework::type eq 'exam') {
@@ -357,9 +367,11 @@
     my %answerhash;
     my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
     my %letter_name_map;
-    if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
-	%letter_name_map=
-	    %{ $Apache::response::itemgroup{'letter_name_map'} };
+    if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
+        if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
+            %letter_name_map=
+                %{ $Apache::response::itemgroup{'letter_name_map'} };
+        }
     }
     my @items;
     foreach my $name (@whichfoils) {
@@ -494,14 +506,18 @@
     my $part=$Apache::inputtags::part;
     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
     my %letter_name_map;
-    if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
-	%letter_name_map=
-	    %{ $Apache::response::itemgroup{'letter_name_map'} };
+    if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
+        if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
+            %letter_name_map=
+                %{ $Apache::response::itemgroup{'letter_name_map'} };
+        }
     }
     my %name_letter_map;
-    if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
-	%name_letter_map=
-	    %{ $Apache::response::itemgroup{'name_letter_map'} };
+    if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
+        if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
+            %name_letter_map=
+                %{ $Apache::response::itemgroup{'name_letter_map'} };
+        }
     }
     if ( &Apache::response::show_answer() && ($target ne 'tex')) {
 	foreach my $name (@whichfoils) {
@@ -746,9 +762,11 @@
 	if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
 	$result.=&Apache::edit::text_arg('Name:','name',$token);
 	my @names;
-	if (defined(@{ $Apache::response::itemgroup{'names'} })) {
-	    @names=@{ $Apache::response::itemgroup{'names'} };
-	}
+        if (ref($Apache::response::itemgroup{'names'}) eq 'ARRAY') {
+            if (@{ $Apache::response::itemgroup{'names'} }) {
+                @names=@{ $Apache::response::itemgroup{'names'} };
+            }
+        }
 	$result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused', at names],$token,'15');
 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
 						 $safeeval,'-3');




More information about the LON-CAPA-cvs mailing list