--- loncom/interface/lonnavmaps.pm 2003/02/21 20:05:00 1.145 +++ loncom/interface/lonnavmaps.pm 2003/03/08 20:12:32 1.153 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.145 2003/02/21 20:05:00 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.153 2003/03/08 20:12:32 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,12 +38,15 @@ # YEAR=2002 # 1/1 Gerd Kortemeyer # Oct-Nov Jeremy Bowers +# YEAR=2003 +# Jeremy Bowers ... lots of days package Apache::lonnavmaps; use strict; use Apache::Constants qw(:common :http); use Apache::loncommon(); +use Apache::lonmenu(); use POSIX qw (floor strftime); my %navmaphash; @@ -152,11 +155,21 @@ sub real_handler { } $r->print("\n"); - $r->print("Navigate Course Contents"); + $r->print("Navigate Course Contents"); +# ------------------------------------------------------------ Get query string + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']); +# ----------------------------------------------------- Force menu registration + my $addentries=''; + if ($ENV{'form.register'}) { + $addentries=' onLoad="'.&Apache::lonmenu::loadevents(). + '" onUnload="'.&Apache::lonmenu::unloadevents().'"'; + $r->print(&Apache::lonmenu::registerurl(1)); + } # Header - $r->print(&Apache::loncommon::bodytag('Navigate Course Contents','', - '')); + $r->print(''. + &Apache::loncommon::bodytag('Navigate Course Contents','', + $addentries,'','',$ENV{'form.register'})); $r->print(''); $r->rflush(); @@ -178,7 +191,7 @@ sub real_handler { # renderer call my $render = render({ 'cols' => [0,1,2,3], 'url' => '/adm/navmaps', - 'printKey' => 1, + 'suppressNavmap' => 1, 'r' => $r}); $navmap->untieHashes(); @@ -525,7 +538,9 @@ Most of these parameters are only useful =item * B: If true, print the "Close all folders" or "open all folders" links. Default is true. -=item * B: A function that takes the resource object as its only parameter and returns a true or false value. If true, the resource is displayed. If false, it is simply skipped in the display. By default, all resources are showne. +=item * B: A function that takes the resource object as its only parameter and returns a true or false value. If true, the resource is displayed. If false, it is simply skipped in the display. By default, all resources are shown. + +=item * B: If true, will not display Navigate Content resources. Default to false. =back @@ -804,6 +819,7 @@ sub render { my $here; my $jump; my $currentJumpIndex = setDefault($args->{'currentJumpIndex'}, 0); + my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0); my $currentJumpDelta = 2; # change this to change how many resources are displayed # before the current resource when using #current @@ -1070,6 +1086,12 @@ sub render { next; } + # If we're suppressing navmaps and this is a navmap, continue on + if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) { + $curRes = $it->next(); + next; + } + # Does it have multiple parts? $args->{'multipart'} = 0; $args->{'condensed'} = 0; @@ -1181,7 +1203,7 @@ sub render { $result .= " \n"; $args->{'isNewBranch'} = 0; } - + if ($r && $rownum % 20 == 0) { $r->print($result); $result = ""; @@ -1621,6 +1643,12 @@ sub parmval_real { 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. +=item * B(map, filterFunc, recursive): Convience method for + + scalar(retrieveResources($map, $filterFunc, $recursive, 1)) > 0 + +which will tell whether the map has resources matching the description in the filter function. + =cut sub getResourceByUrl { @@ -1661,7 +1689,50 @@ sub retrieveResources { return (); } - # UNFINISHED... I was checking in getResourceByUrl + # Get an iterator. + my $it = $self->getIterator($map->map_start(), $map->map_finish(), + !$recursive); + + my @resources = (); + + # Run down the iterator and collect the resources. + my $depth = 1; + $it->next(); + my $curRes = $it->next(); + + while ($depth > 0) { + if ($curRes == $it->BEGIN_MAP()) { + $depth++; + } + if ($curRes == $it->END_MAP()) { + $depth--; + } + + if (ref($curRes)) { + if (!&$filterFunc($curRes)) { + next; + } + + push @resources, $curRes; + + if ($bailout) { + return @resources; + } + } + + $curRes = $it->next(); + } + + return @resources; +} + +sub hasResource { + my $self = shift; + my $map = shift; + my $filterFunc = shift; + my $recursive = shift; + + return scalar($self->retrieveResources($map, $filterFunc, $recursive, 1)) > 0; } 1; @@ -2631,28 +2702,30 @@ sub countParts { sub extractParts { my $self = shift; - return if ($self->{PARTS}); + return if (defined($self->{PARTS})); return if ($self->ext); $self->{PARTS} = []; # Retrieve part count, if this is a problem if ($self->is_problem()) { - my $metadata = &Apache::lonnet::metadata($self->src(), 'allpossiblekeys'); + my $metadata = &Apache::lonnet::metadata($self->src(), 'packages'); if (!$metadata) { $self->{RESOURCE_ERROR} = 1; $self->{PARTS} = []; return; } - foreach (split(/\,/,$metadata)) { - if ($_ =~ /^parameter\_(.*)\_opendate$/) { - push @{$self->{PARTS}}, $1; + if ($_ =~ /^part_(.*)$/) { + my $part = $1; + # check to see if part is turned off. + if (! Apache::loncommon::check_if_partid_hidden($part, $self->symb())) { + push @{$self->{PARTS}}, $1; + } } } - # Is this possible to do in one line? - Jeremy my @sortedParts = sort @{$self->{PARTS}}; $self->{PARTS} = \@sortedParts; }