--- loncom/interface/spreadsheet/studentcalc.pm 2003/05/19 15:48:18 1.3 +++ loncom/interface/spreadsheet/studentcalc.pm 2003/05/29 18:39:58 1.10 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.3 2003/05/19 15:48:18 matthew Exp $ +# $Id: studentcalc.pm,v 1.10 2003/05/29 18:39:58 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,12 +64,24 @@ my %Exportrows = (); my $current_course; +sub 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 +103,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 +129,8 @@ sub get_title { $self->{'name'},$self->{'domain'}); } $title .= "

\n"; - $title .= '

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

\n"; - $title .= '

'.localtime(time).'

'; + $title .= '

'.$desc."

\n"; + $title .= '

'.$time.'

'; return $title; } @@ -156,24 +179,40 @@ END $label_num++; } $tableheader .="\n"; - # - $r->print($tableheader); - # - # Print out template row - $r->print('Template '. - $self->html_template_row($num_uneditable)."\n"); - # - # Print out summary/export row - $r->print('Export0'. - $self->html_export_row()."\n"); + if ($self->blackout()) { + $r->print('

'. + 'Some computations are not available at this time.
'. + 'There are problems whose status you are allowed to view.'. + '

'."\n"); + } else { + $r->print($tableheader); + # + # Print out template row + if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { + $r->print('Template '. + $self->html_template_row($num_uneditable)."\n"); + } + # + # Print out summary/export row + $r->print('Summary0'. + $self->html_export_row()."\n"); + } $r->print("\n"); # # Prepare to output rows - $tableheader =<<"END"; + if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { + $tableheader =<<"END";

END + } else { + $tableheader =<<"END"; +

+

RowAssessment
+ +END + } foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { $tableheader.=''; } else { $row_output .= ''; } - $row_output .= $self->html_row($num_uneditable,$rownum). - "\n"; + if ($self->blackout() && $self->{'blackout_rows'}->{$rownum}>0) { + $row_output .= + ''."\n"; + } else { + $row_output .= $self->html_row($num_uneditable,$rownum). + "\n"; + } $r->print($row_output); } $r->print("
 Assessment'; @@ -203,19 +242,25 @@ END ''. - $resource->{'title'}.'
'; + '&usymb='.&Apache::lonnet::escape($resource->{'symb'}). + '">'.$resource->{'title'}.'
'; $row_output .= &assess_file_selector($rownum, $assess_filename, \@AssessFileNames). '
Go To'; $row_output .= ''.$resource->{'title'}.'
Unavailable at this time
\n"); @@ -279,39 +324,67 @@ sub modify_cell { return; } -sub outsheet_csv { - my $self = shift; - my ($r) = @_; -} -sub outsheet_excel { +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_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'); @@ -356,6 +429,10 @@ sub compute { $assess_filename, $resource->{'symb'}); my @exportdata = $assessSheet->export_data(); + if ($assessSheet->blackout()) { + $self->blackout(1); + $self->{'blackout_rows'}->{$rownum} = 1; + } # # Be sure not to disturb the formulas in the 'A' column my $data = shift(@exportdata); @@ -385,6 +462,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; } @@ -396,6 +487,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'}); } } @@ -464,6 +556,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());