--- loncom/interface/spreadsheet/studentcalc.pm 2003/05/22 21:16:35 1.4 +++ loncom/interface/spreadsheet/studentcalc.pm 2003/07/16 20:30:36 1.15 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.4 2003/05/22 21:16:35 matthew Exp $ +# $Id: studentcalc.pm,v 1.15 2003/07/16 20:30:36 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,12 +64,25 @@ my %Exportrows = (); my $current_course; +sub initialize { + &Apache::assesscalc::initialize(); + &initialize_sequence_cache(); +} + sub initialize_package { $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'}) { + &initialize_sequence_cache(); + $current_course = $ENV{'request.course.id'}; + } + return; +} + sub initialize_sequence_cache { # # Set up the sequences and assessments @@ -91,14 +104,25 @@ sub clear_package { sub get_title { my $self = shift; - my $title = ''; + my @title = (); + # + # Determine the students name my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'}, $self->{'domain'}); - &Apache::lonnet::logthis('userenv = '.join(' ',%userenv)); - my $name = - join(' ',@userenv{'firstname','middlename','lastname','generation'}); + my $name = join(' ', + @userenv{'firstname','middlename','lastname','generation'}); $name =~ s/\s+$//; - $title .= '

'.$name; + + push (@title,$name); + push (@title,$self->{'coursedesc'}); + push (@title,scalar(localtime(time))); + return @title; +} + +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'}) { $title .= &Apache::loncommon::aboutmewrapper @@ -106,8 +130,8 @@ sub get_title { $self->{'name'},$self->{'domain'}); } $title .= "

\n"; - $title .= '

'.$self->{'coursedesc'}."

\n"; - $title .= '

'.localtime(time).'

'; + $title .= '

'.$desc."

\n"; + $title .= '

'.$time.'

'; return $title; } @@ -120,9 +144,29 @@ sub parent_link { return $link; } +sub convenience_links { + my $self = shift; + my ($resource) = @_; + my $symb = &Apache::lonnet::escape($resource->{'symb'}); + my $result = <<"END"; + + + + + + + + + +END + return $result; +} + sub outsheet_html { my $self = shift; my ($r) = @_; + my $importcolor = '#FFFFAA'; + my $exportcolor = '#88FF88'; #################################### # Get the list of assessment files # #################################### @@ -139,7 +183,7 @@ sub outsheet_html { - @@ -148,7 +192,7 @@ END my $label_num = 0; foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader .=''. - $self->html_template_row($num_uneditable)."\n"); + $self->html_template_row($num_uneditable, + $importcolor)."\n"); } # # Print out summary/export row $r->print(''. - $self->html_export_row()."\n"); + $self->html_export_row($exportcolor)."\n"); } $r->print("
Student + Import Calculations'; + $tableheader .=''; } else { $tableheader .=''; } @@ -167,12 +211,13 @@ END # Print out template row if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { $r->print('
Template 
Summary0
\n"); # @@ -181,7 +226,7 @@ END $tableheader =<<"END";

- + END } else { $tableheader =<<"END"; @@ -215,6 +260,7 @@ END my $row_output = ''; if ($editing_is_allowed) { $row_output .= ''; + $row_output .= ''; $row_output .= ''."\n"; } else { - $row_output .= $self->html_row($num_uneditable,$rownum). + $row_output .= $self->html_row($num_uneditable,$rownum, + $exportcolor,$importcolor). "\n"; } $r->print($row_output); @@ -301,39 +348,67 @@ sub modify_cell { return; } -sub outsheet_csv { +sub csv_rows { + # writes the meat of the spreadsheet to an excel worksheet. Called + # by Spreadsheet::outsheet_excel; my $self = shift; - my ($r) = @_; -} -sub outsheet_excel { - my $self = shift; - my ($r) = @_; -} -sub outsheet_recursive_excel { - my $self = shift; - my ($r) = @_; -} - -sub display { - my $self = shift; - my ($r) = @_; - $self->compute(); - $self->outsheet_html($r); + my ($filehandle) = @_; + # + # Write a header row + $self->csv_output_row($filehandle,undef, + ('Sequence or Folder','Assessment title')); + # + # Write each assessments row + if (scalar(@Sequences)< 1) { + &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'}); + $self->csv_output_row($filehandle,$rownum,@assessdata); + } + } return; } -sub set_row_sources { +sub excel_rows { + # writes the meat of the spreadsheet to an excel worksheet. Called + # by Spreadsheet::outsheet_excel; my $self = shift; - while (my ($cell,$value) = each(%{$self->{'formulas'}})) { - next if ($cell !~ /^A(\d+)/ && $1 > 0); - my $row = $1; - (undef,$value) = split('__&&&__',$value); - $value = 'Default' if (! defined($value)); - $self->{'row_source'}->{$row} = $value; + my ($worksheet,$cols_output,$rows_output) = @_; + # + # Write a header row + $cols_output = 0; + foreach my $value ('Container','Assessment title') { + $worksheet->write($rows_output,$cols_output++,$value); + } + $rows_output++; + # + # Write each assessments row + if (scalar(@Sequences)< 1) { + &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'}); + $self->excel_output_row($worksheet,$rownum,$rows_output++, + @assessdata); + } } return; } +sub outsheet_recursive_excel { + my $self = shift; + my ($r) = @_; +} + sub compute { my $self = shift; $self->logthis('computing'); @@ -411,6 +486,20 @@ sub compute { $Exportrows{$student}->{'data'} = \@exportarray; # save export row $self->save_export_data(); + # + $self->save() if ($self->need_to_save()); + return; +} + +sub set_row_sources { + my $self = shift; + while (my ($cell,$value) = each(%{$self->{'formulas'}})) { + next if ($cell !~ /^A(\d+)/ && $1 > 0); + my $row = $1; + (undef,$value) = split('__&&&__',$value); + $value = 'Default' if (! defined($value)); + $self->{'row_source'}->{$row} = $value; + } return; } @@ -422,6 +511,7 @@ sub set_row_numbers { next if ($row == 0); my ($symb,undef) = split('__&&&__',$formula); $self->{'row_numbers'}->{$symb} = $row; + $self->{'maxrow'} = $1 if ($1 > $self->{'maxrow'}); } } @@ -490,6 +580,7 @@ Writes the export data for this student ############################################# sub save_export_data { my $self = shift; + return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; return if (! exists($Exportrows{$student})); return if (! $self->is_default()); @@ -524,6 +615,8 @@ sub export_data { my $self = shift; my $student = $self->{'name'}.':'.$self->{'domain'}; if (! exists($Exportrows{$student}) || + ! defined($Exportrows{$student}) || + ! defined($Exportrows{$student}->{'data'}) || ! $self->check_expiration_time($Exportrows{$student}->{'time'})) { $self->compute(); }
RowAssessment
Row Assessment
'.$rownum.''.$self->convenience_links($resource).''. 'Unavailable at this time