--- loncom/interface/lonnavmaps.pm 2003/03/21 22:41:12 1.165
+++ loncom/interface/lonnavmaps.pm 2003/05/14 18:34:44 1.189
@@ -1,8 +1,7 @@
-
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.165 2003/03/21 22:41:12 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.189 2003/05/14 18:34:44 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,7 +41,6 @@
# Jeremy Bowers ... lots of days
package Apache::lonnavmaps;
-use vars qw($test @refsToUntie);
use strict;
use Apache::Constants qw(:common :http);
@@ -50,10 +48,6 @@ use Apache::loncommon();
use Apache::lonmenu();
use POSIX qw (floor strftime);
-my %navmaphash;
-my %parmhash;
-@refsToUntie;
-
# symbolic constants
sub SYMB { return 1; }
sub URL { return 2; }
@@ -77,7 +71,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.open.gif',
+ $resObj->ANSWER_SUBMITTED => '' );
my %iconAltTags =
( 'navmap.correct.gif' => 'Correct',
@@ -100,33 +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');
- }
- }
-}
sub handler {
my $r = shift;
@@ -157,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);
@@ -202,51 +170,90 @@ 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();
+ # See if there's only one map in the top-level, if we don't
+ # already have a filter... if so, automatically display it
+ if ($ENV{QUERY_STRING} !~ /filter/) {
+ 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. We know the condition because
+ # the defined($ENV{'form.filter'}) also ensures this
+ # is a fresh call.
+ $ENV{'form.filter'} = "$sequenceId";
}
-
- $curRes = $iterator->next();
}
- if ($sequenceCount == 1) {
- # The automatic iterator creation in the render call
- # will pick this up.
- $ENV{'form.filter'} = "$sequenceId";
+ # Check to see if the student is jumping to next open, do-able problem
+ if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') {
+ # Find the next homework problem that they can do.
+ my $iterator = $navmap->getIterator(undef, undef, undef, 1);
+ my $depth = 1;
+ $iterator->next();
+ my $curRes = $iterator->next();
+ my $foundDoableProblem = 0;
+ my $problemRes;
+
+ while ($depth > 0 && !$foundDoableProblem) {
+ if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
+ if ($curRes == $iterator->END_MAP()) { $depth--; }
+
+ if (ref($curRes) && $curRes->is_problem()) {
+ my $status = $curRes->status();
+ if (($status == $curRes->OPEN ||
+ $status == $curRes->TRIES_LEFT()) &&
+ $curRes->getCompletionStatus() != $curRes->ATTEMPTED()) {
+ $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);
+
+ # Mark as both "here" and "jump"
+ $ENV{'form.postsymb'} = $curRes->symb();
+ }
+ }
+ } continue {
+ $curRes = $iterator->next();
+ }
+
+ # If we found no problems, print a note to that effect.
+ if (!$foundDoableProblem) {
+ $r->print("All homework assignments have been completed.
");
+ }
+ } else {
+ $r->print("" .
+ "Go To My First Homework Problem
");
}
# 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("