--- loncom/interface/lonnavmaps.pm 2003/03/25 22:35:58 1.167 +++ loncom/interface/lonnavmaps.pm 2003/04/04 21:00:54 1.173 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.167 2003/03/25 22:35:58 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.173 2003/04/04 21:00:54 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,6 @@ # Jeremy Bowers ... lots of days package Apache::lonnavmaps; -use vars qw($test @refsToUntie %navmaphash %parmhash); use strict; use Apache::Constants qw(:common :http); @@ -96,34 +95,6 @@ my %colormap = # And a special case in the nav map; what to do when the assignment # is not yet done and due in less then 24 hours my $hurryUpColor = "#FF0000"; -$test = 'abc'; -sub cleanup { - &Apache::lonnet::logthis("Cleanup called."); - &Apache::lonnet::logthis("refs size".scalar(@refsToUntie)); - &Apache::lonnet::logthis("test is ".$test); - $test = '467'; - if (tied(%navmaphash)){ - &Apache::lonnet::logthis('Cleanup navmaps: navmaphash'); - unless (untie(%navmaphash)) { - &Apache::lonnet::logthis('Failed cleanup navmaps: navmaphash'); - } - } - if (tied(%parmhash)){ - &Apache::lonnet::logthis('Cleanup navmaps: parmhash'); - unless (untie(%parmhash)) { - &Apache::lonnet::logthis('Failed cleanup navmaps: parmhash'); - } - } - # Apparently, if you take a reference to a tied hash, both the - # original hash and the tied hash must be untied. Bleh. - for my $ref (@refsToUntie) { - &Apache::lonnet::logthis('Cleanup navmaps: reference'); - unless (untie(%$ref)) { - &Apache::lonnet::logthis('Failed cleanup navmaps: reference'); - } - } - @refsToUntie = (); -} sub handler { my $r = shift; @@ -154,7 +125,7 @@ sub real_handler { $r->send_http_header; # Create the nav map - my $navmap = Apache::lonnavmaps::navmap->new($r, + my $navmap = Apache::lonnavmaps::navmap->new( $ENV{"request.course.fn"}.".db", $ENV{"request.course.fn"}."_parms.db", 1, 1); @@ -228,22 +199,11 @@ sub real_handler { # renderer call my $render = render({ 'cols' => [0,1,2,3], 'url' => '/adm/navmaps', + 'navmap' => $navmap, 'suppressNavmap' => 1, 'r' => $r}); - #$navmap->untieHashes(); - - if (tied(%navmaphash)) { - $r->print("Dang it."); - } else { - $r->print("It's out."); - } - - if (tied(%parmhash)) { - $r->print("Dang it."); - } else { - $r->print("It's out."); - } + $navmap->untieHashes(); $r->print(""); $r->rflush(); @@ -531,7 +491,7 @@ The pre-packaged column names are refere =item * B: If true (default), the resource will show a part count if the full part list is not displayed. If false, the resource will never show a part count. -=item * B: If true, the resource's folder will not be clickable to open or close it. Default is false. +=item * B: If true, the resource's folder will not be clickable to open or close it. Default is false. True implies printCloseAll is false, since you can't close or open folders when this is on anyhow. =back @@ -888,7 +848,7 @@ sub render { if (!$ENV{'form.folderManip'} && !defined($args->{'iterator'})) { # Step 1: Check to see if we have a navmap if (!defined($navmap)) { - $navmap = Apache::lonnavmaps::navmap->new($r, + $navmap = Apache::lonnavmaps::navmap->new( $ENV{"request.course.fn"}.".db", $ENV{"request.course.fn"}."_parms.db", 1, 1); $mustCloseNavMap = 1; @@ -1033,7 +993,7 @@ sub render { $result .= ''; } - if ($printCloseAll) { + if ($printCloseAll && !$args->{'resource_no_folder_link'}) { if ($condition) { $result.="{NAV_HASH} = \%navmaphash; + $self->{PARM_HASH} = \%parmhash; $self->{INITED} = 0; - $self->{RESPONSE}->register_cleanup(\&Apache::lonnavmaps::cleanup); - Apache::lonnet::logthis("Pushed cleanup."); - bless($self); return $self; @@ -1472,18 +1433,11 @@ sub getIterator { # unties the hash when done sub untieHashes { -# my $self = shift; -# untie $self->{NAV_HASH}; -# untie $self->{PARM_HASH}; -# &Apache::lonnavmaps::cleanup(); + my $self = shift; + untie %{$self->{NAV_HASH}}; + untie %{$self->{PARM_HASH}}; } -# when the object is destroyed, be sure to untie all the hashes we tied. -#sub DESTROY { -# my $self = shift; -# $self->untieHashes(); -#} - # Private method: Does the given resource (as a symb string) have # current discussion? Returns 0 if chat/mail data not extracted. sub hasDiscussion { @@ -1543,6 +1497,14 @@ sub getById { return "Apache::lonnavmaps::resource"->new($self, $id); } +sub getBySymb { + my $self = shift; + my $symb = shift; + my ($mapUrl, $id, $filename) = split (/___/, $symb); + my $map = $self->getResourceByUrl($mapUrl); + return $self->getById($map->map_pc() . '.' . $id); +} + =pod =item * B(): Returns a resource object reference corresponding to the first resource in the navmap. @@ -1669,7 +1631,7 @@ sub parmval_real { =item * B(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(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 in the list; regardless of branching, recursion, etc., it will be a flat list. +=item * B(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 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 many resources match a given description; for this use, if all you want to know is if I resources match the description, the bailout parameter will allow you to avoid potentially expensive enumeration of all matching resources. @@ -1710,7 +1672,7 @@ sub retrieveResources { # Create the necessary iterator. if (!ref($map)) { # assume it's a url of a map. - $map = $self->getMapByUrl($map); + $map = $self->getResourceByUrl($map); } # Check the map's validity.