--- loncom/interface/lonnavmaps.pm 2014/12/11 01:56:34 1.504 +++ loncom/interface/lonnavmaps.pm 2015/04/13 16:30:28 1.505 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.504 2014/12/11 01:56:34 raeburn Exp $ +# $Id: lonnavmaps.pm,v 1.505 2015/04/13 16:30:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees @@ -2927,7 +2927,7 @@ resource appears multiple times in the c will be returned (useful for maps), unless the multiple parameter has been included, in which case all instances are returned in an array. -=item * B(map, filterFunc, recursive, bailout, showall): +=item * B(map, filterFunc, recursive, bailout, showall, noblockcheck): The map is a specification of a map to retreive the resources from, either as a url or as an object. The filterFunc is a reference to a @@ -2936,13 +2936,18 @@ true if the resource should be included, be. If recursive is true, the map will be recursively examined, otherwise it will not be. If bailout is true, the function will return as soon as it finds a resource, if false it will finish. If showall is -true it will not hide maps that contain nothing but one other map. By -default, the map is the top-level map of the course, filterFunc is a -function that always returns 1, recursive is true, bailout is false, -showall is false. The resources will be returned in a list containing -the resource objects for the corresponding resources, with B in the list; regardless of branching, -recursion, etc., it will be a flat list. +true it will not hide maps that contain nothing but one other map. The +noblockcheck arg is propagated to become the sixth arg in the call to +lonnet::allowed when checking a resource's availability during collection +of resources using the iterator. noblockcheck needs to be true if +retrieveResources() was called by a routine that itself was called by +lonnet::allowed, in order to avoid recursion. By default the map +is the top-level map of the course, filterFunc is a function that +always returns 1, recursive is true, bailout is false, showall is +false. The resources will be returned in a list containing the +resource objects for the corresponding resources, with B in the list; regardless of branching, recursion, etc., +it will be a flat list. Thus, this is suitable for cases where you don't want the structure, just a list of all resources. It is also suitable for finding out how @@ -3009,6 +3014,7 @@ sub retrieveResources { my $bailout = shift; if (!defined($bailout)) { $bailout = 0; } my $showall = shift; + my $noblockcheck = shift # Create the necessary iterator. if (!ref($map)) { # assume it's a url of a map. $map = $self->getResourceByUrl($map); @@ -3038,7 +3044,7 @@ sub retrieveResources { # Run down the iterator and collect the resources. my $curRes; - while ($curRes = $it->next()) { + while ($curRes = $it->next(undef,$noblockcheck)) { if (ref($curRes)) { if (!&$filterFunc($curRes)) { next; @@ -3189,7 +3195,14 @@ Note that inside of the loop, it's frequ resource objects will be references, and any non-references will be the tokens described above. -Also note there is some old code floating around that trys to track +The next() routine can take two (optional) arguments: +closeAllPages - if true will not recurse down a .page +noblockcheck - passed to browsePriv() for passing as sixth arg to +call to lonnet::allowed. This needs to be set if retrieveResources +was already called from another routine called within lonnet::allowed, +so as to prevent recursion. + +Also note there is some old code floating around that triess to track the depth of the iterator to see when it's done; do not copy that code. It is difficult to get right and harder to understand than this. They should be migrated to this new style. @@ -3365,6 +3378,7 @@ sub new { sub next { my $self = shift; my $closeAllPages=shift; + my $noblockcheck = shift; if ($self->{FINISHED}) { return END_ITERATOR(); } @@ -3514,7 +3528,7 @@ sub next { # If this is a blank resource, don't actually return it. # Should you ever find you need it, make sure to add an option to the code # that you can use; other things depend on this behavior. - my $browsePriv = $self->{HERE}->browsePriv(); + my $browsePriv = $self->{HERE}->browsePriv($noblockcheck); if (!$self->{HERE}->src() || (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) { return $self->next($closeAllPages); @@ -5657,12 +5671,14 @@ sub getPrevious { sub browsePriv { my $self = shift; + my $noblockcheck = shift; if (defined($self->{BROWSE_PRIV})) { return $self->{BROWSE_PRIV}; } $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(), - $self->symb()); + $self->symb(),undef, + undef,$noblockcheck); } =pod