--- loncom/interface/lonnavmaps.pm 2002/11/08 18:44:02 1.99
+++ loncom/interface/lonnavmaps.pm 2002/11/08 20:58:13 1.101
@@ -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.101 2002/11/08 20:58:13 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('
\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;
}
}
|