[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet assesscalc.pm

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 11 Nov 2003 15:36:28 -0000


matthew		Tue Nov 11 10:36:28 2003 EDT

  Modified files:              
    /loncom/interface/spreadsheet	assesscalc.pm 
  Log:
  Fix bug 55: Hide part information from spreadsheet for hidden parts.
  
  
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.27 loncom/interface/spreadsheet/assesscalc.pm:1.28
--- loncom/interface/spreadsheet/assesscalc.pm:1.27	Mon Nov 10 10:09:13 2003
+++ loncom/interface/spreadsheet/assesscalc.pm	Tue Nov 11 10:36:28 2003
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.27 2003/11/10 15:09:13 matthew Exp $
+# $Id: assesscalc.pm,v 1.28 2003/11/11 15:36:28 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -474,6 +474,11 @@
     #
     my $num_output = 0;
     foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
+        if (! $self->parameter_part_is_valid(
+                                             $self->{'formulas'}->{'A'.$rownum}
+                                             )) {
+            next;
+        }
 	if ($num_output++ % 50 == 0) {
 	    $r->print("</table>\n".$tableheader);
 	}
@@ -637,6 +642,52 @@
     return %student_parameters;
 }
 
+sub determine_parts {
+    my $self = shift;
+    if (exists($self->{'Parts'}) && ref($self->{'Parts'}) eq 'HASH') {
+        return;
+    }
+    my (undef,undef,$url) = &Apache::lonnet::decode_symb($self->{'symb'});
+    my $src = &Apache::lonnet::clutter($url);
+    return if (! defined($src));
+    my %Parts;
+    my $metadata = &Apache::lonnet::metadata($src,'packages');
+    foreach (split(',',$metadata)) {
+        my ($part) = (/^part_(.*)$/);
+        if (defined($part) && 
+            ! &Apache::loncommon::check_if_partid_hidden
+                ($part,$self->{'symb'},$self->{'name'},$self->{'domain'})
+            ) {
+            $Parts{$part}++;
+        }
+    }
+    # Make sure part 0 is defined.
+    $Parts{'0'}++;
+    $self->{'Parts'} = \%Parts;
+    return;
+}
+
+sub parameter_part_is_valid {
+    my $self = shift;
+    my ($parameter) = @_;
+    return 1 if ($parameter eq 'timestamp');
+    if (! defined($self->{'Parts'}) || 
+        ! ref ($self->{'Parts'})    ||
+        ref($self->{'Parts'}) ne 'HASH') {
+        return 1;
+    }
+    #
+    my (undef,$part) = 
+        ($parameter =~ m/^(resource|stores|parameter)_([^_]+)_.*/);
+    if (exists($self->{'Parts'})          && 
+        exists($self->{'Parts'}->{$part}) &&
+        $self->{'Parts'}->{$part} ) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
 sub compute {
     my $self = shift;
     my ($r) = @_;
@@ -686,6 +737,14 @@
         $parm =~ s/^resource\./stores_/;
         $parm =~ s/\./_/g;
         $parameters{$parm} = $value;
+    }
+    #
+    # Clean out any bad parameters
+    $self->determine_parts();
+    foreach my $param (keys(%parameters)) {
+        if (! $self->parameter_part_is_valid($param)) {
+            delete ($parameters{$param});
+        }
     }
     #
     # Set up the formulas and parameter values