\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) {
+ $r->print('');
+ }
# print indentation
- for (my $i = 0; $i < $indentLevel - $deltalevel; $i++) {
+ for (my $i = 0; $i < $indentLevel - $deltalevel + $deltadepth; $i++) {
$r->print($indentString);
}
@@ -1692,7 +1763,8 @@ sub courseMapDefined {
sub getIterator {
my $self = shift;
my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
- shift, undef, shift);
+ shift, undef, shift,
+ $ENV{'form.direction'});
return $iterator;
}
@@ -1916,7 +1988,7 @@ getIterator behaves as follows:
=over 4
-=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, which is to say, do not recurse unless explicitly asked to.
+=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.
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.
@@ -1946,6 +2018,8 @@ sub BEGIN_MAP { return 1; } # beginin
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
@@ -1976,6 +2050,7 @@ sub new {
$self->{ALREADY_SEEN} = shift;
if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
$self->{CONDITION} = shift;
+ $self->{DIRECTION} = shift || FORWARD();
# Flag: Have we started yet? If not, the first action is to return BEGIN_MAP.
$self->{STARTED} = 0;
@@ -2000,7 +2075,11 @@ sub new {
$self->{FORCE_NEXT} = undef;
# Start with the first resource
- push @{$self->{BRANCH_STACK}}, $self->{FIRST_RESOURCE};
+ if ($self->{DIRECTION} == FORWARD) {
+ push @{$self->{BRANCH_STACK}}, $self->{FIRST_RESOURCE};
+ } else {
+ push @{$self->{BRANCH_STACK}}, $self->{FINISH_RESOURCE};
+ }
$self->{BRANCH_STACK_SIZE} = 1;
bless($self);
@@ -2097,7 +2176,12 @@ sub next {
$self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
# Get the next possible resources
- my $nextUnfiltered = $self->{HERE}->getNext();
+ my $nextUnfiltered;
+ if ($self->{DIRECTION} == FORWARD()) {
+ $nextUnfiltered = $self->{HERE}->getNext();
+ } else {
+ $nextUnfiltered = $self->{HERE}->getPrevious();
+ }
my $next = [];
# filter the next possibilities to remove things we've
@@ -2147,7 +2231,7 @@ sub next {
$self->{RECURSIVE_ITERATOR} =
Apache::lonnavmaps::iterator->new ($self->{NAV_MAP}, $firstResource,
$finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
- $self->{CONDITION});
+ $self->{CONDITION}, $self->{DIRECTION});
}
return $self->{HERE};
@@ -2174,7 +2258,7 @@ sub populateStack {
my $self=shift;
my $stack = shift;
- push @$stack, $self->{HERE};
+ push @$stack, $self->{HERE} if ($self->{HERE});
if ($self->{RECURSIVE_ITERATOR_FLAG}) {
$self->{RECURSIVE_ITERATOR}->populateStack($stack);
|