[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Mon, 07 Oct 2002 21:07:47 -0000


bowersj2		Mon Oct  7 17:07:47 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  * Honors randomout for CC and students.
  * Fixed in passing a bug where under some circumstances an open map on the 
    end of some sequence would not show its contents.
  * Removed an out-of-date comment.
  
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.67 loncom/interface/lonnavmaps.pm:1.68
--- loncom/interface/lonnavmaps.pm:1.67	Mon Oct  7 15:00:38 2002
+++ loncom/interface/lonnavmaps.pm	Mon Oct  7 17:07:47 2002
@@ -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 @@
 
     my $condition = 0;
     if ($ENV{'form.condition'}) {
-	$condition = 1;
+        $condition = 1;
     }
 
     my $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, $condition);
@@ -946,6 +946,12 @@
             $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 @@
                     # 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 @@
             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 @@
                         removeFromFilter(\%filterHash, $mapId);
                     $linkopen .= "&condition=$condition&$queryAdd\">";
                     $linkclose = "</a>";
-                    
+
                 }
                 
                 my $colorizer = "";
@@ -1087,6 +1094,10 @@
                     }
                 }
 
+                if ($curRes->randomout()) {
+                    $nonLinkedText .= ' <i>(hidden)</i> ';
+                }
+
                 # FIRST COL: The resource indentation, branch icon, and name
                 $r->print("  <tr><td align=\"left\" valign=\"bottom\">\n");
 
@@ -1097,14 +1108,12 @@
 
                 $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("  <a href=\"$link\">$title$partLabel</a> $nonLinkedText");
@@ -1163,6 +1172,9 @@
                     !$firstDisplayed) {
                     $r->print (getDescription($curRes, $part));
                 }
+                if ($curRes->is_map() && advancedUser() && $curRes->randompick()) {
+                    $r->print('(randomly select ' . $curRes->randompick() .')');
+                }
 
                 $r->print("</td></tr>\n");
             }
@@ -1273,6 +1285,10 @@
     }
 }
 
+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 @@
     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 @@
         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 @@
             $self->{FORCE_NEXT} = $self->END_BRANCH();
             $self->{BRANCH_DEPTH}--;
         }
-        return $self->{HERE};
     }
     
     while (@$next) {
@@ -1908,15 +1942,12 @@
     }
 
     # 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 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);