Diff for /loncom/interface/lonnavmaps.pm between versions 1.100 and 1.101

version 1.100, 2002/11/08 19:10:58 version 1.101, 2002/11/08 20:58:13
Line 89  sub handler { Line 89  sub handler {
     $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',      $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',
                                           ''));                                            ''));
     $r->print('<script>window.focus();</script>');      $r->print('<script>window.focus();</script>');
     my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};  
     $r->print('<table border="0" cellpadding="2" cellspacing="0">');      $r->print('<table border="0" cellpadding="2" cellspacing="0">');
     my $date=localtime;      my $date=localtime;
     $r->print('<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>');      $r->print('<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>');
   
       # Print discussions and feedback header
     if ($navmap->{LAST_CHECK}) {      if ($navmap->{LAST_CHECK}) {
         $r->print('<td align="center" valign="bottom">&nbsp;&nbsp;'.          $r->print('<td align="center" valign="bottom">&nbsp;&nbsp;'.
                   '<img src="/adm/lonMisc/chat.gif"> New discussion since '.                    '<img src="/adm/lonMisc/chat.gif"> New discussion since '.
Line 107  sub handler { Line 109  sub handler {
                   '</td>');                     '</td>'); 
     }      }
     $r->print('</tr></table>');      $r->print('</tr></table>');
   
     my $condition = 0;      my $condition = 0;
     if ($ENV{'form.condition'}) {      if ($ENV{'form.condition'}) {
         $condition = 1;          $condition = 1;
Line 135  sub handler { Line 138  sub handler {
     # is technically not proper, but should be harmless      # is technically not proper, but should be harmless
     my $res = $navmap->firstResource();      my $res = $navmap->firstResource();
   
       # These are some data tables, which make it easy to change some of
       # of the specific visualization parameters if desired.
   
     # Defines a status->color mapping, null string means don't color      # Defines a status->color mapping, null string means don't color
     my %colormap =       my %colormap = 
     ( $res->NETWORK_FAILURE        => '',      ( $res->NETWORK_FAILURE        => '',
Line 192  sub handler { Line 198  sub handler {
     my $currenturl = $ENV{'form.postdata'};      my $currenturl = $ENV{'form.postdata'};
     $currenturl=~s/^http\:\/\///;      $currenturl=~s/^http\:\/\///;
     $currenturl=~s/^[^\/]+//;      $currenturl=~s/^[^\/]+//;
   
     # alreadyHere allows us to only open the maps necessary to view      # alreadyHere allows us to only open the maps necessary to view
     # the current location once, while at the same time remembering      # the current location once, while at the same time remembering
     # the current location. Without that check, the user would never      # the current location. Without that check, the user would never
Line 210  sub handler { Line 217  sub handler {
     # Here's a simple example of the iterator.      # Here's a simple example of the iterator.
     # Preprocess the map: Look for current URL, force inlined maps to display      # Preprocess the map: Look for current URL, force inlined maps to display
   
     # This currently does very little...      my $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, 1);
     #my $mapEventualIterator = Apache::lonnavmaps::iterator->new($navmap, undef, undef, {},  
     #undef, $condition);  
   
     my $mapIterator = $navmap->getIterator(undef, undef, {}, 1);  
     my $found = 0;      my $found = 0;
     my $depth = 1;      my $depth = 1;
     my $currentUrlIndex = 0; # keeps track of when the current resource is found,      my $currentUrlIndex = 0; # keeps track of when the current resource is found,
                              # so we can back up a few and put the anchor above the                               # so we can back up a few and put the anchor above the
                              # current resource                               # current resource
       my $currentUrlDelta = 5; # change this to change how many resources are displayed
                                # before the current resource when using #current
     $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;
Line 237  sub handler { Line 242  sub handler {
             # show it by making sure the containing maps              # show it by making sure the containing maps
             # are open.              # are open.
   
               # This is why we have to use the main iterator instead of the
               # potentially faster DFS: The count has to be the same, so
               # the order has to be the same, which DFS won't give us.
             $currentUrlIndex = $counter;              $currentUrlIndex = $counter;
                           
               # Ensure the parent maps are open
             for my $map (@{$mapStack}) {              for my $map (@{$mapStack}) {
                 if ($condition) {                  if ($condition) {
                     undef $filterHash{$map->map_pc()};                      undef $filterHash{$map->map_pc()};
Line 286  sub handler { Line 295  sub handler {
   
     $counter = 0;      $counter = 0;
   
       # Print the 'current' anchor here if it would fall off the top
       if ($currentUrlIndex - $currentUrlDelta < 0) {
           $r->print('<a name="current" />');
       }
   
     while ($depth > 0) {      while ($depth > 0) {
         # If we're in a new style course, and this is a BEGIN_MAP, END_MAP, or          # If this is an inlined map, cancel the shift to the right,
         # map resource and the stack depth is only one, just plain ignore this resource          # which has the effect of making the map look inlined
         # entirely. (This has the effect of inlining the resources in that map  
         # in the nav map.)  
         if ($inlineTopLevelMaps && scalar(@{$mapIterator->getStack()}) == 1 &&          if ($inlineTopLevelMaps && scalar(@{$mapIterator->getStack()}) == 1 &&
             ref($curRes) && $curRes->is_map()) {              ref($curRes) && $curRes->is_map()) {
             # We let the normal depth stuff occur, but we need to shift everything  
             # over by one to the left to make it look right.  
             $deltadepth = -1;              $deltadepth = -1;
             $curRes = $mapIterator->next();              $curRes = $mapIterator->next();
             next;              next;
Line 319  sub handler { Line 329  sub handler {
         if ($depth == 1) { $deltadepth = 0; } # we're done shifting, because we're          if ($depth == 1) { $deltadepth = 0; } # we're done shifting, because we're
                                               # out of the inlined map                                                # out of the inlined map
   
         # Is this resource being blotted out?          # Is this resource being ignored because it is in a random-out
           # map and it was not selected?
         if (ref($curRes) && !advancedUser() && $curRes->randomout()) {          if (ref($curRes) && !advancedUser() && $curRes->randomout()) {
             $curRes = $mapIterator->next();              $curRes = $mapIterator->next();
             next; # and totally ignore this resource              next; # if yes, then just ignore this resource
         }          }
   
         if (ref($curRes) && $curRes->src()) {          if (ref($curRes) && $curRes->src()) {
Line 333  sub handler { Line 344  sub handler {
             my $condensed = 0;              my $condensed = 0;
                                   
             if ($curRes->is_problem()) {              if ($curRes->is_problem()) {
                 # Is it multipart?  
   
                   # Is it multipart?
                 if ($multipart) {                  if ($multipart) {
                     # If it's multipart, see if part 0 is "open"                      # If it's multipart, see if part 0 is "open"
                     # if it is, display all parts, if it isn't,                      # if it is, display all parts, if it isn't,
                     # just display first                      # just display first
                     if (!$curRes->opendate("0")) {                      if (!$curRes->opendate("0")) {
                         @parts = ("0"); # just display the zero-th part                          # no parts are open, display as one part
                           @parts = ("0");
                         $condensed = 1;                          $condensed = 1;
                     } else {                      } else {
                         # Otherwise, only display part 0 if we want to                           # Otherwise, only display part 0 if we want to 
Line 348  sub handler { Line 360  sub handler {
                         if ($curRes->hasDiscussion() || $curRes->getFeedback()) {                          if ($curRes->hasDiscussion() || $curRes->getFeedback()) {
                             shift @parts;                              shift @parts;
                         } else {                          } else {
                             # If there's discussion or feedback, that counts  
                             # as a difference, so display the parts.  
                               
                             # Now, we decide whether to condense the                              # Now, we decide whether to condense the
                             # parts due to similarity                              # parts due to similarity
                             my $status = $curRes->status($parts[1]);                              my $status = $curRes->status($parts[1]);
Line 391  sub handler { Line 400  sub handler {
             } else {              } else {
                 $parts[0] = "0"; # this is to get past foreach loop below                  $parts[0] = "0"; # this is to get past foreach loop below
                  # you can consider a non-problem resource as a resource                   # you can consider a non-problem resource as a resource
                   # with only one part without loss                    # with only one part without loss, and it simplifies the looping
             }              }
   
             # Is it a multipart problem with a single part, now in               # Is it a multipart problem with a single part, now in 
             # @parts with "0" filtered out? If so, forget it's a multi-part              # @parts with "0" filtered out? If so, 'forget' it's a multi-part
             # problem and treat it like a single-part problem.              # problem and treat it like a single-part problem.
             if ( scalar(@parts) == 1 ) {              if ( scalar(@parts) == 1 ) {
                 $multipart = 0;                  $multipart = 0;
Line 403  sub handler { Line 412  sub handler {
   
             # Display one part, in event of network error.              # Display one part, in event of network error.
             # If this is a single part, we can at least show the correct              # If this is a single part, we can at least show the correct
             # status, but if it's multipart, we're lost.              # status, but if it's multipart, we're lost, since we can't
               # retreive the metadata to count the parts
             if ($curRes->{RESOURCE_ERROR}) {              if ($curRes->{RESOURCE_ERROR}) {
                 @parts = ("0");                  @parts = ("0");
             }              }
   
             # Step two: Show the parts              # Step Two: Print the actual data.
   
               # For each part we intend to display...
             foreach my $part (@parts) {              foreach my $part (@parts) {
   
                 my $deltalevel = 0; # for inserting the branch icon                  my $deltalevel = 0; # for inserting the branch icon
                 my $nonLinkedText = ""; # unlinked stuff after title                  my $nonLinkedText = ""; # unlinked stuff after title
                                   
                 # For each thing we're displaying...  
   
                 my $stack = $mapIterator->getStack();                  my $stack = $mapIterator->getStack();
                 my $src = getLinkForResource($stack);                  my $src = getLinkForResource($stack);
   
                   # Pass the correct symb on the querystring, so the
                   # remote will figure out where we are if we click a link
                 my $srcHasQuestion = $src =~ /\?/;                  my $srcHasQuestion = $src =~ /\?/;
                 my $link = $src.                  my $link = $src.
                     ($srcHasQuestion?'&':'?') .                      ($srcHasQuestion?'&':'?') .
                     'symb='.&Apache::lonnet::escape($curRes->symb()).                      'symb='.&Apache::lonnet::escape($curRes->symb()).
                     '"';                      '"';
   
                 my $title = $curRes->title();                  my $title = $curRes->title();
                 if (!$title) {                  if (!$title) {
                     $title = $curRes->src();                      $title = $curRes->src();
Line 433  sub handler { Line 446  sub handler {
                 my $newBranchText = "";                  my $newBranchText = "";
   
                 # If this is a new branch, label it so                  # If this is a new branch, label it so
                 # (temporary, this should be an icon w/ alt text)  
                 if ($isNewBranch) {                  if ($isNewBranch) {
                     $newBranchText = "<img src=\"/adm/lonIcons/branch.gif\" border=\"0\">";                      $newBranchText = "<img src=\"/adm/lonIcons/branch.gif\" border=\"0\">";
                     $isNewBranch = 0;                      $isNewBranch = 0;
                     $deltalevel = 1;                      $deltalevel = 1; # reserves space for the branch icon
                 }                  }
   
                 # links to open and close the folders                  # links to open and close the folders
Line 509  sub handler { Line 521  sub handler {
                 # 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\" width=\"60%\">\n");
   
                 # anchor for current resource... - 5 is deliberate: If it's that                  # Print the anchor if necessary
                 # high on the screen, don't bother focusing on it. Also this will                  if ($counter == $currentUrlIndex - $currentUrlDelta) {
                 # print multiple anchors if this is an expanded multi-part problem...  
                 # who cares?  
                 if ($counter == $currentUrlIndex - 5) {  
                     $r->print('<a name="current" />');                      $r->print('<a name="current" />');
                 }                  }
   
Line 543  sub handler { Line 552  sub handler {
                 }                  }
   
                 $r->print("  $curMarkerBegin<a href=\"$link\">$title$partLabel</a> $curMarkerEnd $nonLinkedText");                  $r->print("  $curMarkerBegin<a href=\"$link\">$title$partLabel</a> $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}) {                  if ($curRes->{RESOURCE_ERROR}) {
                     $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down",                      $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down",
                                               '<font size="-1">Host down</font>'));                                                '<font size="-1">Host down</font>'));
                     }                      }
   
                   # SECOND COL: Is there text, feedback, errors??
                 my $discussionHTML = ""; my $feedbackHTML = "";                  my $discussionHTML = ""; my $feedbackHTML = "";
   
                 # SECOND COL: Is there text, feedback, errors??  
                 if ($curRes->hasDiscussion()) {                  if ($curRes->hasDiscussion()) {
                     $discussionHTML = $linkopen .                      $discussionHTML = $linkopen .
                         '<img border="0" src="/adm/lonMisc/chat.gif" />' .                          '<img border="0" src="/adm/lonMisc/chat.gif" />' .
Line 577  sub handler { Line 583  sub handler {
   
                 # Is this the first displayed part of a multi-part problem                  # Is this the first displayed part of a multi-part problem
                 # that has not been condensed, so we should suppress these two                  # 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";                  my $firstDisplayed = !$condensed && $multipart && $part eq "0";
   
                 # THIRD COL: Problem status icon                  # THIRD COL: Problem status icon
Line 595  sub handler { Line 602  sub handler {
                 }                  }
   
                 # FOURTH COL: Text description                  # FOURTH COL: Text description
                 #$r->print("<td $colorizer align=\"right\" valign=\"center\">\n");  
                 $r->print("<td align=\"right\" valign=\"center\">\n");                  $r->print("<td align=\"right\" valign=\"center\">\n");
                                   
                 if ($curRes->kind() eq "res" &&                  if ($curRes->kind() eq "res" &&
Line 727  sub getDescription { Line 733  sub getDescription {
     }      }
 }  }
   
   # This puts a human-readable name on the ENV variable.
 sub advancedUser {  sub advancedUser {
     return $ENV{'user.adv'};      return $ENV{'user.adv'};
 }  }
Line 772  sub timeToHumanString { Line 779  sub timeToHumanString {
         $delta = -$delta;          $delta = -$delta;
     }      }
   
     # Is it in the future?  
     if ( $delta > 0 ) {      if ( $delta > 0 ) {
         # Is it less then a minute away?  
         my $tense = $inPast ? " ago" : "";          my $tense = $inPast ? " ago" : "";
         my $prefix = $inPast ? "" : "in ";          my $prefix = $inPast ? "" : "in ";
           
           # Less then a minute
         if ( $delta < $minute ) {          if ( $delta < $minute ) {
             if ($delta == 1) { return "${prefix}1 second$tense"; }              if ($delta == 1) { return "${prefix}1 second$tense"; }
             return "$prefix$delta seconds$tense";              return "$prefix$delta seconds$tense";
         }          }
   
         # Is it less then an hour away?          # Less then an hour
         if ( $delta < $hour ) {          if ( $delta < $hour ) {
             # If so, use minutes              # If so, use minutes
             my $minutes = floor($delta / 60);              my $minutes = floor($delta / 60);
Line 876  sub new { Line 884  sub new {
     $self->{GENERATE_COURSE_USER_OPT} = shift;      $self->{GENERATE_COURSE_USER_OPT} = shift;
     $self->{GENERATE_EMAIL_DISCUSS_STATUS} = 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.      # them on-demand so we don't pay for creating resources unless we use them.
     $self->{RESOURCE_CACHE} = {};      $self->{RESOURCE_CACHE} = {};
   
Line 1029  sub courseMapDefined { Line 1037  sub courseMapDefined {
 sub getIterator {  sub getIterator {
     my $self = shift;      my $self = shift;
     my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,      my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
                                                      shift, undef, shift,                                                        shift, undef, shift);
                                                      $ENV{'form.direction'});  
     return $iterator;      return $iterator;
 }  }
   
Line 1121  sub finishResource { Line 1128  sub finishResource {
     return $self->getById($firstResource);      return $self->getById($firstResource);
 }  }
   
 # -------------------------------------------- Figure out a cascading parameter  # Parmval reads the parm hash and cascades the lookups. parmval_real does
 #  # the actual lookup; parmval caches the results.
 # For this function to work  
 #  
 # * parmhash needs to be tied  
 # * courseopt and useropt need to be initialized for this user and course  
 #  
   
 sub parmval {  sub parmval {
     my $self = shift;      my $self = shift;
     my ($what,$symb)=@_;      my ($what,$symb)=@_;
Line 1230  sub parmval_real { Line 1231  sub parmval_real {
   
 package Apache::lonnavmaps::iterator;  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  =pod
   
 =back  =back
Line 1254  getIterator behaves as follows: Line 1251  getIterator behaves as follows:
   
 =over 4  =over 4
   
 =item B<getIterator>(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<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.
   
 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:  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:
   
Line 1756  sub navHash { Line 1753  sub navHash {
   
 B<Metadata Retreival>  B<Metadata Retreival>
   
 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  =over 4
   
Line 1766  These are methods that help you retrieve Line 1763  These are methods that help you retrieve
   
 =item * B<kind>: Returns the kind of the resource from the compiled nav map.  =item * B<kind>: Returns the kind of the resource from the compiled nav map.
   
 =item * B<randomout>: Returns true if this resource was chosen to NOT be shown to the user by the random map selection feature.  =item * B<randomout>: 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<randompick>: Returns true for a map if the randompick feature is being used on the map. (?)  =item * B<randompick>: Returns true for a map if the randompick feature is being used on the map. (?)
   
Line 1826  These methods are shortcuts to deciding Line 1823  These methods are shortcuts to deciding
   
 =item * B<is_problem>: Returns true if the resource is a problem.  =item * B<is_problem>: Returns true if the resource is a problem.
   
 =item * B<is_sequence>: Returns true if the resource sequence.  =item * B<is_sequence>: Returns true if the resource is a sequence.
   
 =back  =back
   
Line 1855  sub is_sequence { Line 1852  sub is_sequence {
     return ($src =~ /sequence$/);      return ($src =~ /sequence$/);
 }  }
   
   # Private method: Shells out to the parmval in the nav map, handler parts.
   
   
   
 # Move this into POD: In order to use these correctly, courseopt  
 # and useropt need to be generated  
 sub parmval {  sub parmval {
     my $self = shift;      my $self = shift;
     my $what = shift;      my $what = shift;
Line 2143  sub extractParts { Line 2135  sub extractParts {
   
 =head2 Resource Status  =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.  There are two aspects to the status: the date-related information and the completion information.
   
Line 2160  Idiomatic usage of these two methods wou Line 2152  Idiomatic usage of these two methods wou
     ... use it here ...      ... 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  =over 4
   
 =item * B<getDateStatus>($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:  =item * B<getDateStatus>($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:
Line 2296  sub getCompletionStatus { Line 2292  sub getCompletionStatus {
   
 B<Composite Status>  B<Composite Status>
   
 Along with directly returning the date or completion status, the resource object includes a convenience function B<status>() 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<status>() 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  =over 4
   
Line 2400  sub status { Line 2396  sub status {
   
 =over 4  =over 4
   
 =item * B<getNext>($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<getNext>(): 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<getPrevious>($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<getPrevious>(): Retreive an array of the possible previous resources from this one. Always returns an array, even in the one- or zero-element case. 
   
 =cut  =cut
   
 sub getNext {  sub getNext {
     my $self = shift;      my $self = shift;
     my $alreadySeenHash = shift;  
     my @branches;      my @branches;
     my $to = $self->to();      my $to = $self->to();
     foreach my $branch ( split(/,/, $to) ) {      foreach my $branch ( split(/,/, $to) ) {
Line 2416  sub getNext { Line 2411  sub getNext {
         my $next = $choice->goesto();          my $next = $choice->goesto();
         $next = $self->{NAV_MAP}->getById($next);          $next = $self->{NAV_MAP}->getById($next);
   
         # Don't remember it if we've already seen it or if          # Don't remember it if the student doesn't have browse priviledges
         # 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);          my $browsePriv = &Apache::lonnet::allowed('bre', $self->src);
         if (!defined($alreadySeenHash) ||          if ($browsePriv ne '2' && $browsePriv ne 'F') {
             !defined($alreadySeenHash->{$next->{ID}}) ||              push @branches, $next;
             ($browsePriv ne '2' && $browsePriv ne 'F')) {          }
                 push @branches, $next;  
             }  
     }      }
     return \@branches;      return \@branches;
 }  }
   
 sub getPrevious {  sub getPrevious {
     my $self = shift;      my $self = shift;
     my $alreadySeenHash = shift;  
     my @branches;      my @branches;
     my $from = $self->from();      my $from = $self->from();
     foreach my $branch ( split /,/, $from) {      foreach my $branch ( split /,/, $from) {
Line 2438  sub getPrevious { Line 2430  sub getPrevious {
         my $prev = $choice->comesfrom();          my $prev = $choice->comesfrom();
         $prev = $self->{NAV_MAP}->getById($prev);          $prev = $self->{NAV_MAP}->getById($prev);
   
         # Skip it if we've already seen it or the user doesn't have          # Don't remember it if the student doesn't have browse priviledges
         # browse privs          # future note: this may properly belong in the client of the resource
         my $browsePriv = &Apache::lonnet::allowed('bre', $self->src);          my $browsePriv = &Apache::lonnet::allowed('bre', $self->src);
         if (!defined($alreadySeenHash) ||          if ($browsePriv ne '2' && $browsePriv ne 'F') {
             !defined($alreadySeenHash->{$prev->{ID}}) ||  
             ($browsePriv ne '2' && $browsePriv ne 'F')) {  
             push @branches, $prev;              push @branches, $prev;
         }          }
     }      }

Removed from v.1.100  
changed lines
  Added in v.1.101


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