--- loncom/interface/lonnavmaps.pm 2003/05/12 19:22:39 1.186 +++ loncom/interface/lonnavmaps.pm 2003/05/14 18:33:28 1.188 @@ -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.188 2003/05/14 18:33:28 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2594,6 +2594,12 @@ You will probably never need to instanti Apache::lonnavmaps::navmap, and use the "start" method to obtain the starting resource. +Resource objects respect the parameter_hiddenparts, which suppresses +various parts according to the wishes of the map author. As of this +writing, there is no way to override this parameter, and suppressed +parts will never be returned, nor will their response types or ids be +stored. + =head2 Public Members resource objects have a hash called DATA ($resourceRef->{DATA}) that @@ -3097,6 +3103,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 +3141,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; @@ -3174,6 +3197,43 @@ 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); + if (!defined($responseIdHash{$partIdSoFar})) { + $responseIdHash{$partIdSoFar} = []; + } + push @{$responseIdHash{$partIdSoFar}}, $responseId; + $responseTypeHash{$partIdSoFar} = $responseType; + last; + } + } + } + } + + $self->{RESPONSE_IDS} = \%responseIdHash; + $self->{RESPONSE_TYPES} = \%responseTypeHash; } return;