--- loncom/interface/lonprintout.pm 2012/12/08 20:10:26 1.625 +++ loncom/interface/lonprintout.pm 2012/12/10 01:09:06 1.626 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.625 2012/12/08 20:10:26 raeburn Exp $ +# $Id: lonprintout.pm,v 1.626 2012/12/10 01:09:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -705,11 +705,14 @@ sub incomplete { # to only those that are in the original set selcted to be printed. # # Parameters: -# $helper - The helper we need $helper->{'VARS'}->{'symb'} -# to construct the navmap and the iteration. -# $seq - The original set of resources to print +# $map - The URL of the folder being printed. +# Used to determine which startResource and finishResource +# to use when using the navmap's getIterator method. +# $seq - The original set of resources to print. # (really an array of resource names (array of symb's). # $who - Student/domain for whome the sequence will be generated. +# $code - CODE being printed when printing Problems/Resources +# from folder for CODEd assignments # # Implicit inputs: # $ @@ -718,34 +721,35 @@ sub incomplete { # print_resources. # sub master_seq_to_person_seq { - my ($helper, $seq, $who, $code) = @_; + my ($map, $seq, $who, $code) = @_; my ($username, $userdomain, $usersection) = split(/:/, $who); - # Toss the sequence up into a hash so that we have O(1) lookup time. # on the items that come out of the user's list of resources. # - + my %seq_hash = map {$_ => 1} @$seq; my @output_seq; - my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, $code); - my $iterator = $navmap->getIterator($navmap->firstResource(), - $navmap->finishResource(), - {}, 1); - my %nonResourceItems = ( - $iterator->BEGIN_MAP => 1, - $iterator->BEGIN_BRANCH => 1, - $iterator->END_BRANCH => 1, - $iterator->END_MAP => 1, - $iterator->FORWARD => 1, - $iterator->BACKWARD => 1 + my ($start,$finish); - ); # These items are not resources but appear in the midst of iteration. + if ($map) { + my $mapres = $navmap->getResourceByUrl($map); + if ($mapres->is_map()) { + $start = $mapres->map_start(); + $finish = $mapres->map_finish(); + } + } + unless ($start && $finish) { + $start = $navmap->firstResource(); + $finish = $navmap->finishResource(); + } + + my $iterator = $navmap->getIterator($start,$finish,{},1); # Iterate on the resource..select the items that are randomly selected # and that are in the seq_has. Presumably the iterator will take care @@ -757,15 +761,14 @@ sub master_seq_to_person_seq { # Only process resources..that are not removed by randomout... # and are selected for printint as well. # - - if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) { - my $symb = $curres->symb(); - if (exists $seq_hash{$symb}) { - push(@output_seq, $symb); + + if (ref($curres) && ! $curres->randomout()) { + my $currsymb = $curres->symb(); + if (exists($seq_hash{$currsymb})) { + push(@output_seq, $currsymb); } } } - return \@output_seq; # for now. @@ -3145,6 +3148,12 @@ ENDPART } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + my $map; + if ($helper->{VARS}->{'symb'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); + } + #loop over students my $flag_latex_header_remove = 'NO'; @@ -3179,7 +3188,8 @@ ENDPART } else { $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); } - my $actual_seq = master_seq_to_person_seq($helper, \@master_seq, $person); + my $actual_seq = master_seq_to_person_seq($map, \@master_seq, + $person); my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, \%moreenv, $actual_seq, @@ -3221,16 +3231,16 @@ ENDPART } } } - my ($randomorder,$randompick); + my ($randomorder,$randompick,$map); if ($helper->{VARS}{'symb'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); my $navmap = Apache::lonnavmaps::navmap->new(); if (defined($navmap)) { - my ($map,$id,$resource) = - &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); if ($map) { - my $res = $navmap->getResourceByUrl($map); - $randomorder = $res->randomorder(); - $randompick = $res->randompick(); + my $mapres = $navmap->getResourceByUrl($map); + $randomorder = $mapres->randomorder(); + $randompick = $mapres->randompick(); } } } @@ -3298,7 +3308,8 @@ ENDPART my $actual_seq = \@master_seq; if ($randomorder) { $env{'form.CODE'} = $moreenv{'CODE'}; - $actual_seq = master_seq_to_person_seq($helper,\@master_seq,undef, + $actual_seq = master_seq_to_person_seq($map, \@master_seq, + undef, $moreenv{'CODE'}); delete($env{'form.CODE'}); }