Diff for /loncom/interface/lonnavmaps.pm between versions 1.144 and 1.145

version 1.144, 2003/02/20 22:08:55 version 1.145, 2003/02/21 20:05:00
Line 533  Most of these parameters are only useful Line 533  Most of these parameters are only useful
   
 In addition to the parameters you can pass to the renderer, which will be passed through unchange to the column renderers, the renderer will generate the following information which your renderer may find useful:  In addition to the parameters you can pass to the renderer, which will be passed through unchange to the column renderers, the renderer will generate the following information which your renderer may find useful:
   
   If you want to know how many rows were printed, the 'counter' element of the hash passed into the render function will contain the count. You may want to check whether any resources were printed at all.
   
 =over 4  =over 4
   
 =back  =back
Line 941  sub render { Line 943  sub render {
         # See if we're being passed a specific map          # See if we're being passed a specific map
         if ($args->{'iterator_map'}) {          if ($args->{'iterator_map'}) {
             my $map = $args->{'iterator_map'};              my $map = $args->{'iterator_map'};
             $map = &Apache::lonnet::clutter($map);              $map = $navmap->getResourceByUrl($map);
             $map = $navmap->{NAV_HASH}->{'ids_' . $map};  
             $map = $navmap->getById($map);  
             my $firstResource = $map->map_start();              my $firstResource = $map->map_start();
             my $finishResource = $map->map_finish();              my $finishResource = $map->map_finish();
   
Line 1613  sub parmval_real { Line 1613  sub parmval_real {
     return '';      return '';
 }  }
   
   =pod 
   
   =item * B<getResourceByUrl>(url): Retrieves a resource object by URL of the resource. If passed a resource object, it will simply return it, so it is safe to use this method in code like "$res = $navmap->getResourceByUrl($res)", if you're not sure if $res is already an object, or just a URL. If the resource appears multiple times in the course, only the first instance will be returned. As a result, this is probably useful only for maps.
   
   =item * B<retrieveResources>(map, filterFunc, recursive, bailout): 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 function that takes a resource object as its one argument and returns true if the resource should be included, or false if it should not 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. 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. The resources will be returned in a list reference containing the resource objects for the corresponding resources, with B<no structure information> 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 many resources match a given description; for this use, if all you want to know is if I<any> resources match the description, the bailout parameter will allow you to avoid potentially expensive enumeration of all matching resources.
   
   =cut
   
   sub getResourceByUrl {
       my $self = shift;
       my $resUrl = shift;
   
       if (ref($resUrl)) { return $resUrl; }
   
       $resUrl = &Apache::lonnet::clutter($resUrl);
       my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
       if ($resId =~ /,/) {
           $resId = (split (/,/, $resId))[0];
       }
       if (!$resId) { return ''; }
       return $self->getById($resId);
   }
   
   sub retrieveResources {
       my $self = shift;
       my $map = shift;
       my $filterFunc = shift;
       if (!defined ($filterFunc)) {
           $filterFunc = sub {return 1;};
       }
       my $recursive = shift;
       if (!defined($recursive)) { $recursive = 1; }
       my $bailout = shift;
       if (!defined($bailout)) { $bailout = 0; }
   
       # Create the necessary iterator.
       if (!ref($map)) { # assume it's a url of a map.
           $map = $self->getMapByUrl($map);
       }
   
       # Check the map's validity.
       if (!$map || !$map->is_map()) {
           # Oh, to throw an exception.... how I'd love that!
           return ();
       }
   
       # UNFINISHED... I was checking in getResourceByUrl
   }
   
 1;  1;
   
 package Apache::lonnavmaps::iterator;  package Apache::lonnavmaps::iterator;

Removed from v.1.144  
changed lines
  Added in v.1.145


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