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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 09 Sep 2004 09:49:03 -0000


albertel		Thu Sep  9 05:49:03 2004 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - different way of doing response id/type reordering
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.285 loncom/interface/lonnavmaps.pm:1.286
--- loncom/interface/lonnavmaps.pm:1.285	Tue Aug 31 11:28:03 2004
+++ loncom/interface/lonnavmaps.pm	Thu Sep  9 05:49:03 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.285 2004/08/31 15:28:03 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.286 2004/09/09 09:49:03 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4049,8 +4049,6 @@
         # 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;
@@ -4066,7 +4064,6 @@
                         my $responseId = join('_', @otherChunks);
                         push @{$responseIdHash{$partIdSoFar}}, $responseId;
                         push @{$responseTypeHash{$partIdSoFar}}, $responseType;
-                        $response_type_by_id{$responseId} = $responseType;
                     }
                 }
             }
@@ -4077,25 +4074,24 @@
 	if ($resorder) {
 	    my @resorder=split(/,/,$resorder);
 	    foreach my $part (keys(%responseIdHash)) {
-		my %resids = map { ($_,1) } @{ $responseIdHash{$part} };
+		my $i=0;
+		my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} };
 		my @neworder;
 		foreach my $possibleid (@resorder) {
 		    if (exists($resids{$possibleid})) {
-			push(@neworder,$possibleid);
+			push(@neworder,$resids{$possibleid});
 		    }
 		}
-		$responseIdHash{$part}=\@neworder;	
+		my @ids;
+		my @type;
+		foreach my $element (@neworder) {
+		    push (@ids,$responseIdHash{$part}->[$element]);
+		    push (@type,$responseTypeHash{$part}->[$element]);
+		}
+		$responseIdHash{$part}=\@ids;
+		$responseTypeHash{$part}=\@type;
 	    }
 	}
-        #
-        # 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;
     }