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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 03 Mar 2005 17:52:36 -0000


This is a MIME encoded message

--matthew1109872356
Content-Type: text/plain

matthew		Thu Mar  3 12:52:36 2005 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm assesscalc.pm 
                                 	studentcalc.pm 
  Log:
  Changed to use navmaps.
  
  
--matthew1109872356
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20050303125236.txt"

Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.38 loncom/interface/spreadsheet/Spreadsheet.pm:1.39
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.38	Thu Feb  3 18:59:41 2005
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Thu Mar  3 12:52:36 2005
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.38 2005/02/03 23:59:41 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.39 2005/03/03 17:52:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,6 +86,9 @@
     my ($stype) = ($class =~ /Apache::(.*)$/);
     #
     my ($name,$domain,$filename,$usymb)=@_;
+    if (defined($usymb) && ref($usymb)) {
+        $usymb = $usymb->symb;
+    }
     if (! defined($name) || $name eq '') {
         $name = $ENV{'user.name'};
     }
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.36 loncom/interface/spreadsheet/assesscalc.pm:1.37
--- loncom/interface/spreadsheet/assesscalc.pm:1.36	Sat Feb  5 01:56:24 2005
+++ loncom/interface/spreadsheet/assesscalc.pm	Thu Mar  3 12:52:36 2005
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.36 2005/02/05 06:56:24 albertel Exp $
+# $Id: assesscalc.pm,v 1.37 2005/03/03 17:52:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -104,6 +104,7 @@
 my %useropt;
 my %userdata;
 my %courseopt;
+my $navmap;
 
 ########################################################
 ########################################################
@@ -136,11 +137,11 @@
     undef(%useropt);
     undef(%userdata);
     undef(%courseopt);
+    undef($navmap);
 }
 
 sub save_cached_export_rows {
     my ($sname,$sdomain) = @_;
-    my $start = Time::HiRes::time;
     my $result = &Apache::lonnet::put
         ('nohist_calculatedsheets_'.$ENV{'request.course.id'},
          $newExportrows{$sname.':'.$sdomain},
@@ -149,7 +150,15 @@
 }
 
 sub initialize {
+    my ($in_navmap) = @_;
     &clear_package();
+    $navmap = $in_navmap;
+    if (! defined($navmap)) {
+        $navmap = Apache::lonnavmaps::navmap->new();
+    }
+    if (!defined($navmap)) {
+        &Apache::lonnet::logthis('assesscalc:Can not open Coursemap');
+    }
     &Apache::loncoursedata::clear_internal_caches();
 }
 
@@ -165,9 +174,10 @@
 ########################################################
 ########################################################
 sub initialize_package {
-    my ($sname,$sdomain) = @_;
+    my ($sname,$sdomain,$in_navmap) = @_;
     $current_name   = $sname;
     $current_domain = $sdomain;
+    $navmap = $in_navmap;
     undef(%useropt);
     undef(%userdata);
     if ($current_course ne $ENV{'request.course.id'}) {
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.27 loncom/interface/spreadsheet/studentcalc.pm:1.28
--- loncom/interface/spreadsheet/studentcalc.pm:1.27	Tue Dec  7 19:56:00 2004
+++ loncom/interface/spreadsheet/studentcalc.pm	Thu Mar  3 12:52:36 2005
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.27 2004/12/08 00:56:00 albertel Exp $
+# $Id: studentcalc.pm,v 1.28 2005/03/03 17:52:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -63,13 +63,14 @@
 @Apache::studentcalc::ISA = ('Apache::Spreadsheet');
 
 my @Sequences = ();
+my $navmap;
 my %Exportrows = ();
 
 my $current_course;
 
 sub initialize {
-    &Apache::assesscalc::initialize();
     &initialize_sequence_cache();
+    &Apache::assesscalc::initialize($navmap);
 }
 
 sub initialize_package {
@@ -90,14 +91,27 @@
     #
     # Set up the sequences and assessments
     undef(@Sequences);
-    my ($top,$sequences,$assessments) = 
-        &Apache::loncoursedata::get_sequence_assessment_data();
-    if (! defined($top) || ! ref($top)) {
-        # There has been an error, better report it
-        &Apache::lonnet::logthis('top is undefined (studentcalc.pm)');
-        return;
+    undef($navmap);
+    $navmap = Apache::lonnavmaps::navmap->new();
+    if (!defined($navmap)) {
+        &Apache::lonnet::logthis('student spreadsheet:Can not open Coursemap');
+    }
+    my @all_sequences = $navmap->retrieveResources(undef,
+                                               sub { shift->is_map(); },1,0,1);
+    for my $sequence ($navmap->getById('0.0'), @all_sequences) {
+	if ($navmap->hasResource($sequence,sub { shift->is_problem(); }, 0)){
+            push(@Sequences,$sequence);
+        }
     }
-    @Sequences = @{$sequences} if (ref($sequences) eq 'ARRAY');
+}
+
+sub get_resources {
+    my ($seq) = @_;
+    return () if (! defined($navmap) || ! ref($navmap));
+    my @resources = $navmap->retrieveResources($seq,
+                                               sub { shift->is_problem(); },
+                                               0,0,0);
+    return @resources;
 }
 
 sub clear_package {
@@ -143,9 +157,9 @@
 sub convenience_links {
     my $self = shift;
     my ($resource) = @_;
-    my $result=&Apache::loncommon::submlink('<img src="/adm/lonMisc/subm_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
-    $result .= &Apache::loncommon::pgrdlink('<img src="/adm/lonMisc/pgrd_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
-    $result .= &Apache::loncommon::pprmlink('<img src="/adm/lonMisc/pprm_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
+    my $result=&Apache::loncommon::submlink('<img src="/adm/lonMisc/subm_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
+    $result .= &Apache::loncommon::pgrdlink('<img src="/adm/lonMisc/pgrd_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
+    $result .= &Apache::loncommon::pprmlink('<img src="/adm/lonMisc/pprm_button.gif" border="0" />',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
     return $result;
 }
 
@@ -248,12 +262,10 @@
         &initialize_sequence_cache();
     }
     foreach my $Sequence (@Sequences) {
-	next if ($Sequence->{'num_assess'} < 1);
-	$r->print("<h3>".$Sequence->{'title'}."</h3>\n");
+	$r->print("<h3>".$Sequence->compTitle."</h3>\n");
  	$r->print($tableheader);
-	foreach my $resource (@{$Sequence->{'contents'}}) {
-	    next if ($resource->{'type'} ne 'assessment');
-	    my $rownum = $self->get_row_number_from_key($resource->{'symb'});
+	foreach my $resource (&get_resources($Sequence)) {
+	    my $rownum = $self->get_row_number_from_key($resource->symb);
             my $assess_filename = $self->{'row_source'}->{$rownum};
             my $row_output = '<tr>';
             if ($editing_is_allowed) {
@@ -263,17 +275,17 @@
                     '<a href="/adm/assesscalc?sname='.$self->{'name'}.
                     '&sdomain='.$self->{'domain'}.
                     '&filename='.$assess_filename.
-                    '&usymb='.&Apache::lonnet::escape($resource->{'symb'}).
-                    '">'.$resource->{'title'}.'</a><br />';
+                    '&usymb='.&Apache::lonnet::escape($resource->symb).
+                    '">'.$resource->compTitle.'</a><br />';
                 $row_output .= &assess_file_selector($rownum,
                                                      $assess_filename,
                                                      \@AssessFileNames).
                                                          '</td>';
             } else {
-                $row_output .= '<td><a href="'.$resource->{'src'}.'?symb='.
-                    &Apache::lonnet::escape($resource->{'symb'}).
+                $row_output .= '<td><a href="'.$resource->src.'?symb='.
+                    &Apache::lonnet::escape($resource->symb).
                     '">Go&nbsp;To</a>';
-                $row_output .= '</td><td>'.$resource->{'title'}.'</td>';
+                $row_output .= '</td><td>'.$resource->compTitle.'</td>';
             }
             if ($self->blackout() && $self->{'blackout_rows'}->{$rownum}>0) {
                 $row_output .= 
@@ -361,11 +373,10 @@
         &initialize_sequence_cache();
     }
     foreach my $Sequence (@Sequences) {
-	next if ($Sequence->{'num_assess'} < 1);
-	foreach my $resource (@{$Sequence->{'contents'}}) {
-	    my $rownum = $self->get_row_number_from_key($resource->{'symb'});
-            my @assessdata = ($Sequence->{'title'},
-                              $resource->{'title'});
+	foreach my $resource (&get_resources($Sequence)) {
+	    my $rownum = $self->get_row_number_from_key($resource->symb);
+            my @assessdata = ($Sequence->compTitle,
+                              $resource->compTitle);
             $self->csv_output_row($filehandle,$rownum,@assessdata);
         }
     }
@@ -390,11 +401,10 @@
         &initialize_sequence_cache();
     }
     foreach my $Sequence (@Sequences) {
-	next if ($Sequence->{'num_assess'} < 1);
-	foreach my $resource (@{$Sequence->{'contents'}}) {
-	    my $rownum = $self->get_row_number_from_key($resource->{'symb'});
-            my @assessdata = ($Sequence->{'title'},
-                              $resource->{'title'});
+	foreach my $resource (&get_resources($Sequence)) {
+	    my $rownum = $self->get_row_number_from_key($resource->symb);
+            my @assessdata = ($Sequence->compTitle,
+                              $resource->compTitle);
             $self->excel_output_row($worksheet,$rownum,$rows_output++,
                                     @assessdata);
         }
@@ -414,11 +424,10 @@
     my $self = shift();
     my ($sequence) = @_;
     my @Rows;
-    foreach my $resource (@{$sequence->{'contents'}}) {
-        if ($resource->{'type'} eq 'assessment') {
-            my $rownum = $self->get_row_number_from_key($resource->{'symb'});
-            push (@Rows,$rownum);
-        }
+    my @resources = &get_resources($sequence);
+    foreach my $resource (@resources) {
+        my $rownum = $self->get_row_number_from_key($resource->symb);
+        push (@Rows,$rownum);
     }
     return @Rows;
 }
@@ -497,18 +506,17 @@
         &initialize_sequence_cache();
     }
     $self->initialize_safe_space();
-    &Apache::assesscalc::initialize_package($self->{'name'},$self->{'domain'});
+    &Apache::assesscalc::initialize_package($self->{'name'},$self->{'domain'},
+                                            $navmap);
     my %f = $self->formulas();
     #
     # Process the formulas list - 
     #   the formula for the A column of a row is symb__&&__filename
     my %c = $self->constants();
     foreach my $seq (@Sequences) {
-        next if ($seq->{'num_assess'}<1);
-        foreach my $resource (@{$seq->{'contents'}}) {
+        foreach my $resource (&get_resources($seq)) {
             if ($connection->aborted()) { $self->cleanup(); return; }
-            next if ($resource->{'type'} ne 'assessment');
-            my $rownum = $self->get_row_number_from_key($resource->{'symb'});
+            my $rownum = $self->get_row_number_from_key($resource->symb);
             my $cell = 'A'.$rownum;
             my $assess_filename = 'Default';
             if (exists($self->{'row_source'}->{$rownum})) {
@@ -516,13 +524,13 @@
             } else {
                 $self->{'row_source'}->{$rownum} = $assess_filename;
             }
-            $f{$cell} = $resource->{'symb'}.'__&&&__'.$assess_filename;
+            $f{$cell} = $resource->symb.'__&&&__'.$assess_filename;
             if ($connection->aborted()) { $self->cleanup(); return; }
             my $assessSheet;
                 $assessSheet = Apache::assesscalc->new($self->{'name'},
                                                        $self->{'domain'},
                                                        $assess_filename,
-                                                       $resource->{'symb'});
+                                                       $resource->symb);
             my @exportdata = $assessSheet->export_data($r);
             #
             if ($assessSheet->badcalc()) {

--matthew1109872356--