Diff for /loncom/interface/lonnavmaps.pm between versions 1.186 and 1.187

version 1.186, 2003/05/12 19:22:39 version 1.187, 2003/05/14 18:01:16
Line 3097  number of parts in the problem, not incl Line 3097  number of parts in the problem, not incl
 B<parts> may return an array with fewer parts in it then countParts  B<parts> may return an array with fewer parts in it then countParts
 might lead you to believe.  might lead you to believe.
   
   =item * B<responseType>($part):
   
   Returns the response type of the part, without the word "response" on the
   end. Example return values: 'string', 'essay', 'numeric', etc.
   
   =item * B<responseId>($part):
   
   Retreives the response ID for the given part, which may be an empty string.
   
 =back  =back
   
 =cut  =cut
Line 3126  sub countParts { Line 3135  sub countParts {
     return scalar(@{$parts}) + $delta;      return scalar(@{$parts}) + $delta;
 }  }
   
 sub partType {  sub responseType {
       my $self = shift;
       my $part = shift;
   
       $self->extractParts();
       return $self->{RESPONSE_TYPE}->{$part};
   }
   
   sub responseId {
     my $self = shift;      my $self = shift;
     my $part = shift;      my $part = shift;
   
     $self->extractParts();      $self->extractParts();
     return $self->{PART_TYPE}->{$part};      return $self->{RESPONSE_IDS}->{$part};
 }  }
   
 # Private function: Extracts the parts information, both part names and  # Private function: Extracts the parts information, both part names and
 # part types, and saves it  # part types, and saves it. 
 sub extractParts {   sub extractParts { 
     my $self = shift;      my $self = shift;
           
Line 3149  sub extractParts { Line 3166  sub extractParts {
     # Retrieve part count, if this is a problem      # Retrieve part count, if this is a problem
     if ($self->is_problem()) {      if ($self->is_problem()) {
         my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');          my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
           print $metadata;
         if (!$metadata) {          if (!$metadata) {
             $self->{RESOURCE_ERROR} = 1;              $self->{RESOURCE_ERROR} = 1;
             $self->{PARTS} = [];              $self->{PARTS} = [];
Line 3174  sub extractParts { Line 3192  sub extractParts {
                   
         my @sortedParts = sort keys %parts;          my @sortedParts = sort keys %parts;
         $self->{PARTS} = \@sortedParts;          $self->{PARTS} = \@sortedParts;
   
           my %responseIdHash;
           my %responseTypeHash;
   
           # Now, the unfortunate thing about this is that parts, part name, and
           # response if are delimited by underscores, but both the part
           # name and response id can themselves have underscores in them.
           # 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.
           foreach (split /,/, $metadata) {
               if ($_ =~ /^([a-zA-Z]+)response_(.*)/) {
                   my $responseType = $1;
                   my $partStuff = $2;
                   my $partIdSoFar = '';
                   my @partChunks = split /_/, $partStuff;
                   my $i = 0;
   
                   for ($i = 0; $i < scalar(@partChunks); $i++) {
                       if ($partIdSoFar) { $partIdSoFar .= '_'; }
                       $partIdSoFar .= $partChunks[$i];
                       if ($parts{$partIdSoFar}) {
                           my @otherChunks = @partChunks[$i+1..$#partChunks];
                           my $responseId = join('_', @otherChunks);
                           $responseIdHash{$partIdSoFar} = $responseId;
                           $responseTypeHash{$partIdSoFar} = $responseType;
                           last;
                       }
                   }
               }
           }
   
           $self->{RESPONSE_IDS} = \%responseIdHash;
           $self->{RESPONSE_TYPES} = \%responseTypeHash;
     }      }
   
     return;      return;

Removed from v.1.186  
changed lines
  Added in v.1.187


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>