--- loncom/interface/lonnavmaps.pm 2002/10/07 19:00:38 1.67 +++ loncom/interface/lonnavmaps.pm 2002/10/07 21:07:47 1.68 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.67 2002/10/07 19:00:38 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.68 2002/10/07 21:07:47 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -920,7 +920,7 @@ sub new_handle { my $condition = 0; if ($ENV{'form.condition'}) { - $condition = 1; + $condition = 1; } my $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, $condition); @@ -946,6 +946,12 @@ sub new_handle { $isNewBranch = 1; } + # Is this resource being blotted out? + if (ref($curRes) && !advancedUser() && $curRes->randomout()) { + $curRes = $mapIterator->next(); + next; # and totally ignore this resource + } + if (ref($curRes) && $curRes->src()) { # Step one: Decide which parts to show @@ -962,7 +968,7 @@ sub new_handle { # just display first if (!$curRes->opendate("0")) { @parts = ("0"); # just display the zero-th part - $condensed = 1; + $condensed = 1; } else { # Otherwise, only display part 0 if we want to # attach feedback or email information to it @@ -1026,6 +1032,7 @@ sub new_handle { foreach my $part (@parts) { my $deltalevel = 0; # for inserting the branch icon + my $nonLinkedText = ""; # unlinked stuff after title # For each thing we're displaying... @@ -1075,7 +1082,7 @@ sub new_handle { removeFromFilter(\%filterHash, $mapId); $linkopen .= "&condition=$condition&$queryAdd\">"; $linkclose = ""; - + } my $colorizer = ""; @@ -1087,6 +1094,10 @@ sub new_handle { } } + if ($curRes->randomout()) { + $nonLinkedText .= ' (hidden) '; + } + # FIRST COL: The resource indentation, branch icon, and name $r->print(" \n"); @@ -1097,14 +1108,12 @@ sub new_handle { $r->print(" ${newBranchText}${linkopen}$icon${linkclose}\n"); - my $nonLinkedText = ""; - if ($curRes->is_problem() && $part != "0" && !$condensed) { $partLabel = " (Part $part)"; $title = ""; } if ($multipart && $condensed) { - $nonLinkedText = ' (' . $curRes->countParts() . ' parts)'; + $nonLinkedText .= ' (' . $curRes->countParts() . ' parts)'; } $r->print(" $title$partLabel $nonLinkedText"); @@ -1163,6 +1172,9 @@ sub new_handle { !$firstDisplayed) { $r->print (getDescription($curRes, $part)); } + if ($curRes->is_map() && advancedUser() && $curRes->randompick()) { + $r->print('(randomly select ' . $curRes->randompick() .')'); + } $r->print("\n"); } @@ -1273,6 +1285,10 @@ sub getDescription { } } +sub advancedUser { + return $ENV{'user.adv'}; +} + # I want to change this into something more human-friendly. For # now, this is a simple call to localtime. The final function # probably belongs in loncommon. @@ -1770,21 +1786,33 @@ sub new { return $self; } +# FIXME: Document this. +sub cancelTopRecursion { + my $self = shift; + + if (!$self->{RECURSIVE_ITERATOR_FLAG}) {return;} + + # is this the iterator we want to kill? + if ($self->{RECURSIVE_ITERATOR_FLAG} && + !$self->{RECURSIVE_ITERATOR}->{RECURSIVE_ITERATOR_FLAG}) { + $self->{RECURSIVE_ITERATOR_FLAG} = 0; + undef $self->{RECURSIVE_ITERATOR}; + return; + } + + $self->{RECURSIVE_ITERATOR}->cancelTopRecursion(); +} + # 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*. +# FIXME: Doc that skipMap will prevent the recursion, if any. sub next { my $self = shift; + my $skipMap = shift; # Iterator logic goes here - # Is this return value pre-determined? - if (defined($self->{FORCE_NEXT})) { - my $tmp = $self->{FORCE_NEXT}; - $self->{FORCE_NEXT} = undef; - return $tmp; - } - # 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}) @@ -1804,6 +1832,13 @@ 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) { @@ -1892,7 +1927,6 @@ sub next { $self->{FORCE_NEXT} = $self->END_BRANCH(); $self->{BRANCH_DEPTH}--; } - return $self->{HERE}; } while (@$next) { @@ -1908,15 +1942,12 @@ sub next { } # If this is a map and we want to recurse down it... (not filtered out) - if ($self->{HERE}->is_map() && + if ($self->{HERE}->is_map() && !$skipMap && (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) { $self->{RECURSIVE_ITERATOR_FLAG} = 1; my $firstResource = $self->{HERE}->map_start(); my $finishResource = $self->{HERE}->map_finish(); - # Odd perl syntax here; $self->new allows one to create a new iterator - # can't figure out how to ref this package directly correctly - # isn't MAIN::new, __PACKAGE__::new or Apache::lonnavmaps::iterator->new $self->{RECURSIVE_ITERATOR} = Apache::lonnavmaps::iterator->new ($self->{NAV_MAP}, $firstResource, $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN}, @@ -2038,6 +2069,12 @@ sub goesto { my $self=shift; return $sel sub to { my $self=shift; return $self->navHash("to_", 1); } sub kind { my $self=shift; return $self->navHash("kind_", 1); } sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; } +sub randomout { my $self=shift; return $self->navHash("randomout_", 1); } +sub randompick { + my $self = shift; + return $self->{NAV_MAP}->{PARM_HASH}->{$self->symb . + '.0.parameter_randompick'}; +} sub src { my $self=shift; return $self->navHash("src_", 1);