[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm lonnavmaps.pm lonprintout.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 24 Mar 2004 22:22:05 -0000


This is a MIME encoded message

--albertel1080166925
Content-Type: text/plain

albertel		Wed Mar 24 17:22:05 2004 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm lonnavmaps.pm lonhelper.pm 
  Log:
  - add the ability to have .pages summarized
  - Make it so that you can choose to print a page or not print a page, don't allow people to pick and choose resources gfrom inside of a .page
  - BUG#2851, 
  
  
--albertel1080166925
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040324172205.txt"

Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.286 loncom/interface/lonprintout.pm:1.287
--- loncom/interface/lonprintout.pm:1.286	Tue Mar 23 14:36:51 2004
+++ loncom/interface/lonprintout.pm	Wed Mar 24 17:22:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.286 2004/03/23 19:36:51 albertel Exp $
+# $Id: lonprintout.pm,v 1.287 2004/03/24 22:22:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1415,10 +1415,10 @@
 #    $r->print($helper->{VARS}->{'postdata'});
 
     # Useful filter strings
-    my $isProblem = '$res->is_problem()';
+    my $isProblem = '($res->is_problem()||$res->contains_problem) ';
     $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
-    my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
-    my $isNotMap = '!$res->is_map()';
+    my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence()';
+    my $isNotMap = '!$res->is_sequence()';
     $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
     my $isMap = '$res->is_map()';
     my $symbFilter = '$res->symb()';
@@ -1442,7 +1442,8 @@
         my $helperFragment = <<HELPERFRAGMENT;
   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
-    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
+    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
+              closeallpages="1">
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>
@@ -1452,7 +1453,8 @@
 
   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
     <message>(mark them then click "next" button) <br /></message>
-    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
+    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
+              closeallpages="1">
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>
@@ -1471,11 +1473,11 @@
          &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
-    <resource variable="RESOURCES" multichoice="1"
-	suppressEmptySequences='1' addstatus="1">
+    <resource variable="RESOURCES" toponly='0' multichoice="1"
+	suppressEmptySequences='0' addstatus="1" closeallpages="1">
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblemOrMap;</filterfunc>
-      <choicefunc>return $isProblem;</choicefunc>
+      <choicefunc>return $isNotMap;</choicefunc>
       <valuefunc>return $symbFilter;</valuefunc>
     </resource>
   </state>
@@ -1487,7 +1489,8 @@
 	}
 	my $resource_selector=<<RESOURCE_SELECTOR;
    <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
-    <resource variable="RESOURCES" multichoice="1" addstatus="1">
+    <resource variable="RESOURCES" multichoice="1" addstatus="1" 
+              closeallpages="1">
       <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>
@@ -1511,8 +1514,9 @@
 CHOOSE_STUDENTS
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
   <state name="CHOOSE_ANON1" title="Select Students and Resources">
-    <message><hr width='33%' /><b>How many Anonymous exams to print?</b></message>
+    <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
+    
     <message><hr width='33%' /></message>
     $resource_selector
   </state>
@@ -1527,7 +1531,8 @@
 
 	$resource_selector=<<RESOURCE_SELECTOR;
     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
-    <resource variable="RESOURCES" multichoice="1" addstatus="1">
+    <resource variable="RESOURCES" multichoice="1" addstatus="1" 
+              closeallpages="1">
       <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>
@@ -1605,7 +1610,8 @@
     </state>
   <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
     <message>(mark desired resources then click "next" button) <br /></message>
-    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
+    <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
+              closeallpages="1">
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblem</filterfunc>
       <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.255 loncom/interface/lonnavmaps.pm:1.256
--- loncom/interface/lonnavmaps.pm:1.255	Mon Mar 22 17:17:40 2004
+++ loncom/interface/lonnavmaps.pm	Wed Mar 24 17:22:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.255 2004/03/22 22:17:40 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.256 2004/03/24 22:22:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1119,35 +1119,53 @@
 use Data::Dumper;
 sub render_parts_summary_status {
     my ($resource, $part, $params) = @_;
-    if (!$resource->is_problem()) { return '<td></td>'; }
+    if (!$resource->is_problem() && !$resource->contains_problem) { return '<td></td>'; }
     if ($params->{showParts}) { 
 	return '<td></td>';
     }
 
     my $td = "<td align='right'>\n";
     my $endtd = "</td>\n";
+    my @probs;
 
-    # If there is a single part, just show the simple status
-    if ($resource->singlepart()) {
-	my $status = $resource->simpleStatus(${$resource->parts}[0]);
-	return $td . "<font color='" . $statusColors{$status} . "'>"
-	    . $statusStrings{$status} . "</font>" . $endtd;
-    }
-
-    # Now we can be sure the $part doesn't really matter.
-    my $statusCount = $resource->simpleStatusCount();
-    my @counts;
-    foreach my $status(@statuses) {
-	# decouple display order from the simpleStatusCount order
-	my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
-	if ($statusCount->[$slot]) {
-	    push @counts, "<font color='" . $statusColors{$status} .
-		"'>" . $statusCount->[$slot] . ' '
+    if ($resource->contains_problem) {
+	@probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
+    } else {
+	@probs=($resource);
+    }
+    my $return;
+    my %overallstatus;
+    my $totalParts;
+    foreach my $resource (@probs) {
+	# If there is a single part, just show the simple status
+	if ($resource->singlepart()) {
+	    my $status = $resource->simpleStatus(${$resource->parts}[0]);
+	    $overallstatus{$status}++;
+	    $totalParts++;
+	    next;
+	}
+	# Now we can be sure the $part doesn't really matter.
+	my $statusCount = $resource->simpleStatusCount();
+	my @counts;
+	foreach my $status (@statuses) {
+	    # decouple display order from the simpleStatusCount order
+	    my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
+	    if ($statusCount->[$slot]) {
+		$overallstatus{$status}+=$statusCount->[$slot];
+		$totalParts+=$statusCount->[$slot];
+	    }
+	}
+    }
+    $return.= $td . $totalParts . ' parts: ';
+    foreach my $status (@statuses) {
+	if ($overallstatus{$status}) {
+	    $return.="<font color='" . $statusColors{$status} .
+		"'>" . $overallstatus{$status} . ' '
 		. $statusStrings{$status} . "</font>";
 	}
     }
-
-    return $td . $resource->countParts() . ' parts: ' . join (', ', @counts) . $endtd;
+    $return.= $endtd;
+    return $return;
 }
 
 my @preparedColumns = (\&render_resource, \&render_communication_status,
@@ -1182,6 +1200,7 @@
     my $jump = $args->{'jump'};
     my $here = $args->{'here'};
     my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
+    my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
     my $currentJumpDelta = 2; # change this to change how many resources are displayed
                              # before the current resource when using #current
 
@@ -1290,7 +1309,7 @@
             $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);
         }
     }
-    
+
     # (re-)Locate the jump point, if any
     # Note this does not take filtering or hidden into account... need
     # to be fixed?
@@ -1427,7 +1446,7 @@
     $args->{'here'} = $here;
 
     $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
-    while ($curRes = $it->next()) {
+    while ($curRes = $it->next($closeAllPages)) {
         # Maintain indentation level.
         if ($curRes == $it->BEGIN_MAP() ||
             $curRes == $it->BEGIN_BRANCH() ) {
@@ -2168,7 +2187,7 @@
 parameter will allow you to avoid potentially expensive enumeration of
 all matching resources.
 
-=item * B<hasResources>(map, filterFunc, recursive):
+=item * B<hasResource>(map, filterFunc, recursive):
 
 Convience method for
 
@@ -2547,7 +2566,7 @@
 
 sub next {
     my $self = shift;
-
+    my $closeAllPages=shift;
     if ($self->{FINISHED}) {
 	return END_ITERATOR();
     }
@@ -2561,7 +2580,7 @@
 
     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
         # grab the next from the recursive iterator 
-        my $next = $self->{RECURSIVE_ITERATOR}->next();
+        my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
 
         # is it a begin or end map? If so, update the depth
         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
@@ -2675,7 +2694,7 @@
 
     # That ends the main iterator logic. Now, do we want to recurse
     # down this map (if this resource is a map)?
-    if ($self->{HERE}->is_map() &&
+    if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
         (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
         $self->{RECURSIVE_ITERATOR_FLAG} = 1;
         my $firstResource = $self->{HERE}->map_start();
@@ -2693,7 +2712,7 @@
     my $browsePriv = $self->{HERE}->browsePriv();
     if (!$self->{HERE}->src() || 
         (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
-        return $self->next();
+        return $self->next($closeAllPages);
     }
 
     return $self->{HERE};
@@ -3162,6 +3181,15 @@
 
 =cut
 
+sub hasResource {
+   my $self = shift;
+   return $self->{NAV_MAP}->hasResource(@_);
+}
+
+sub retrieveResources {
+   my $self = shift;
+   return $self->{NAV_MAP}->retrieveResources(@_);
+}
 
 sub is_html {
     my $self=shift;
@@ -3178,7 +3206,15 @@
 sub is_problem {
     my $self=shift;
     my $src = $self->src();
-    return ($src =~ /\.(problem|exam|quiz|assess|survey|form|library)$/);
+    return ($src =~ /\.(problem|exam|quiz|assess|survey|form|library)$/)
+}
+sub contains_problem {
+    my $self=shift;
+    if ($self->is_page()) {
+	my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
+	return $hasProblem;
+    }
+    return 0;
 }
 sub is_sequence {
     my $self=shift;
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.65 loncom/interface/lonhelper.pm:1.66
--- loncom/interface/lonhelper.pm:1.65	Mon Mar  8 12:31:37 2004
+++ loncom/interface/lonhelper.pm	Wed Mar 24 17:22:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.65 2004/03/08 17:31:37 www Exp $
+# $Id: lonhelper.pm,v 1.66 2004/03/24 22:22:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1777,6 +1777,7 @@
     $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'};
     $paramHash->{'toponly'} = $token->[2]{'toponly'};
     $paramHash->{'addstatus'} = $token->[2]{'addstatus'};
+    $paramHash->{'closeallpages'} = $token->[2]{'closeallpages'};
     return '';
 }
 
@@ -1962,6 +1963,7 @@
                                        'showParts' => 0,
                                        'filterFunc' => $filterFunc,
                                        'resource_no_folder_link' => 1,
+				       'closeAllPages' => $self->{'closeallpages'},
                                        'suppressEmptySequences' => $self->{'suppressEmptySequences'},
                                        'iterator_map' => $mapUrl }
                                        );

--albertel1080166925--