--- loncom/interface/lonprintout.pm 2011/06/19 13:38:44 1.594 +++ loncom/interface/lonprintout.pm 2011/06/22 11:00:47 1.595 @@ -2,7 +2,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.594 2011/06/19 13:38:44 foxr Exp $ +# $Id: lonprintout.pm,v 1.595 2011/06/22 11:00:47 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -444,19 +444,9 @@ RESOURCE_SELECTOR sub incomplete { my ($username, $domain, $map) = @_; - # Manipulate the env so the navmap is made - # in the context of the appropriate user: - my $me = $env{'user.name'}; - my $my_domain = $env{'user.domain'}; - - $env{'user.name'} = $username; - $env{'user.domain'} = $domain; - - my $navmap = Apache::lonnavmaps::navmap->new(); + my $navmap = Apache::lonnavmaps::navmap->new($username, $domain); - $env{'user.name'} = $me; # Restore user/domain context. - $env{'user.domain'} = $my_domain; if (defined($navmap)) { my $res = $navmap->getResourceByUrl($map); @@ -466,6 +456,77 @@ sub incomplete { return 1; } } +# +# When printing for students, the resoures and order of the +# resources may need to be altered if there are folders with +# random selectiopn or random ordering (or both) enabled. +# This sub computes the set of resources to print for a student +# modified both by random ordering and selection and filtered +# 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 +# (really an array of resource names +# $who - Student/domain for whome the sequence will be generated. +# +# Implicit inputs: +# $ +# Returns: +# reference to an array of resources that can be passed to +# print_resources. +# +sub master_seq_to_person_seq { + my ($helper, $seq, $who) = @_; + + + 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); + 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 + + ); # These items are not resources but appear in the midst of iteration. + + # Iterate on the resource..select the items that are randomly selected + # and that are in the seq_has. Presumably the iterator will take care + # of the random ordering part of the deal. + # + my $curres; + while ($curres = $iterator->next()) { + # + # Only process resources..that re not removed by randomout... + # + if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) { + my $symb = $curres->symb(); + if (exists $seq_hash{$symb}) { + push(@output_seq, $symb); + } + } + } + + + return \@output_seq; # for now. + +} + # Fetch the contents of a resource, uninterpreted. # This is used here to fetch a latex file to be included @@ -640,7 +701,6 @@ sub ssi_with_retries { $ssi_last_error_resource = $resource; $ssi_last_error = $response->code . " " . $response->message; $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error"); } return $content; @@ -656,7 +716,6 @@ sub get_student_view_with_retries { $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain; $ssi_last_error = $response->code . " " . $response->message; $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain"); } return $content; @@ -2840,9 +2899,10 @@ ENDPART } else { $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); } + my $actual_seq = master_seq_to_person_seq($helper, \@master_seq, $person); my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, - \%moreenv,\@master_seq, + \%moreenv, $actual_seq, $flag_latex_header_remove, $LaTeXwidth); $resources_printed .= ":"; @@ -3355,9 +3415,7 @@ sub print_resources { # incomplete resources for the person. # - &Apache::lonnet::logthis("Number printed: $actually_printed"); if ($actually_printed == 0) { - &Apache::lonnet::logthis("Remove? $remove_latex_header"); $current_output = &encapsulate_minipage("\\vskip -10mm \nNo incomplete resources\n \\vskip 100 mm { }\n"); if ($remove_latex_header eq "NO") { $current_output = &print_latex_header() . $current_output;