--- loncom/interface/lonnavmaps.pm 2003/02/21 21:40:07 1.146
+++ loncom/interface/lonnavmaps.pm 2003/03/13 17:05:36 1.156
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.146 2003/02/21 21:40:07 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.156 2003/03/13 17:05:36 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();
@@ -175,10 +188,36 @@ sub real_handler {
return OK;
}
+ # See if there's only one map in the top-level... if so,
+ # automatically display it
+ my $iterator = $navmap->getIterator(undef, undef, undef, 0);
+ my $depth = 1;
+ $iterator->next();
+ my $curRes = $iterator->next();
+ my $sequenceCount = 0;
+ my $sequenceId;
+ while ($depth > 0) {
+ if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
+ if ($curRes == $iterator->END_MAP()) { $depth--; }
+
+ if (ref($curRes) && $curRes->is_sequence()) {
+ $sequenceCount++;
+ $sequenceId = $curRes->map_pc();
+ }
+
+ $curRes = $iterator->next();
+ }
+
+ if ($sequenceCount == 1) {
+ # The automatic iterator creation in the render call
+ # will pick this up.
+ $ENV{'form.filter'} = "$sequenceId";
+ }
+
# renderer call
my $render = render({ 'cols' => [0,1,2,3],
'url' => '/adm/navmaps',
- 'printKey' => 1,
+ 'suppressNavmap' => 1,
'r' => $r});
$navmap->untieHashes();
@@ -525,7 +564,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
@@ -579,7 +620,7 @@ sub render_resource {
my $icon = "
";
if ($resource->is_problem()) {
- if ($part eq "0" || $params->{'condensed'}) {
+ if ($part eq "" || $params->{'condensed'}) {
$icon = '
';
} else {
$icon = $params->{'indentString'};
@@ -651,7 +692,7 @@ sub render_resource {
$curMarkerEnd = '<';
}
- if ($resource->is_problem() && $part ne "0" &&
+ if ($resource->is_problem() && $part ne "" &&
!$params->{'condensed'}) {
$partLabel = " (Part $part)";
$title = "";
@@ -804,6 +845,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
@@ -1065,11 +1107,15 @@ sub render {
# If this has been filtered out, continue on
if (!(&$filterFunc($curRes))) {
- $curRes = $it->next();
$args->{'isNewBranch'} = 0; # Don't falsely remember this
next;
}
+ # If we're suppressing navmaps and this is a navmap, continue on
+ if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
+ next;
+ }
+
# Does it have multiple parts?
$args->{'multipart'} = 0;
$args->{'condensed'} = 0;
@@ -1120,28 +1166,19 @@ sub render {
}
}
-
- } else {
- # Not showing parts
- @parts = ("0"); # show main part only
}
-
+
# If the multipart problem was condensed, "forget" it was multipart
if (scalar(@parts) == 1) {
$args->{'multipart'} = 0;
}
- # In the event of a network error, display one part.
- # If this is a single part, we can at least show the correct
- # status, but if it's multipart, we're lost, since we can't
- # retreive the metadata to count the parts
- if ($curRes->{RESOURCE_ERROR}) {
- @parts = ("0");
- }
-
# Now, we've decided what parts to show. Loop through them and
# show them.
- foreach my $part (@parts) {
+ foreach my $part ('', @parts) {
+ if ($part eq '0') {
+ next;
+ }
$rownum ++;
my $backgroundColor = $backgroundColors[$rownum % scalar(@backgroundColors)];
@@ -1181,13 +1218,13 @@ sub render {
$result .= " \n";
$args->{'isNewBranch'} = 0;
}
-
+
if ($r && $rownum % 20 == 0) {
$r->print($result);
$result = "";
$r->rflush();
}
-
+ } continue {
$curRes = $it->next();
}
@@ -2680,28 +2717,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;
}