--- loncom/interface/lonnavdisplay.pm 2011/12/25 20:41:53 1.20 +++ loncom/interface/lonnavdisplay.pm 2011/12/28 04:11:05 1.21 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavdisplay.pm,v 1.20 2011/12/25 20:41:53 raeburn Exp $ +# $Id: lonnavdisplay.pm,v 1.21 2011/12/28 04:11:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -113,21 +113,31 @@ sub real_handler { return OK; } - # See if there's only one map in the top-level, if we don't - # already have a filter... if so, automatically display it - # (older code; should use retrieveResources) - if ($ENV{QUERY_STRING} !~ /filter/) { - my $iterator = $navmap->getIterator(undef, undef, undef, 0); - my $curRes; - my $sequenceCount = 0; - my $sequenceId; - while ($curRes = $iterator->next()) { - if (ref($curRes) && $curRes->is_sequence()) { + my @resources = $navmap->retrieveResources(); + my $sequenceCount = 0; + my $problemCount = 0; + my $notaprobCount = 0; + my $sequenceId; + my $notools; + foreach my $curRes (@resources) { + if (ref($curRes)) { + if ($curRes->is_sequence()) { $sequenceCount++; $sequenceId = $curRes->map_pc(); + } elsif ($curRes->is_problem()) { + $problemCount ++; + } else { + $notaprobCount ++; } } - + } + if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) { + $notools = 1; + } + + # If there's only one map in the top-level and we don't + # already have a filter, automatically display it + if ($ENV{QUERY_STRING} !~ /filter/) { if ($sequenceCount == 1) { # The automatic iterator creation in the render call # will pick this up. We know the condition because @@ -183,9 +193,11 @@ sub real_handler { if ($env{'form.register'}) { $link .= '&register='.$env{'form.register'}; } - &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework', - 'location.href="'.$link.'"', - "Show my first due problem"); + unless ($notools) { + &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework', + 'location.href="'.$link.'"', + "Show my first due problem"); + } } my $suppressEmptySequences = 0; @@ -216,13 +228,18 @@ sub real_handler { if ($env{'form.register'}) { $link .= '&register='.$env{'form.register'}; } - &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted', - 'location.href="'.$link.'"', - 'Show only uncompleted problems'); + unless ($notools) { + &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted', + 'location.href="'.$link.'"', + 'Show only uncompleted problems'); + } } my %selected=($env{'form.sort'} => ' selected="selected"'); - my $sort_html=('
+ my $sort_html; + unless ($notools) { + $sort_html=( + ' '.&mt('Sort by:').' @@ -235,6 +252,7 @@ sub real_handler {
'); + } # renderer call my $renderArgs = { 'cols' => [0,1,2,3], 'sort' => $env{'form.sort'}, @@ -247,7 +265,9 @@ sub real_handler { 'sort_html'=> $sort_html, 'r' => $r, 'caller' => 'navmapsdisplay', - 'linkitems' => \%toplinkitems}; + 'linkitems' => \%toplinkitems, + 'notools' => $notools}; + my $render = &Apache::lonnavmaps::render($renderArgs); # If no resources were printed, print a reassuring message so the