--- loncom/interface/spreadsheet/studentcalc.pm 2004/12/08 00:56:00 1.27
+++ loncom/interface/spreadsheet/studentcalc.pm 2005/05/13 20:30:14 1.31
@@ -1,5 +1,5 @@
#
-# $Id: studentcalc.pm,v 1.27 2004/12/08 00:56:00 albertel Exp $
+# $Id: studentcalc.pm,v 1.31 2005/05/13 20:30:14 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -63,25 +63,26 @@ use Apache::lonlocal;
@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 {
- $current_course = $ENV{'request.course.id'};
+ $current_course = $env{'request.course.id'};
&initialize_sequence_cache();
&load_cached_export_rows();
}
sub ensure_correct_sequence_data {
- if ($current_course ne $ENV{'request.course.id'}) {
+ if ($current_course ne $env{'request.course.id'}) {
&initialize_sequence_cache();
- $current_course = $ENV{'request.course.id'};
+ $current_course = $env{'request.course.id'};
}
return;
}
@@ -90,19 +91,39 @@ sub initialize_sequence_cache {
#
# 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);
+ &get_resources($sequence);
+ }
}
- @Sequences = @{$sequences} if (ref($sequences) eq 'ARRAY');
+}
+
+my %res_memoize;
+sub get_resources {
+ my ($seq) = @_;
+ if (exists($res_memoize{$seq->symb()})) {
+ return @{$res_memoize{$seq->symb()}};
+ }
+ return () if (! defined($navmap) || ! ref($navmap));
+ my @resources = $navmap->retrieveResources($seq,
+ sub { shift->is_problem(); },
+ 0,0,0);
+ $res_memoize{$seq->symb()}=\@resources;
+ return @resources;
}
sub clear_package {
undef(@Sequences);
undef(%Exportrows);
+ undef(%res_memoize);
&Apache::assesscalc::clear_package();
}
@@ -123,8 +144,8 @@ sub get_html_title {
my $self = shift;
my ($name,$desc,$time) = $self->get_title();
my $title = '
'.$name;
- if ($ENV{'user.name'} ne $self->{'name'} &&
- $ENV{'user.domain'} ne $self->{'domain'}) {
+ if ($env{'user.name'} ne $self->{'name'} &&
+ $env{'user.domain'} ne $self->{'domain'}) {
$title .= ' '.&Apache::loncommon::aboutmewrapper
($self->{'name'}.'@'.$self->{'domain'},
$self->{'name'},$self->{'domain'});
@@ -143,9 +164,9 @@ sub parent_link {
sub convenience_links {
my $self = shift;
my ($resource) = @_;
- my $result=&Apache::loncommon::submlink(' ',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
- $result .= &Apache::loncommon::pgrdlink(' ',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
- $result .= &Apache::loncommon::pprmlink(' ',$self->{'name'},$self->{'domain'},$resource->{'symb'},'LONcatInfo');
+ my $result=&Apache::loncommon::submlink(' ',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
+ $result .= &Apache::loncommon::pgrdlink(' ',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
+ $result .= &Apache::loncommon::pprmlink(' ',$self->{'name'},$self->{'domain'},$resource->symb,'LONcatInfo');
return $result;
}
@@ -159,7 +180,7 @@ sub outsheet_html {
####################################
my @AssessFileNames = $self->othersheets('assesscalc');
my $editing_is_allowed = &Apache::lonnet::allowed('mgr',
- $ENV{'request.course.id'});
+ $env{'request.course.id'});
####################################
# Report any calculation errors #
####################################
@@ -207,7 +228,7 @@ END
$r->print($tableheader);
#
# Print out template row
- if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) {
+ if (exists($env{'request.role.adv'}) && $env{'request.role.adv'}) {
$r->print('Template '.
$self->html_template_row($num_uneditable,
$importcolor)." \n");
@@ -220,7 +241,7 @@ END
$r->print("\n");
#
# Prepare to output rows
- if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) {
+ if (exists($env{'request.role.adv'}) && $env{'request.role.adv'}) {
$tableheader =<<"END";
@@ -248,12 +269,10 @@ END
&initialize_sequence_cache();
}
foreach my $Sequence (@Sequences) {
- next if ($Sequence->{'num_assess'} < 1);
- $r->print("".$Sequence->{'title'}." \n");
+ $r->print("".$Sequence->compTitle." \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 = '';
if ($editing_is_allowed) {
@@ -263,17 +282,17 @@ END
''.$resource->{'title'}.' ';
+ '&usymb='.&Apache::lonnet::escape($resource->symb).
+ '">'.$resource->compTitle.' ';
$row_output .= &assess_file_selector($rownum,
$assess_filename,
\@AssessFileNames).
'';
} else {
- $row_output .= 'src.'?symb='.
+ &Apache::lonnet::escape($resource->symb).
'">Go To ';
- $row_output .= ''.$resource->{'title'}.' ';
+ $row_output .= ''.$resource->compTitle.' ';
}
if ($self->blackout() && $self->{'blackout_rows'}->{$rownum}>0) {
$row_output .=
@@ -307,7 +326,7 @@ sub assess_file_selector {
if (!defined($AssessFiles) || ! @$AssessFiles) {
return '';
}
- return '' if (! &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}));
+ return '' if (! &Apache::lonnet::allowed('mgr',$env{'request.course.id'}));
my $element_name = 'FileSelect_'.$row;
my $load_dialog = '{'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);
}
}
@@ -376,12 +394,12 @@ sub excel_rows {
# writes the meat of the spreadsheet to an excel worksheet. Called
# by Spreadsheet::outsheet_excel;
my $self = shift;
- my ($connection,$worksheet,$cols_output,$rows_output) = @_;
+ my ($connection,$worksheet,$cols_output,$rows_output,$format) = @_;
#
# Write a header row
$cols_output = 0;
foreach my $value ('Container','Assessment title') {
- $worksheet->write($rows_output,$cols_output++,&mt($value));
+ $worksheet->write($rows_output,$cols_output++,&mt($value),$format->{'h4'});
}
$rows_output++;
#
@@ -390,11 +408,10 @@ sub excel_rows {
&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 +431,10 @@ sub get_rows_in_sequence {
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;
}
@@ -490,25 +506,24 @@ sub compute {
my $connection = $r->connection();
if ($connection->aborted()) { $self->cleanup; return; }
if (! defined($current_course) ||
- $current_course ne $ENV{'request.course.id'} ||
+ $current_course ne $env{'request.course.id'} ||
! @Sequences ) {
- $current_course = $ENV{'request.course.id'};
+ $current_course = $env{'request.course.id'};
&clear_package();
&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 +531,13 @@ sub compute {
} 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()) {
@@ -624,12 +639,12 @@ These rows are saved in the courses dire
sub load_cached_export_rows {
undef(%Exportrows);
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'},undef);
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},undef);
my %Selected_Assess_Sheet;
if ($tmp[0] =~ /^error/) {
&Apache::lonnet::logthis('unable to read cached student export rows '.
- 'for course '.$ENV{'request.course.id'});
+ 'for course '.$env{'request.course.id'});
return;
}
my %tmp = @tmp;