[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm
foxr
foxr@source.lon-capa.org
Wed, 22 Jun 2011 11:00:47 -0000
foxr Wed Jun 22 11:00:47 2011 EDT
Modified files:
/loncom/interface lonprintout.pm
Log:
BZ 6454 - first shot at handling randompick though I don't see the random
order working yet.
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.594 loncom/interface/lonprintout.pm:1.595
--- loncom/interface/lonprintout.pm:1.594 Sun Jun 19 13:38:44 2011
+++ loncom/interface/lonprintout.pm Wed Jun 22 11:00:47 2011
@@ -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 @@
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 @@
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 @@
$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 @@
$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 @@
} 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 @@
# 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;