--- loncom/interface/lonnavmaps.pm 2003/03/25 22:35:58 1.167
+++ loncom/interface/lonnavmaps.pm 2003/08/19 15:29:33 1.222
@@ -1,8 +1,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.222 2003/08/19 15:29:33 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,13 +41,13 @@
# Jeremy Bowers ... lots of days
package Apache::lonnavmaps;
-use vars qw($test @refsToUntie %navmaphash %parmhash);
use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon();
use Apache::lonmenu();
use POSIX qw (floor strftime);
+use Data::Dumper; # for debugging, not always used
# symbolic constants
sub SYMB { return 1; }
@@ -73,7 +72,8 @@ my %statusIconMap =
$resObj->TRIES_LEFT => 'navmap.open.gif',
$resObj->INCORRECT => 'navmap.wrong.gif',
$resObj->OPEN => 'navmap.open.gif',
- $resObj->ATTEMPTED => 'navmap.open.gif' );
+ $resObj->ATTEMPTED => 'navmap.ellipsis.gif',
+ $resObj->ANSWER_SUBMITTED => 'navmap.ellipsis.gif' );
my %iconAltTags =
( 'navmap.correct.gif' => 'Correct',
@@ -92,38 +92,13 @@ my %colormap =
$resObj->TRIES_LEFT => '',
$resObj->INCORRECT => '',
$resObj->OPEN => '',
- $resObj->NOTHING_SET => '' );
+ $resObj->NOTHING_SET => '',
+ $resObj->ATTEMPTED => '',
+ $resObj->ANSWER_SUBMITTED => ''
+ );
# 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,9 +129,7 @@ sub real_handler {
$r->send_http_header;
# Create the nav map
- my $navmap = Apache::lonnavmaps::navmap->new($r,
- $ENV{"request.course.fn"}.".db",
- $ENV{"request.course.fn"}."_parms.db", 1, 1);
+ my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
@@ -186,12 +159,6 @@ sub real_handler {
$r->rflush();
- # Now that we've displayed some stuff to the user, init the navmap
- $navmap->init();
-
- $r->print('
');
- $r->rflush();
-
# Check that it's defined
if (!($navmap->courseMapDefined())) {
$r->print('Coursemap undefined.' .
@@ -199,50 +166,110 @@ 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";
+ # 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()) {
+ $sequenceCount++;
+ $sequenceId = $curRes->map_pc();
+ }
+ }
+
+ if ($sequenceCount == 1) {
+ # The automatic iterator creation in the render call
+ # will pick this up. We know the condition because
+ # the defined($ENV{'form.filter'}) also ensures this
+ # is a fresh call.
+ $ENV{'form.filter'} = "$sequenceId";
+ }
}
- # renderer call
- my $render = render({ 'cols' => [0,1,2,3],
- 'url' => '/adm/navmaps',
- 'suppressNavmap' => 1,
- 'r' => $r});
+ my $jumpToFirstHomework = 0;
+ # Check to see if the student is jumping to next open, do-able problem
+ if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') {
+ $jumpToFirstHomework = 1;
+ # Find the next homework problem that they can do.
+ my $iterator = $navmap->getIterator(undef, undef, undef, 1);
+ my $curRes;
+ my $foundDoableProblem = 0;
+ my $problemRes;
+
+ while (($curRes = $iterator->next()) && !$foundDoableProblem) {
+ if (ref($curRes) && $curRes->is_problem()) {
+ my $status = $curRes->status();
+ if ($curRes->completable()) {
+ $problemRes = $curRes;
+ $foundDoableProblem = 1;
+
+ # Pop open all previous maps
+ my $stack = $iterator->getStack();
+ pop @$stack; # last resource in the stack is the problem
+ # itself, which we don't need in the map stack
+ my @mapPcs = map {$_->map_pc()} @$stack;
+ $ENV{'form.filter'} = join(',', @mapPcs);
- #$navmap->untieHashes();
+ # Mark as both "here" and "jump"
+ $ENV{'form.postsymb'} = $curRes->symb();
+ }
+ }
+ }
- if (tied(%navmaphash)) {
- $r->print("Dang it.");
+ # If we found no problems, print a note to that effect.
+ if (!$foundDoableProblem) {
+ $r->print("All homework assignments have been completed.
");
+ }
} else {
- $r->print("It's out.");
+ $r->print("" .
+ "Go To My First Homework Problem ");
}
- if (tied(%parmhash)) {
- $r->print("Dang it.");
+ my $suppressEmptySequences = 0;
+ my $filterFunc = undef;
+ my $resource_no_folder_link = 0;
+
+ # Display only due homework.
+ my $showOnlyHomework = 0;
+ if ($ENV{QUERY_STRING} eq 'showOnlyHomework') {
+ $showOnlyHomework = 1;
+ $suppressEmptySequences = 1;
+ $filterFunc = sub { my $res = shift;
+ return $res->completable() || $res->is_map();
+ };
+ $r->print("
Uncompleted Homework
"); + $ENV{'form.filter'} = ''; + $ENV{'form.condition'} = 1; + $resource_no_folder_link = 1; } else { - $r->print("It's out."); + $r->print("" . + "Show Only Uncompleted Homework "); + } + + # renderer call + my $renderArgs = { 'cols' => [0,1,2,3], + 'url' => '/adm/navmaps', + 'navmap' => $navmap, + 'suppressNavmap' => 1, + 'suppressEmptySequences' => $suppressEmptySequences, + 'filterFunc' => $filterFunc, + 'resource_no_folder_link' => $resource_no_folder_link, + 'r' => $r}; + my $render = render($renderArgs); + $navmap->untieHashes(); + + # If no resources were printed, print a reassuring message so the + # user knows there was no error. + if ($renderArgs->{'counter'} == 0) { + if ($showOnlyHomework) { + $r->print("All homework is currently completed.
"); + } else { # both jumpToFirstHomework and normal use the same: course must be empty + $r->print("This course is empty.
"); + } } $r->print("