[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 30 Aug 2004 18:45:52 -0000


matthew		Mon Aug 30 14:45:52 2004 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  Bug 3358: response types were not being reported properly
  &extractparts reorders the array of respons ids but was not reordering the
  (parallel) array holding response types.
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.283 loncom/interface/lonnavmaps.pm:1.284
--- loncom/interface/lonnavmaps.pm:1.283	Sun Aug 29 11:40:14 2004
+++ loncom/interface/lonnavmaps.pm	Mon Aug 30 14:45:52 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.283 2004/08/29 15:40:14 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.284 2004/08/30 18:45:52 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4033,6 +4033,7 @@
         }
         
 
+        # These hashes probably do not need names that end with "Hash"....
         my %responseIdHash;
         my %responseTypeHash;
 
@@ -4048,6 +4049,8 @@
         # So we have to use our knowlege of part names to figure out 
         # where the part names begin and end, and even then, it is possible
         # to construct ambiguous situations.
+        #
+        my %response_type_by_id;
         foreach (split /,/, $metadata) {
             if ($_ =~ /^([a-zA-Z]+)response_(.*)/) {
                 my $responseType = $1;
@@ -4063,11 +4066,14 @@
                         my $responseId = join('_', @otherChunks);
                         push @{$responseIdHash{$partIdSoFar}}, $responseId;
                         push @{$responseTypeHash{$partIdSoFar}}, $responseType;
+                        $response_type_by_id{$responseId} = $responseType;
                     }
                 }
             }
         }
 	my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
+        #
+        # Reorder the arrays in the %responseIdHash and %responseTypeHash
 	if ($resorder) {
 	    my @resorder=split(/,/,$resorder);
 	    foreach my $part (keys(%responseIdHash)) {
@@ -4081,6 +4087,15 @@
 		$responseIdHash{$part}=\@neworder;	
 	    }
 	}
+        #
+        # Reorder the response types
+        foreach my $partid (keys(%responseIdHash)) {
+            delete($responseTypeHash{$partid});
+            foreach my $respid (@{$responseIdHash{$partid}}) {
+                push(@{$responseTypeHash{$partid}},
+                     $response_type_by_id{$respid});
+            }
+        }
         $self->{RESPONSE_IDS} = \%responseIdHash;
         $self->{RESPONSE_TYPES} = \%responseTypeHash;
     }