--- loncom/interface/lonprintout.pm 2011/06/19 13:34:46 1.593
+++ loncom/interface/lonprintout.pm 2011/09/13 21:43:03 1.596
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.593 2011/06/19 13:34:46 foxr Exp $
+# $Id: lonprintout.pm,v 1.596 2011/09/13 21:43:03 raeburn 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 .= ":";
@@ -2868,17 +2928,24 @@ ENDPART
my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
my @lines = &Apache::grades::get_scantronformat_file();
- my ($code_type,$code_length)=('letter',6);
+ my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10);
foreach my $line (@lines) {
- my ($name,$type,$length) = (split(/:/,$line))[0,2,4];
+ chomp($line);
+ my ($name,$type,$length,$bubbles_per_item) =
+ (split(/:/,$line))[0,2,4,17];
if ($name eq $code_option) {
$code_length=$length;
if ($type eq 'number') { $code_type = 'number'; }
+ chomp($bubbles_per_item);
+ if (($bubbles_per_item ne '') && ($bubbles_per_item > 0)) {
+ $bubbles_per_row = $bubbles_per_item;
+ }
}
}
my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
$moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
$moreenv{'instructor_comments'}='hide';
+ $moreenv{'bubbles_per_row'} = $bubbles_per_row;
my $seed=time+($$<<16)+($$);
my @allcodes;
if ($old_name) {
@@ -3205,7 +3272,7 @@ sub print_resources {
($print_type eq 'incomplete_problems_selpeople_course')) {
$print_incomplete = 1;
}
- if ($person =~ 'anon') {
+ if ($person eq 'anonymous') {
$namepostfix .="Name: ";
$fullname = "CODE - ".$moreenv->{'CODE'};
}
@@ -3355,9 +3422,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;
@@ -3789,7 +3854,7 @@ sub printHelper {
}
push(@{$printChoices},
- [&mt('Selected Incomplete [_1]Problems[_2] from folder [_3]' . $textSuffix,
+ [&mt('Selected [_1]Incomplete Problems[_2] from folder [_3]' . $textSuffix,
'', '',
''. $sequenceTitle . ''),
$printSelector,
@@ -3836,7 +3901,7 @@ sub printHelper {
# BZ 5209 - incomplete problems from entire course:
push(@{$printChoices},
- [&mtn('Selected incomplete Problems from entire course for selected people'),
+ [&mtn('Selected Incomplete Problems from entire course for selected people'),
'incomplete_problems_selpeople_course', 'INCOMPLETE_PROBLEMS_COURSE_RESOURCES']);
my $helperFragment = &create_incomplete_course_helper($helper); # Create needed states.