--- loncom/interface/lonnavmaps.pm 2002/11/08 18:44:02 1.99 +++ loncom/interface/lonnavmaps.pm 2002/11/12 18:24:38 1.102 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.99 2002/11/08 18:44:02 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.102 2002/11/12 18:24:38 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -89,10 +89,12 @@ sub handler { $r->print(&Apache::loncommon::bodytag('Navigate Course Map','', '')); $r->print(''); - my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + $r->print(''); my $date=localtime; $r->print(''); + + # Print discussions and feedback header if ($navmap->{LAST_CHECK}) { $r->print(''); } $r->print('
Key:    '. ' New discussion since '. @@ -107,6 +109,7 @@ sub handler { '
'); + my $condition = 0; if ($ENV{'form.condition'}) { $condition = 1; @@ -135,6 +138,9 @@ sub handler { # is technically not proper, but should be harmless my $res = $navmap->firstResource(); + # These are some data tables, which make it easy to change some of + # of the specific visualization parameters if desired. + # Defines a status->color mapping, null string means don't color my %colormap = ( $res->NETWORK_FAILURE => '', @@ -192,6 +198,7 @@ sub handler { my $currenturl = $ENV{'form.postdata'}; $currenturl=~s/^http\:\/\///; $currenturl=~s/^[^\/]+//; + # alreadyHere allows us to only open the maps necessary to view # the current location once, while at the same time remembering # the current location. Without that check, the user would never @@ -210,16 +217,14 @@ sub handler { # Here's a simple example of the iterator. # Preprocess the map: Look for current URL, force inlined maps to display - # This currently does very little... - #my $mapEventualIterator = Apache::lonnavmaps::iterator->new($navmap, undef, undef, {}, - #undef, $condition); - - my $mapIterator = $navmap->getIterator(undef, undef, {}, 1); + my $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, 1); my $found = 0; my $depth = 1; my $currentUrlIndex = 0; # keeps track of when the current resource is found, # so we can back up a few and put the anchor above the # current resource + my $currentUrlDelta = 5; # change this to change how many resources are displayed + # before the current resource when using #current $mapIterator->next(); # discard the first BEGIN_MAP my $curRes = $mapIterator->next(); my $counter = 0; @@ -237,8 +242,12 @@ sub handler { # show it by making sure the containing maps # are open. + # This is why we have to use the main iterator instead of the + # potentially faster DFS: The count has to be the same, so + # the order has to be the same, which DFS won't give us. $currentUrlIndex = $counter; + # Ensure the parent maps are open for my $map (@{$mapStack}) { if ($condition) { undef $filterHash{$map->map_pc()}; @@ -286,15 +295,16 @@ sub handler { $counter = 0; + # Print the 'current' anchor here if it would fall off the top + if ($currentUrlIndex - $currentUrlDelta < 0) { + $r->print(''); + } + while ($depth > 0) { - # If we're in a new style course, and this is a BEGIN_MAP, END_MAP, or - # map resource and the stack depth is only one, just plain ignore this resource - # entirely. (This has the effect of inlining the resources in that map - # in the nav map.) + # If this is an inlined map, cancel the shift to the right, + # which has the effect of making the map look inlined if ($inlineTopLevelMaps && scalar(@{$mapIterator->getStack()}) == 1 && ref($curRes) && $curRes->is_map()) { - # We let the normal depth stuff occur, but we need to shift everything - # over by one to the left to make it look right. $deltadepth = -1; $curRes = $mapIterator->next(); next; @@ -319,10 +329,11 @@ sub handler { if ($depth == 1) { $deltadepth = 0; } # we're done shifting, because we're # out of the inlined map - # Is this resource being blotted out? + # Is this resource being ignored because it is in a random-out + # map and it was not selected? if (ref($curRes) && !advancedUser() && $curRes->randomout()) { $curRes = $mapIterator->next(); - next; # and totally ignore this resource + next; # if yes, then just ignore this resource } if (ref($curRes) && $curRes->src()) { @@ -333,14 +344,15 @@ sub handler { my $condensed = 0; if ($curRes->is_problem()) { - # Is it multipart? + # Is it multipart? if ($multipart) { # If it's multipart, see if part 0 is "open" # if it is, display all parts, if it isn't, # just display first if (!$curRes->opendate("0")) { - @parts = ("0"); # just display the zero-th part + # no parts are open, display as one part + @parts = ("0"); $condensed = 1; } else { # Otherwise, only display part 0 if we want to @@ -348,9 +360,6 @@ sub handler { if ($curRes->hasDiscussion() || $curRes->getFeedback()) { shift @parts; } else { - # If there's discussion or feedback, that counts - # as a difference, so display the parts. - # Now, we decide whether to condense the # parts due to similarity my $status = $curRes->status($parts[1]); @@ -391,11 +400,11 @@ sub handler { } else { $parts[0] = "0"; # this is to get past foreach loop below # you can consider a non-problem resource as a resource - # with only one part without loss + # with only one part without loss, and it simplifies the looping } # Is it a multipart problem with a single part, now in - # @parts with "0" filtered out? If so, forget it's a multi-part + # @parts with "0" filtered out? If so, 'forget' it's a multi-part # problem and treat it like a single-part problem. if ( scalar(@parts) == 1 ) { $multipart = 0; @@ -403,27 +412,31 @@ sub handler { # Display one part, in event of network error. # If this is a single part, we can at least show the correct - # status, but if it's multipart, we're lost. + # status, but if it's multipart, we're lost, since we can't + # retreive the metadata to count the parts if ($curRes->{RESOURCE_ERROR}) { @parts = ("0"); } - # Step two: Show the parts + # Step Two: Print the actual data. + + # For each part we intend to display... foreach my $part (@parts) { my $deltalevel = 0; # for inserting the branch icon my $nonLinkedText = ""; # unlinked stuff after title - # For each thing we're displaying... - my $stack = $mapIterator->getStack(); my $src = getLinkForResource($stack); + # Pass the correct symb on the querystring, so the + # remote will figure out where we are if we click a link my $srcHasQuestion = $src =~ /\?/; my $link = $src. ($srcHasQuestion?'&':'?') . 'symb='.&Apache::lonnet::escape($curRes->symb()). '"'; + my $title = $curRes->title(); if (!$title) { $title = $curRes->src(); @@ -433,11 +446,10 @@ sub handler { my $newBranchText = ""; # If this is a new branch, label it so - # (temporary, this should be an icon w/ alt text) if ($isNewBranch) { $newBranchText = ""; $isNewBranch = 0; - $deltalevel = 1; + $deltalevel = 1; # reserves space for the branch icon } # links to open and close the folders @@ -509,11 +521,8 @@ sub handler { # FIRST COL: The resource indentation, branch icon, name, and anchor $r->print(" \n"); - # anchor for current resource... - 5 is deliberate: If it's that - # high on the screen, don't bother focusing on it. Also this will - # print multiple anchors if this is an expanded multi-part problem... - # who cares? - if ($counter == $currentUrlIndex - 5) { + # Print the anchor if necessary + if ($counter == $currentUrlIndex - $currentUrlDelta) { $r->print(''); } @@ -543,18 +552,15 @@ sub handler { } $r->print(" $curMarkerBegin$title$partLabel $curMarkerEnd $nonLinkedText"); - #$r->print(" TDV:" . $curRes->{DATA}->{TOP_DOWN_VAL}); # temp - #$r->print(" BUV:" . $curRes->{DATA}->{BOT_UP_VAL}); # temp - #$r->print(" DD:" . $curRes->{DATA}->{DISPLAY_DEPTH}); # temp if ($curRes->{RESOURCE_ERROR}) { $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down", 'Host down')); } + # SECOND COL: Is there text, feedback, errors?? my $discussionHTML = ""; my $feedbackHTML = ""; - # SECOND COL: Is there text, feedback, errors?? if ($curRes->hasDiscussion()) { $discussionHTML = $linkopen . '' . @@ -577,7 +583,8 @@ sub handler { # Is this the first displayed part of a multi-part problem # that has not been condensed, so we should suppress these two - # columns? + # columns so we don't display useless status info about part + # "0"? my $firstDisplayed = !$condensed && $multipart && $part eq "0"; # THIRD COL: Problem status icon @@ -595,7 +602,6 @@ sub handler { } # FOURTH COL: Text description - #$r->print("\n"); $r->print("\n"); if ($curRes->kind() eq "res" && @@ -727,6 +733,7 @@ sub getDescription { } } +# This puts a human-readable name on the ENV variable. sub advancedUser { return $ENV{'user.adv'}; } @@ -772,17 +779,18 @@ sub timeToHumanString { $delta = -$delta; } - # Is it in the future? if ( $delta > 0 ) { - # Is it less then a minute away? + my $tense = $inPast ? " ago" : ""; my $prefix = $inPast ? "" : "in "; + + # Less then a minute if ( $delta < $minute ) { if ($delta == 1) { return "${prefix}1 second$tense"; } return "$prefix$delta seconds$tense"; } - # Is it less then an hour away? + # Less then an hour if ( $delta < $hour ) { # If so, use minutes my $minutes = floor($delta / 60); @@ -876,7 +884,7 @@ sub new { $self->{GENERATE_COURSE_USER_OPT} = shift; $self->{GENERATE_EMAIL_DISCUSS_STATUS} = shift; - # Resource cache stores navmapresource's as we reference them. We generate + # Resource cache stores navmap resources as we reference them. We generate # them on-demand so we don't pay for creating resources unless we use them. $self->{RESOURCE_CACHE} = {}; @@ -1029,8 +1037,7 @@ sub courseMapDefined { sub getIterator { my $self = shift; my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift, - shift, undef, shift, - $ENV{'form.direction'}); + shift, undef, shift); return $iterator; } @@ -1121,14 +1128,8 @@ sub finishResource { return $self->getById($firstResource); } -# -------------------------------------------- Figure out a cascading parameter -# -# For this function to work -# -# * parmhash needs to be tied -# * courseopt and useropt need to be initialized for this user and course -# - +# Parmval reads the parm hash and cascades the lookups. parmval_real does +# the actual lookup; parmval caches the results. sub parmval { my $self = shift; my ($what,$symb)=@_; @@ -1230,10 +1231,6 @@ sub parmval_real { package Apache::lonnavmaps::iterator; -# This package must precede "navmap" because "navmap" uses it. In -# order to keep the documentation order straight, the iterator is documented -# after the navmap object. - =pod =back @@ -1254,9 +1251,9 @@ getIterator behaves as follows: =over 4 -=item B(firstResource, finishResource, filterHash, condition, direction): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0, which is to say, do not recurse unless explicitly asked to. Direction specifies which direction to recurse, either FORWARD or BACKWARD, with FORWARD being default. +=item * B(firstResource, finishResource, filterHash, condition): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0. -Thus, by default, all resources will be shown. Change the condition to a 1 without changing the hash, and only the top level of the map will be shown. Changing the condition to 1 and including some values in the hash will allow you to selectively examine parts of the navmap, while leaving it on 0 and adding things to the hash will allow you to selectively ignore parts of the nav map. See the handler code for examples: By default, the condition is 0 and all folders are closed unless explicitly opened. Clicking "Show All Resources" will use a condition of 1 and an empty filterHash, resulting in all resources being shown. +Thus, by default, only top-level resources will be shown. Change the condition to a 1 without changing the hash, and all resources will be shown. Changing the condition to 1 and including some values in the hash will allow you to selectively suppress parts of the navmap, while leaving it on 0 and adding things to the hash will allow you to selectively add parts of the nav map. See the handler code for examples. The iterator will return either a reference to a resource object, or a token representing something in the map, such as the beginning of a new branch. The possible tokens are: @@ -1371,16 +1368,6 @@ sub new { } } } - if (ref($curRes) && $curRes->is_map() && $direction == FORWARD()) { - my $firstResource = $curRes->map_start(); - my $finishResource = $curRes->map_finish(); - my $newIterator = Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, - $firstResource, - $finishResource, - $self->{FILTER}, - $self->{ALREADY_SEEN}, - $self->{CONDITION}); - } # Assign the final val if (ref($curRes) && $direction == BACKWARD()) { @@ -1549,29 +1536,24 @@ sub populateStack { package Apache::lonnavmaps::DFSiterator; -# UNDOCUMENTED: This is a private library, it should not generally be used -# by the outside world. What it does is walk through the nav map in a -# depth-first fashion. This is not appropriate for most uses, but it is -# used by the main iterator for pre-processing. It also is able to isolate -# much of the complexity of the main iterator, so the main iterator is much -# simpler. -# There is no real benefit in merging the main iterator and this one into one class... -# all the logic in DFSiterator would need to be replicated, you gain no performance, -# at best, you just make one massively complicated iterator in place of two -# somewhat complicated ones. ;-) - Jeremy - -# Here are the tokens for the iterator, replicated from iterator for convenience: +# Not documented in the perldoc: This is a simple iterator that just walks +# through the nav map and presents the resources in a depth-first search +# fashion, ignorant of conditionals, randomized resources, etc. It presents +# BEGIN_MAP and END_MAP, but does not understand branches at all. It is +# useful for pre-processing of some kind, and is in fact used by the main +# iterator that way, but that's about it. +# One could imagine merging this into the init routine of the main iterator, +# but this might as well be left seperate, since it is possible some other +# use might be found for it. - Jeremy sub BEGIN_MAP { return 1; } # begining of a new map sub END_MAP { return 2; } # end of the map -sub BEGIN_BRANCH { return 3; } # beginning of a branch -sub END_BRANCH { return 4; } # end of a branch sub FORWARD { return 1; } # go forward sub BACKWARD { return 2; } -# Params: nav map, start resource, end resource, filter, condition, -# already seen hash ref - +# Params: Nav map ref, first resource id/ref, finish resource id/ref, +# filter hash ref (or undef), already seen hash or undef, condition +# (as in main iterator), direction FORWARD or BACKWARD (undef->forward). sub new { # magic invocation to create a class instance my $proto = shift; @@ -1581,7 +1563,6 @@ sub new { $self->{NAV_MAP} = shift; return undef unless ($self->{NAV_MAP}); - # Handle the parameters $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource(); $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource(); @@ -1600,7 +1581,7 @@ sub new { $self->{CONDITION} = shift; $self->{DIRECTION} = shift || FORWARD(); - # Flag: Have we started yet? If not, the first action is to return BEGIN_MAP. + # Flag: Have we started yet? $self->{STARTED} = 0; # Should we continue calling the recursive iterator, if any? @@ -1614,34 +1595,22 @@ sub new { $self->{RECURSIVE_DEPTH} = 0; # For keeping track of our branches, we maintain our own stack - $self->{BRANCH_STACK} = []; - # If the size shrinks, we exhausted a branch - $self->{BRANCH_STACK_SIZE} = 0; - $self->{BRANCH_DEPTH} = 0; - - # For returning two things in a forced sequence - $self->{FORCE_NEXT} = undef; + $self->{STACK} = []; # Start with the first resource if ($self->{DIRECTION} == FORWARD) { - push @{$self->{BRANCH_STACK}}, $self->{FIRST_RESOURCE}; + push @{$self->{STACK}}, $self->{FIRST_RESOURCE}; } else { - push @{$self->{BRANCH_STACK}}, $self->{FINISH_RESOURCE}; + push @{$self->{STACK}}, $self->{FINISH_RESOURCE}; } - $self->{BRANCH_STACK_SIZE} = 1; bless($self); return $self; } -# Note... this function is *touchy*. I strongly recommend tracing -# through it with the debugger a few times on a non-trivial map before -# modifying it. Order is *everything*. sub next { my $self = shift; - # Iterator logic goes here - # Are we using a recursive iterator? If so, pull from that and # watch the depth; we want to resume our level at the correct time. if ($self->{RECURSIVE_ITERATOR_FLAG}) { @@ -1660,23 +1629,10 @@ sub next { return $next; } - # Is this return value pre-determined? - if (defined($self->{FORCE_NEXT})) { - my $tmp = $self->{FORCE_NEXT}; - $self->{FORCE_NEXT} = undef; - return $tmp; - } - # Is there a current resource to grab? If not, then return - # END_BRANCH and END_MAP in succession. - if (scalar(@{$self->{BRANCH_STACK}}) == 0) { - if ($self->{BRANCH_DEPTH} > 0) { - $self->{FORCE_NEXT} = $self->END_MAP(); - $self->{BRANCH_DEPTH}--; - return $self->END_BRANCH(); - } else { - return $self->END_MAP(); - } + # END_MAP, which will end the iterator. + if (scalar(@{$self->{STACK}}) == 0) { + return $self->END_MAP(); } # Have we not yet begun? If not, return BEGIN_MAP and @@ -1686,42 +1642,10 @@ sub next { return $self->BEGIN_MAP; } - # Did the branch stack shrink since last run? If so, - # we exhausted a branch last time, therefore, we're about - # to start a new one. (We know because we already checked to see - # if the stack was empty.) - if ( scalar (@{$self->{BRANCH_STACK}}) < $self->{BRANCH_STACK_SIZE}) { - $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}}); - $self->{BRANCH_DEPTH}++; - return $self->BEGIN_BRANCH(); - } - - # Remember the size for comparision next time. - $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}}); - - # If the next resource we mean to return is going to need - # a lower branch level, terminate branches until we get - # there. - # Get the next resource in the branch - $self->{HERE} = pop @{$self->{BRANCH_STACK}}; + $self->{HERE} = pop @{$self->{STACK}}; - # Are we at the right depth? If not, close a branch and return - # the current resource onto the branch stack - # Note: There seems to be some bugs here, so don't rely - # on this, use the real iterator instead. - if (defined($self->{HERE}->{DATA}->{ITERATOR_DEPTH}) - && $self->{HERE}->{DATA}->{ITERATOR_DEPTH} < - $self->{BRANCH_DEPTH} ) { - $self->{BRANCH_DEPTH}--; - # return it so we can pick it up eventually - push @{$self->{BRANCH_STACK}}, $self->{HERE}; - return $self->END_BRANCH(); - } - - # We always return it after this point and never before - # (proof: look at just the return statements), so we - # remember that we've seen this. + # remember that we've seen this, so we don't return it again later $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1; # Get the next possible resources @@ -1734,40 +1658,16 @@ sub next { my $next = []; # filter the next possibilities to remove things we've - # already seen. Also, remember what branch depth they should - # be displayed at, since there's no other reliable way to tell. + # already seen. foreach (@$nextUnfiltered) { if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) { push @$next, $_; - $_->{DATA}->{ITERATOR_DEPTH} = - $self->{BRANCH_DEPTH} + 1; } } - # Handle branch cases: - # Nothing is available next: BRANCH_END - # 1 thing next: standard non-branch - # 2+ things next: have some branches - my $nextCount = scalar(@$next); - if ($nextCount == 0) { - # Return this and on the next run, close the branch up if we're - # in a branch - if ($self->{BRANCH_DEPTH} > 0 ) { - $self->{FORCE_NEXT} = $self->END_BRANCH(); - $self->{BRANCH_DEPTH}--; - } - } - while (@$next) { - # copy the next possibilities over to the branch stack - # in the right order - push @{$self->{BRANCH_STACK}}, shift @$next; - } - - if ($nextCount >= 2) { - $self->{FORCE_NEXT} = $self->BEGIN_BRANCH(); - $self->{BRANCH_DEPTH}++; - return $self->{HERE}; + # copy the next possibilities over to the stack + push @{$self->{STACK}}, shift @$next; } # If this is a map and we want to recurse down it... (not filtered out) @@ -1786,28 +1686,6 @@ sub next { return $self->{HERE}; } -sub getStack { - my $self=shift; - - my @stack; - - $self->populateStack(\@stack); - - return \@stack; -} - -# Private method: Calls the iterators recursively to populate the stack. -sub populateStack { - my $self=shift; - my $stack = shift; - - push @$stack, $self->{HERE} if ($self->{HERE}); - - if ($self->{RECURSIVE_ITERATOR_FLAG}) { - $self->{RECURSIVE_ITERATOR}->populateStack($stack); - } -} - 1; package Apache::lonnavmaps::resource; @@ -1875,7 +1753,7 @@ sub navHash { B -These are methods that help you retrieve metadata about the resource: +These are methods that help you retrieve metadata about the resource: Method names are based on the fields in the compiled course representation. =over 4 @@ -1885,7 +1763,7 @@ These are methods that help you retrieve =item * B: Returns the kind of the resource from the compiled nav map. -=item * B: Returns true if this resource was chosen to NOT be shown to the user by the random map selection feature. +=item * B: Returns true if this resource was chosen to NOT be shown to the user by the random map selection feature. In other words, this is usually false. =item * B: Returns true for a map if the randompick feature is being used on the map. (?) @@ -1945,7 +1823,7 @@ These methods are shortcuts to deciding =item * B: Returns true if the resource is a problem. -=item * B: Returns true if the resource sequence. +=item * B: Returns true if the resource is a sequence. =back @@ -1974,12 +1852,7 @@ sub is_sequence { return ($src =~ /sequence$/); } - - - - -# Move this into POD: In order to use these correctly, courseopt -# and useropt need to be generated +# Private method: Shells out to the parmval in the nav map, handler parts. sub parmval { my $self = shift; my $what = shift; @@ -2262,7 +2135,7 @@ sub extractParts { =head2 Resource Status -Problem resources have status information, reflecting their various dates and completion statuses. You can obtain this information and import symbolic constants to represent the status. +Problem resources have status information, reflecting their various dates and completion statuses. There are two aspects to the status: the date-related information and the completion information. @@ -2279,6 +2152,10 @@ Idiomatic usage of these two methods wou ... use it here ... } +Which you use depends on exactly what you are looking for. The status() function has been optimized for the nav maps display and may not precisely match what you need elsewhere. + +The symbolic constants shown below can be accessed through the resource object: $res->OPEN. + =over 4 =item * B($part): ($part defaults to 0). A convenience function that returns a symbolic constant telling you about the date status of the part. The possible return values are: @@ -2415,7 +2292,7 @@ sub getCompletionStatus { B -Along with directly returning the date or completion status, the resource object includes a convenience function B() that will combine the two status tidbits into one composite status that can represent the status of the resource as a whole. The precise logic is documented in the comments of the status method. The following results may be returned, all available as methods on the resource object ($res->NETWORK_FAILURE()): +Along with directly returning the date or completion status, the resource object includes a convenience function B() that will combine the two status tidbits into one composite status that can represent the status of the resource as a whole. The precise logic is documented in the comments of the status method. The following results may be returned, all available as methods on the resource object ($res->NETWORK_FAILURE): =over 4 @@ -2519,15 +2396,14 @@ sub status { =over 4 -=item * B($alreadySeenHashRef): Retreive an array of the possible next resources after this one. Always returns an array, even in the one- or zero-element case. The "alreadySeenHashRef" is an optional parameter that can be passed in to the method. If $$alreadySeenHashRef{$res->id()} is true in that hash, getNext will not return it in the list. In other words, you can use it to suppress resources you've already seen in the getNext method directly. +=item * B(): Retreive an array of the possible next resources after this one. Always returns an array, even in the one- or zero-element case. -=item * B($alreadySeenHashRef): Retreive an array of the possible previous resources from this one. Always returns an array, even in the one- or zero-element case. $alreadySeenHashRef is the same as in getNext. +=item * B(): Retreive an array of the possible previous resources from this one. Always returns an array, even in the one- or zero-element case. =cut sub getNext { my $self = shift; - my $alreadySeenHash = shift; my @branches; my $to = $self->to(); foreach my $branch ( split(/,/, $to) ) { @@ -2535,21 +2411,18 @@ sub getNext { my $next = $choice->goesto(); $next = $self->{NAV_MAP}->getById($next); - # Don't remember it if we've already seen it or if - # the student doesn't have browse priviledges + # Don't remember it if the student doesn't have browse priviledges + # future note: this may properly belong in the client of the resource my $browsePriv = &Apache::lonnet::allowed('bre', $self->src); - if (!defined($alreadySeenHash) || - !defined($alreadySeenHash->{$next->{ID}}) || - ($browsePriv ne '2' && $browsePriv ne 'F')) { - push @branches, $next; - } + if (!($browsePriv ne '2' && $browsePriv ne 'F')) { + push @branches, $next; + } } return \@branches; } sub getPrevious { my $self = shift; - my $alreadySeenHash = shift; my @branches; my $from = $self->from(); foreach my $branch ( split /,/, $from) { @@ -2557,12 +2430,10 @@ sub getPrevious { my $prev = $choice->comesfrom(); $prev = $self->{NAV_MAP}->getById($prev); - # Skip it if we've already seen it or the user doesn't have - # browse privs + # Don't remember it if the student doesn't have browse priviledges + # future note: this may properly belong in the client of the resource my $browsePriv = &Apache::lonnet::allowed('bre', $self->src); - if (!defined($alreadySeenHash) || - !defined($alreadySeenHash->{$prev->{ID}}) || - ($browsePriv ne '2' && $browsePriv ne 'F')) { + if ($browsePriv ne '2' && $browsePriv ne 'F') { push @branches, $prev; } }