Diff for /loncom/interface/lonnavmaps.pm between versions 1.115 and 1.116

version 1.115, 2002/11/26 14:45:24 version 1.116, 2002/11/26 16:25:36
Line 208  sub handler { Line 208  sub handler {
     # Is this a new-style course? If so, we want to suppress showing the top-level      # Is this a new-style course? If so, we want to suppress showing the top-level
     # maps in their own folders, in favor of "inlining" them.      # maps in their own folders, in favor of "inlining" them.
     my $topResource = $navmap->getById("0.0");      my $topResource = $navmap->getById("0.0");
     my $inlineTopLevelMaps = $topResource->src() =~ m|^/uploaded/.*default\.sequence$|;  
     my $inlinedelta = $inlineTopLevelMaps? -1 : 0;  
   
     # Begin the HTML table      # Begin the HTML table
     # four cols: resource + indent, chat+feedback, icon, text string      # four cols: resource + indent, chat+feedback, icon, text string
Line 232  sub handler { Line 230  sub handler {
     $mapIterator->next(); # discard the first BEGIN_MAP      $mapIterator->next(); # discard the first BEGIN_MAP
     my $curRes = $mapIterator->next();      my $curRes = $mapIterator->next();
     my $counter = 0;      my $counter = 0;
       
     while ($depth > 0) {      # We only need to do this if we need to open the maps to show the
       # current position
       while ($depth > 0 && !$ENV{'form.alreadyHere'}) {
         if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; }          if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; }
         if ($curRes == $mapIterator->END_MAP()) { $depth--; }          if ($curRes == $mapIterator->END_MAP()) { $depth--; }
   
Line 262  sub handler { Line 262  sub handler {
             $ENV{'form.alreadyHere'} = 1;              $ENV{'form.alreadyHere'} = 1;
         }          }
                           
         # Preprocessing: If we're inlining nav maps into the top-level display,  
         # make sure we show this map!  
         if ($inlineTopLevelMaps && ref($curRes) && $curRes->is_map &&   
             scalar(@{$mapStack}) == 1) {  
             if ($condition) {  
                 undef $filterHash{$curRes->map_pc()};  
             } else {  
                 $filterHash{$curRes->map_pc()} = 1;  
             }  
         }  
   
         $curRes = $mapIterator->next();          $curRes = $mapIterator->next();
     }      }
           
Line 327  sub handler { Line 316  sub handler {
             next; # if yes, then just ignore this resource              next; # if yes, then just ignore this resource
         }          }
   
         if (ref($curRes) && $curRes->src()) {          if (ref($curRes)) {
   
             my $deltalevel = $isNewBranch? 1 : 0; # reserves space for branch icon              my $deltalevel = $isNewBranch? 1 : 0; # reserves space for branch icon
   
             if ($indentLevel - $deltalevel + $inlinedelta < 0) {              if ($indentLevel - $deltalevel < 0) {
                 # If this would be at a negative depth (top-level maps in                  # If this would be at a negative depth (top-level maps in
                 # new-style courses, we want to suppress their title display)                  # new-style courses, we want to suppress their title display)
                 # then ignore it.                  # then ignore it.
Line 500  sub handler { Line 489  sub handler {
                 my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)];                  my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)];
   
                 # FIRST COL: The resource indentation, branch icon, name, and anchor                  # FIRST COL: The resource indentation, branch icon, name, and anchor
                 $r->print("  <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\" width=\"60%\">\n");                  $r->print("  <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\">\n");
   
                 # Print the anchor if necessary                  # Print the anchor if necessary
                 if ($counter == $currentUrlIndex - $currentUrlDelta) {                  if ($counter == $currentUrlIndex - $currentUrlDelta) {
Line 508  sub handler { Line 497  sub handler {
                 }                  }
   
                 # print indentation                  # print indentation
                 for (my $i = 0; $i < $indentLevel - $deltalevel + $inlinedelta; $i++) {                  for (my $i = 0; $i < $indentLevel - $deltalevel; $i++) {
                     $r->print($indentString);                      $r->print($indentString);
                 }                  }
   
Line 1276  getIterator behaves as follows: Line 1265  getIterator behaves as follows:
   
 =over 4  =over 4
   
 =item * B<getIterator>(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.  =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop): 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. forceTop is a boolean value. If it is false (default), the iterator will only return the first level of map that is not just a single, 'redirecting' map. If true, the iterator will return all information, starting with the top-level map, regardless of content.
   
 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.  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.
   
Line 1296  The iterator will return either a refere Line 1285  The iterator will return either a refere
   
 The tokens are retreivable via methods on the iterator object, i.e., $iterator->END_MAP.  The tokens are retreivable via methods on the iterator object, i.e., $iterator->END_MAP.
   
   Maps can contain empty resources. The iterator will automatically skip over such resources, but will still treat the structure correctly. Thus, a complicated map with several branches, but consisting entirely of empty resources except for one beginning or ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs, but only one resource will be returned.
   
 =back  =back
   
 =cut  =cut
Line 1346  sub new { Line 1337  sub new {
     if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };      if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
     $self->{CONDITION} = shift;      $self->{CONDITION} = shift;
   
       # Do we want to automatically follow "redirection" maps?
       $self->{FORCE_TOP} = shift;
   
     # Now, we need to pre-process the map, by walking forward and backward      # Now, we need to pre-process the map, by walking forward and backward
     # over the parts of the map we're going to look at.      # over the parts of the map we're going to look at.
   
Line 1361  sub new { Line 1355  sub new {
   
     my $maxDepth = 0; # tracks max depth      my $maxDepth = 0; # tracks max depth
   
       # If there is only one resource in this map, and it's a map, we
       # want to remember that, so the user can ask for the first map
       # that isn't just a redirector.
       my $resource; my $resourceCount = 0;
   
     # **1**      # **1**
   
     foreach my $pass (@iterations) {      foreach my $pass (@iterations) {
Line 1384  sub new { Line 1383  sub new {
             if ($curRes == $iterator->END_MAP()) { $depth--; }              if ($curRes == $iterator->END_MAP()) { $depth--; }
                   
             if (ref($curRes)) {              if (ref($curRes)) {
                   # If there's only one resource, this will save it
                   if($direction == FORWARD) { $resource = $curRes; $resourceCount++; }
                 my $resultingVal = $curRes->{DATA}->{$valName};                  my $resultingVal = $curRes->{DATA}->{$valName};
                 my $nextResources = $curRes->$nextResourceMethod();                  my $nextResources = $curRes->$nextResourceMethod();
                 my $resourceCount = scalar(@{$nextResources});                  my $nextCount = scalar(@{$nextResources});
   
                 if ($resourceCount == 1) { # **3**                  if ($nextCount == 1) { # **3**
                     my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;                      my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
                     $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);                      $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
                 }                  }
                                   
                 if ($resourceCount > 1) { # **4**                  if ($nextCount > 1) { # **4**
                     foreach my $res (@{$nextResources}) {                      foreach my $res (@{$nextResources}) {
                         my $current = $res->{DATA}->{$valName} || 999999999;                          my $current = $res->{DATA}->{$valName} || 999999999;
                         $res->{DATA}->{$valName} = min($current, $resultingVal + 1);                          $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
Line 1413  sub new { Line 1414  sub new {
         }          }
     }      }
   
       # Check: Was this only one resource, a map?
       if ($resourceCount == 1 && $resource->is_map() && !$self->{FORCE_TOP}) { 
           my $firstResource = $resource->map_start();
           my $finishResource = $resource->map_finish();
           return 
               Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
                                                 $finishResource, $self->{FILTER},
                                                 $self->{ALREADY_SEEN}, 
                                                 $self->{CONDITION}, 0);
           
       }
   
     # Set up some bookkeeping information.      # Set up some bookkeeping information.
     $self->{CURRENT_DEPTH} = 0;      $self->{CURRENT_DEPTH} = 0;
     $self->{MAX_DEPTH} = $maxDepth;      $self->{MAX_DEPTH} = $maxDepth;
Line 1562  sub next { Line 1575  sub next {
                                               $self->{ALREADY_SEEN}, $self->{CONDITION});                                                $self->{ALREADY_SEEN}, $self->{CONDITION});
     }      }
   
       # If this is a blank resource, don't actually return it.
       if (!$self->{HERE}->src()) {
           return $self->next();
       }
   
     return $self->{HERE};      return $self->{HERE};
   
 }  }
Line 1745  sub next { Line 1763  sub next {
                                              $self->{CONDITION}, $self->{DIRECTION});                                               $self->{CONDITION}, $self->{DIRECTION});
     }      }
   
       # If this is a blank resource, ignore it.
       if (!$self->{HERE}->src()) {
           return $self->next();
       }
       
     return $self->{HERE};      return $self->{HERE};
 }  }
   

Removed from v.1.115  
changed lines
  Added in v.1.116


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>