[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm
foxr
foxr@source.lon-capa.org
Tue, 14 Jun 2011 10:22:40 -0000
foxr Tue Jun 14 10:22:40 2011 EDT
Modified files:
/loncom/interface lonprintout.pm
Log:
BZ5209 - Probably mostly works... needs more testing with
diverse cases.
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.590 loncom/interface/lonprintout.pm:1.591
--- loncom/interface/lonprintout.pm:1.590 Mon Jun 6 10:53:09 2011
+++ loncom/interface/lonprintout.pm Tue Jun 14 10:22:39 2011
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.590 2011/06/06 10:53:09 foxr Exp $
+# $Id: lonprintout.pm,v 1.591 2011/06/14 10:22:39 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -432,6 +432,40 @@
#-----------------------------------------------------------------------
+# Determine if a resource is incomplete given the map:
+# Parameters:
+# $username - Name of user for whom we are checking.
+# $domain - Domain of user we are checking.
+# $map - map name.
+# Returns:
+# 0 - map is not incomplete.
+# 1 - map is incomplete.
+#
+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();
+
+ $env{'user.name'} = $me; # Restore user/domain context.
+ $env{'user.domain'} = $my_domain;
+
+ if (defined($navmap)) {
+ my $res = $navmap->getResourceByUrl($map);
+ my $result = $res->is_incomplete();
+ return $result;
+ } else {
+ return 1;
+ }
+}
# Fetch the contents of a resource, uninterpreted.
# This is used here to fetch a latex file to be included
@@ -2222,13 +2256,12 @@
#BZ 5209
# 2 map_incomplete_problems_seq Print incomplete problems from the current
# folder in student context.
-# 101 map_incomplete_problems_people_seq Print incomplete problems from the
+# 5 map_incomplete_problems_people_seq Print incomplete problems from the
# current folder in privileged context.
-# 102 incomplete_problems_selpeople_course Print incomplete problems for
+# 5 incomplete_problems_selpeople_course Print incomplete problems for
# selected people from the entire course.
#
# Item 101 has much the same processing as 8,
-# Item 102 has much the same processing as 8.
#
# Differences: Item 101, 102 require per-student filtering of the resource
# set so that only the incomplete resources are printed.
@@ -2724,14 +2757,18 @@
} elsif (($print_type eq 'problems_for_students') ||
($print_type eq 'problems_for_students_from_page') ||
($print_type eq 'all_problems_students') ||
- ($print_type eq 'resources_for_students')){
+ ($print_type eq 'resources_for_students') ||
+ ($print_type eq 'incomplete_problems_selpeople_course') ||
+ ($print_type eq 'map_incomplete_problems_people_seq')){
#-- prints assignments for whole class or for selected students
my $type;
if (($print_type eq 'problems_for_students') ||
($print_type eq 'problems_for_students_from_page') ||
- ($print_type eq 'all_problems_students') ) {
+ ($print_type eq 'all_problems_students') ||
+ ($print_type eq 'incomplete_problems_selpeople_course') ||
+ ($print_type eq 'map_incomplete_problems_people_seq')) {
$selectionmade=5;
$type='problems';
} elsif ($print_type eq 'resources_for_students') {
@@ -2788,7 +2825,6 @@
my $i = 0;
my $last_section = (split(/:/,$students[0]))[2];
foreach my $person (@students) {
-
my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
if (-e $duefile) {
my $temp_file = Apache::File->new('>>'.$duefile);
@@ -3159,6 +3195,16 @@
my ($username,$userdomain,$usersection) = split /:/,$person;
my $fullname = &get_name($username,$userdomain);
my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.
+ #
+ # Figure out if we need to filter the output by
+ # the incomplete problems for that person
+ #
+ my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'};
+ my $print_incomplete = 0;
+ if (($print_type eq 'map_incomplete_problems_people_seq') ||
+ ($print_type eq 'incomplete_problems_selpeople_course')) {
+ $print_incomplete = 1;
+ }
if ($person =~ 'anon') {
$namepostfix .="Name: ";
$fullname = "CODE - ".$moreenv->{'CODE'};
@@ -3168,6 +3214,7 @@
#
my $i = 0;
+ my $actually_printed = 0; # Count of resources printed.
#goes through all resources, checks if they are available for
#current student, and produces output
@@ -3184,6 +3231,7 @@
# so we will just rely on prntout.pl to strip ENDOFSTUDENTSTAMP from the
# postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself.
#
+
my $syllabus_first = 0;
foreach my $curresline (@{$master_seq}) {
if (defined $page_breaks{$curresline}) {
@@ -3196,6 +3244,10 @@
if ( !($type eq 'problems' &&
($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) ) {
my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
+ if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) {
+ next;
+ }
+ $actually_printed++; # we're going to print one.
if (&Apache::lonnet::allowed('bre',$res_url)) {
if ($res_url!~m|^ext/|
&& $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
@@ -3209,6 +3261,7 @@
$rendered = &print_latex_header().$rendered;
}
}
+;
if ($remove_latex_header eq 'YES') {
$rendered = &latex_header_footer_remove($rendered);
} else {
@@ -3220,6 +3273,8 @@
# Use a copy of the hash so we don't pervert it on future loop passes.
my %answerenv = %{$moreenv};
$answerenv{'answer_output_mode'}='tex';
+
+
$answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
&Apache::lonxml::restore_problem_counter();
@@ -3294,6 +3349,17 @@
}
if (&Apache::loncommon::connection_aborted($r)) { last; }
}
+ # If we are printing incomplete it's possible we don't have
+ # anything to print. The print subsystem is not so good at handling
+ # that so we're going to generate a stub that says there are no
+ # incomplete resources for the person.
+ #
+ if ($actually_printed == 0) {
+
+ $current_output = 'No incomplete resources';
+ $current_output .= '\end{document}';
+ $current_output = &print_latex_header() . $current_output;
+ }
if ($syllabus_first) {
$current_output =~ s/\\\\ Last updated:/Last updated:/
@@ -3838,7 +3904,7 @@
}
my $randomly_ordered_warning =
- &get_randomly_ordered_warning($helper,$map);
+ &get_randomly_ordered_warning($helper, $map);
# resource_selector will hold a few states that:
# - Allow resources to be selected for printing.