--- loncom/interface/lonnavmaps.pm 2003/05/12 19:22:39 1.186 +++ loncom/interface/lonnavmaps.pm 2003/05/14 18:01:16 1.187 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.186 2003/05/12 19:22:39 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.187 2003/05/14 18:01:16 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3097,6 +3097,15 @@ number of parts in the problem, not incl B may return an array with fewer parts in it then countParts might lead you to believe. +=item * B($part): + +Returns the response type of the part, without the word "response" on the +end. Example return values: 'string', 'essay', 'numeric', etc. + +=item * B($part): + +Retreives the response ID for the given part, which may be an empty string. + =back =cut @@ -3126,16 +3135,24 @@ sub countParts { return scalar(@{$parts}) + $delta; } -sub partType { +sub responseType { my $self = shift; my $part = shift; $self->extractParts(); - return $self->{PART_TYPE}->{$part}; + return $self->{RESPONSE_TYPE}->{$part}; +} + +sub responseId { + my $self = shift; + my $part = shift; + + $self->extractParts(); + return $self->{RESPONSE_IDS}->{$part}; } # Private function: Extracts the parts information, both part names and -# part types, and saves it +# part types, and saves it. sub extractParts { my $self = shift; @@ -3149,6 +3166,7 @@ sub extractParts { # Retrieve part count, if this is a problem if ($self->is_problem()) { my $metadata = &Apache::lonnet::metadata($self->src(), 'packages'); + print $metadata; if (!$metadata) { $self->{RESOURCE_ERROR} = 1; $self->{PARTS} = []; @@ -3174,6 +3192,40 @@ sub extractParts { my @sortedParts = sort keys %parts; $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;