Annotation of loncom/interface/spreadsheet/assesscalc.pm, revision 1.9
1.1 matthew 1: #
1.9 ! matthew 2: # $Id: assesscalc.pm,v 1.8 2003/05/23 19:36:04 matthew Exp $
1.1 matthew 3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: # The LearningOnline Network with CAPA
27: # Spreadsheet/Grades Display Handler
28: #
29: # POD required stuff:
30:
31: =head1 NAME
32:
33: assesscalc
34:
35: =head1 SYNOPSIS
36:
37: =head1 DESCRIPTION
38:
39: =cut
40:
41: ###################################################
42: ### AssessSheet ###
43: ###################################################
44: package Apache::assesscalc;
45:
46: use strict;
47: use Apache::Constants qw(:common :http);
48: use Apache::lonnet;
1.2 matthew 49: use Apache::loncommon;
1.1 matthew 50: use Apache::Spreadsheet;
51: use HTML::Entities();
52: use Spreadsheet::WriteExcel;
53: use GDBM_File;
54: use Time::HiRes;
55:
56: @Apache::assesscalc::ISA = ('Apache::Spreadsheet');
57:
58: ########################################################
59: ########################################################
60:
61: =pod
62:
63: =head2 Package Variables
64:
65: =over 4
66:
67: =item %Exportrows
68:
69: =item $current_name
70:
71: =item $current_domain
72:
73: =item $current_course
74:
75: =item %parmhash
76:
77: =item %nice_parameter_name
78:
79: =item %useropt
80:
81: =item %courseopt
82:
83: =back
84:
85: =cut
86:
87: ########################################################
88: ########################################################
89:
90: my %Exportrows;
91:
92: my $current_name;
93: my $current_domain;
94: my $current_course;
95:
96: my %parmhash;
97: my %nice_parameter_name;
98:
99: my %useropt;
100: my %courseopt;
101:
102: ########################################################
103: ########################################################
104:
105: =pod
106:
107: =head2 Package Subroutines
108:
109: =item &clear_package()
110:
111: Reset all package variables.
112:
113: =cut
114:
115: ########################################################
116: ########################################################
117: sub clear_package {
118: undef(%Exportrows);
119: undef($current_name);
120: undef($current_domain);
121: undef($current_course);
122: undef(%useropt);
123: undef(%courseopt);
124: }
125:
126: ########################################################
127: ########################################################
128:
129: =pod
130:
131: =item &initialize_package()
132:
133: =cut
134:
135: ########################################################
136: ########################################################
137: sub initialize_package {
138: my ($sname,$sdomain) = @_;
139: $current_course = $ENV{'request.course.id'};
140: $current_name = $sname;
141: $current_domain = $sdomain;
142: undef(%courseopt);
143: &load_cached_export_rows();
144: &load_parameter_caches();
145: }
146:
147: ########################################################
148: ########################################################
149:
150: =pod
151:
152: =item &load_parameter_caches()
153:
154: =cut
155:
156: ########################################################
157: ########################################################
158: sub load_parameter_caches {
159: my $userprefix = $current_name.':'.$current_domain.'_';
160: $userprefix =~ s/:/_/g;
161: #
162: # Course Parameters Cache
163: if (! %courseopt) {
164: &Apache::lonnet::logthis("loading course options");
165: $current_course = $ENV{'request.course.id'};
166: undef(%courseopt);
167: if (! defined($current_name) || ! defined($current_domain)) {
168: &Apache::lonnet::logthis('bad call to setup_parameter_caches');
169: return;
170: }
171: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
172: my $id = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
173: my %Tmp = &Apache::lonnet::dump('resourcedata',$dom,$id);
174: while (my ($name,$value) = each(%Tmp)) {
1.3 matthew 175: $courseopt{$name}=$value;
1.1 matthew 176: }
177: }
178: if (! %useropt) {
179: my %Tmp = &Apache::lonnet::dump('resourcedata',
180: $current_domain,$current_name);
181: while (my ($name,$value) = each(%Tmp)) {
182: if ($name =~ /^error: 2/ || $name =~ /no such file/) {
183: undef(%useropt);
184: last;
185: }
186: $useropt{$userprefix.$name}=$value;
187: }
188: }
189: }
190:
191: ########################################################
192: ########################################################
193:
194: =pod
195:
196: =head2 assesscalc object methods
197:
198: =cut
199:
200: ########################################################
201: ########################################################
202: sub ensure_current_parameter_caches {
203: my $self = shift;
204: if (! defined($current_course) ||
205: $current_course ne $ENV{'request.course.id'} ) {
206: $current_course = $ENV{'request.course.id'};
207: undef(%courseopt);
208: }
209: if (! defined($current_name) || $current_name ne $self->{'name'} ||
210: ! defined($current_domain) || $current_domain ne $self->{'domain'}) {
211: $current_domain = $self->{'domain'};
212: $current_name = $self->{'name'};
213: undef(%useropt);
214: }
215: &load_parameter_caches();
216: }
217:
218: ##################################################
219: ##################################################
220:
221: =pod
222:
223: =item &parmval()
224:
225: Determine the value of a parameter.
226:
227: Inputs: $what, the parameter needed, $symb, $uname, $udom, $csec
228:
229: Returns: The value of a parameter, or '' if none.
230:
231: This function cascades through the possible levels searching for a value for
232: a parameter. The levels are checked in the following order:
233: user, course (at section level and course level), map, and lonnet::metadata.
234: This function uses %parmhash, which must be tied prior to calling it.
235: This function also requires %courseopt and %useropt to be initialized for
236: this user and course.
237:
238: =cut
239:
240: ##################################################
241: ##################################################
242: sub parmval {
243: my $self = shift;
244: my ($what,$symb,$uname,$udom,$csec)=@_;
245: $uname = $self->{'name'} if (! defined($uname));
246: $udom = $self->{'domain'} if (! defined($udom));
247: $csec = $self->{'section'} if (! defined($csec));
248: $symb = $self->{'symb'} if (! defined($symb));
249: #
250: my $result='';
251: #
252: # This should be a
253: my ($mapname,$id,$fn)=split(/___/,$symb);
254: # Cascading lookup scheme
255: my $rwhat=$what;
256: $what =~ s/^parameter\_//;
257: $what =~ s/\_([^\_]+)$/\.$1/;
258: #
259: my $symbparm = $symb.'.'.$what;
260: my $mapparm = $mapname.'___(all).'.$what;
1.3 matthew 261: my $courseprefix = $self->{'cid'};
1.1 matthew 262: my $usercourseprefix = $uname.'_'.$udom.'_'.$self->{'cid'};
263: #
1.3 matthew 264: my $seclevel = $courseprefix.'.['.$csec.'].'.$what;
265: my $seclevelr = $courseprefix.'.['.$csec.'].'.$symbparm;
266: my $seclevelm = $courseprefix.'.['.$csec.'].'.$mapparm;
267: #
268: my $courselevel = $courseprefix.'.'.$what;
269: my $courselevelr = $courseprefix.'.'.$symbparm;
270: my $courselevelm = $courseprefix.'.'.$mapparm;
271: #
272: my $ucourselevel = $usercourseprefix.'.'.$what;
273: my $ucourselevelr = $usercourseprefix.'.'.$symbparm;
274: my $ucourselevelm = $usercourseprefix.'.'.$mapparm;
1.1 matthew 275: # check user
276: if (defined($uname)) {
1.3 matthew 277: return $useropt{$ucourselevelr} if (defined($useropt{$ucourselevelr}));
278: return $useropt{$ucourselevelm} if (defined($useropt{$ucourselevelm}));
279: return $useropt{$ucourselevel} if (defined($useropt{$ucourselevel}));
1.1 matthew 280: }
281: # check section
282: if (defined($csec)) {
283: return $courseopt{$seclevelr} if (defined($courseopt{$seclevelr}));
284: return $courseopt{$seclevelm} if (defined($courseopt{$seclevelm}));
285: return $courseopt{$seclevel} if (defined($courseopt{$seclevel}));
286: }
287: #
288: # check course
289: return $courseopt{$courselevelr} if (defined($courseopt{$courselevelr}));
290: return $courseopt{$courselevelm} if (defined($courseopt{$courselevelm}));
291: return $courseopt{$courselevel} if (defined($courseopt{$courselevel}));
292: # check map parms
293: my $thisparm = $parmhash{$symbparm};
294: return $thisparm if (defined($thisparm));
295: # check default
296: $thisparm = &Apache::lonnet::metadata($fn,$rwhat.'.default');
297: return $thisparm if (defined($thisparm));
298: #
299: # Cascade Up
300: my $space=$what;
301: $space=~s/\.\w+$//;
302: if ($space ne '0') {
303: my @parts=split(/_/,$space);
304: my $id=pop(@parts);
305: my $part=join('_',@parts);
306: if ($part eq '') { $part='0'; }
307: my $newwhat=$rwhat;
308: $newwhat=~s/\Q$space\E/$part/;
309: my $partgeneral=$self->parmval($newwhat,$symb,$uname,$udom,$csec);
310: if (defined($partgeneral)) { return $partgeneral; }
311: }
312: #nothing defined
313: return '';
314: }
315:
1.8 matthew 316: sub get_html_title {
317: my $self = shift;
318: my ($assess_title,$name,$time) = $self->get_title();
319: my $title = '<h1>'.$assess_title.'</h1>'.
320: '<h2>'.$name.', '.
321: &Apache::loncommon::aboutmewrapper
322: ($self->{'name'}.'@'.$self->{'domain'},
323: $self->{'name'},$self->{'domain'});
324: $title .= '<h3>'.$time.'</h3>';
325: return $title;
326: }
327:
1.1 matthew 328: sub get_title {
329: my $self = shift;
1.8 matthew 330: my @title = ();
1.1 matthew 331: if (($self->{'usymb'} eq '_feedback') ||
332: ($self->{'usymb'} eq '_evaluation') ||
333: ($self->{'usymb'} eq '_discussion') ||
334: ($self->{'usymb'} eq '_tutoring')) {
1.8 matthew 335: my $assess_title = ucfirst($self->{'usymb'});
336: $assess_title =~ s/^_//;
337: push(@title,$assess_title);
1.1 matthew 338: } else {
1.8 matthew 339: push(@title,&Apache::lonnet::gettitle($self->{'symb'}));
1.1 matthew 340: }
1.2 matthew 341: # Look up the users identifying information
342: # Get the users information
343: my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'},
344: $self->{'domain'});
345: my $name =
346: join(' ',@userenv{'firstname','middlename','lastname','generation'});
347: $name =~ s/\s+$//;
1.8 matthew 348: push (@title,$name);
349: push (@title,scalar(localtime(time)));
350: return @title;
1.1 matthew 351: }
352:
353: sub parent_link {
354: my $self = shift;
355: my $link .= '<p><a href="/adm/studentcalc?'.
356: 'sname='.$self->{'name'}.
357: '&sdomain='.$self->{'domain'}.'">'.
358: 'Student level sheet</a></p>'."\n";
359: return $link;
360: }
361:
362: sub outsheet_html {
363: my $self = shift;
364: my ($r) = @_;
365: ###################################
366: # Determine table structure
367: ###################################
368: my $num_uneditable = 1;
369: my $num_left = 52-$num_uneditable;
370: my $tableheader =<<"END";
371: <table border="2">
372: <tr>
373: <th colspan="2" rowspan="2"><font size="+2">Assessment</font></th>
374: <td bgcolor="#FFDDDD" colspan="$num_uneditable"> </td>
375: <td colspan="$num_left">
376: <b><font size="+1">Calculations</font></b></td>
377: </tr><tr>
378: END
379: my $label_num = 0;
380: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
381: if ($label_num<$num_uneditable) {
382: $tableheader .= '<td bgcolor="#FFDDDD">';
383: } else {
384: $tableheader .= '<td>';
385: }
386: $tableheader .= "<b><font size=+1>$_</font></b></td>";
387: $label_num++;
388: }
389: $tableheader.="</tr>\n";
390: #
391: $r->print($tableheader);
392: #
393: # Print out template row
394: $r->print('<tr><td>Template</td><td> </td>'.
395: $self->html_template_row($num_uneditable)."</tr>\n");
396: #
397: # Print out summary/export row
398: $r->print('<tr><td>Export</td><td>0</td>'.
399: $self->html_export_row()."</tr>\n");
400: #
401: # Prepare to output rows
402: $tableheader =<<"END";
403: <table border="2">
404: <tr><th>row</th><th>Item</th>
405: END
406: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
407: if ($label_num<$num_uneditable) {
408: $tableheader.='<th bgcolor="#FFDDDD">';
409: } else {
410: $tableheader.='<th>';
411: }
412: $tableheader.="<b><font size=+1>$_</font></b></th>";
413: }
414: #
415: my $num_output = 0;
1.8 matthew 416: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
1.1 matthew 417: if ($num_output++ % 50 == 0) {
418: $r->print("</table>\n".$tableheader);
419: }
420: $r->print('<tr><td>'.$rownum.'</td>'.
421: $self->assess_html_row($num_uneditable,$rownum)."</tr>\n");
422: }
423: $r->print("</table>\n");
424: return;
425: }
426:
427: sub assess_html_row {
428: my $self = shift();
429: my ($num_uneditable,$row) = @_;
430: my $parameter_name = $self->{'formulas'}->{'A'.$row};
431: my @rowdata = $self->get_row($row);
432: my $num_cols_output = 0;
433: my $row_html;
434: if (exists($nice_parameter_name{$parameter_name})) {
435: my $name = $nice_parameter_name{$parameter_name};
436: $name =~ s/ /\ /g;
437: $row_html .= '<td>'.$name.'<br />'.$parameter_name.'</td>';
438: } else {
439: $row_html .= '<td>'.$parameter_name.'</td>';
440: }
441: foreach my $cell (@rowdata) {
1.8 matthew 442: $row_html .= '<td bgcolor="#EOFFDD">';
443: $row_html .= &Apache::Spreadsheet::html_editable_cell($cell,'#E0FFDD');
1.1 matthew 444: $row_html .= '</td>';
445: }
446: return $row_html;
447: }
448:
1.9 ! matthew 449: sub csv_rows {
! 450: # writes the meat of the spreadsheet to an excel worksheet. Called
! 451: # by Spreadsheet::outsheet_excel;
1.1 matthew 452: my $self = shift;
1.9 ! matthew 453: my ($filehandle) = @_;
! 454: #
! 455: # Write a header row
! 456: $self->csv_output_row($filehandle,undef,
! 457: ('Parameter','Description','Value'));
! 458: #
! 459: # Write each row
! 460: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
! 461: my $parameter_name = $self->{'formulas'}->{'A'.$rownum};
! 462: my $description = '';
! 463: if (exists($nice_parameter_name{$parameter_name})) {
! 464: $description = $nice_parameter_name{$parameter_name};
! 465: }
! 466: $self->csv_output_row($filehandle,$rownum,
! 467: $parameter_name,$description);
! 468: }
! 469: return;
1.1 matthew 470: }
471:
1.8 matthew 472: sub excel_rows {
473: # writes the meat of the spreadsheet to an excel worksheet. Called
474: # by Spreadsheet::outsheet_excel;
1.1 matthew 475: my $self = shift;
1.8 matthew 476: my ($worksheet,$cols_output,$rows_output) = @_;
477: #
478: # Write a header row
479: $cols_output = 0;
480: foreach my $value ('Parameter','Description','Value') {
481: $worksheet->write($rows_output,$cols_output++,$value);
482: }
483: $rows_output++;
484: #
485: # Write each row
486: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
487: my $parameter_name = $self->{'formulas'}->{'A'.$rownum};
488: my $description = '';
489: if (exists($nice_parameter_name{$parameter_name})) {
490: $description = $nice_parameter_name{$parameter_name};
491: }
492: $self->excel_output_row($worksheet,$rownum,$rows_output++,
493: $parameter_name,$description);
494: }
495: return;
1.1 matthew 496: }
497:
498: sub compute {
499: my $self = shift;
500: $self->logthis('computing');
501: $self->initialize_safe_space();
502: #
503: # Definitions
504: undef(%nice_parameter_name);
505: my %parameters; # holds underscored parameters by name
506: #
507: # Get the metadata fields and determine their proper names
508: my ($symap,$syid,$srcf)=split(/___/,$self->{'symb'});
509: my @Metadata = split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
510: foreach my $parm (@Metadata) {
511: next if ($parm !~ /^(resource\.|stores|parameter)_/);
512: my $cleaned_name = $parm;
513: $cleaned_name =~ s/^resource\./stores_/;
514: $cleaned_name =~ s/\./_/g;
515: my $display = &Apache::lonnet::metadata($srcf,
516: $cleaned_name.'.display');
517: if (! $display) {
518: $display .= &Apache::lonnet::metadata($srcf,$cleaned_name.'.name');
519: }
520: $parameters{$cleaned_name}++;
521: $nice_parameter_name{$cleaned_name} = $display;
522: }
523: #
524: # Get the values of the metadata fields
525: $self->ensure_current_parameter_caches();
526: my $filename = $self->{'coursefilename'}.'_parms.db';
527: if (tie(%parmhash,'GDBM_File',
528: $self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
529: foreach my $parmname (keys(%parameters)) {
1.3 matthew 530: my $value = $self->parmval($parmname);
1.1 matthew 531: $parameters{$parmname} =$value;
532: }
533: untie(%parmhash);
534: } else {
535: $self->logthis('unable to tie '.$filename);
536: }
537: #
538: # Clean out unnecessary parameters
539: foreach (keys(%parameters)) {
540: delete($parameters{$_}) if (! /(resource\.|stores_|parameter_)/);
541: }
542: #
543: # Get the students performance data
544: my %student_parameters =
545: &Apache::loncoursedata::get_current_state($self->{'name'},
546: $self->{'domain'},
547: $self->{'symb'},
548: $self->{'cid'});
549: while (my ($parm,$value) = each(%student_parameters)) {
550: $parm =~ s/^resource\./stores_/;
551: $parm =~ s/\./_/g;
552: $parameters{$parm} = $value;
553: }
554: #
555: # Set up the formulas and parameter values
556: my %f=$self->formulas();
557: my %c;
558: #
1.5 matthew 559: # Check for blackout requirements
560: if ((!exists($ENV{'request.role.adv'}) || !$ENV{'request.role.adv'})) {
561: while (my ($parm,$value) = each(%parameters)) {
562: last if ($self->blackout());
563: next if ($parm !~ /^(parameter_.*)_problemstatus$/);
564: next if ($parameters{$1.'_answerdate'}<time);
565: if (lc($value) eq 'no') {
566: # We must blackout this sheet
567: $self->blackout(1);
568: }
569: }
570: }
571: #
572: # Move the parameters into the spreadsheet
1.1 matthew 573: while (my ($parm,$value) = each(%parameters)) {
574: my $cell = 'A'.$self->get_row_number_from_key($parm);
575: $f{$cell} = $parm;
1.6 matthew 576: $value = '"'.$value.'"' if ($value =~/[^0-9.]/);
577: $c{$parm} = $value;
1.1 matthew 578: }
1.6 matthew 579: $self->formulas(\%f);
580: $self->constants(\%c);
1.1 matthew 581: $self->calcsheet();
582: #
583: # Store export row in cache
584: my @exportarray = $self->exportrow();
585: $Exportrows{$self->{'symb'}}->{'time'} = time;
586: $Exportrows{$self->{'symb'}}->{$self->{'filename'}} = \@exportarray;
587: #
588: # Save the export data
589: $self->save_export_data();
590: return;
591: }
592:
593: ##
594: ## sett overrides Spreadsheet::sett
595: ##
596: sub sett {
597: my $self = shift;
598: my %t=();
599: #
600: # Deal with the template row by copying the template formulas into each
601: # row.
602: foreach my $col ($self->template_cells()) {
603: next if ($col=~/^A/);
604: foreach my $row ($self->rows()) {
605: # Get the name of this cell
606: my $cell=$col.$row;
607: # Grab the template declaration
608: $t{$cell}=$self->formula('template_'.$col);
609: # Replace '#' with the row number
610: $t{$cell}=~s/\#/$row/g;
611: # Replace '....' with ','
612: $t{$cell}=~s/\.\.+/\,/g;
613: # Replace 'A0' with the value from 'A0'
614: $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
615: # Replace parameters
616: $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;
617: }
618: }
619: #
620: # Deal with the cells which have formulas
621: while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
622: next if ($cell =~ /template_/);
623: if ($cell =~ /^A/ && $cell ne 'A0') {
624: if ($formula !~ /^\!/) {
625: $t{$cell}=$self->{'constants'}->{$formula};
626: }
627: } else {
628: $t{$cell}=$formula;
629: $t{$cell}=~s/\.\.+/\,/g;
630: $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
631: $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;
632: }
633: }
634: # Put %t into the safe space
635: %{$self->{'safe'}->varglob('t')}=%t;
636: }
637:
638:
639: ########################################################
640: ########################################################
641:
642: =pod
643:
644: =item &load_cached_export_rows()
645:
646: Retrieves and parsers the export rows of the assessment spreadsheets.
647: These rows are saved in the students directory in the format:
648:
649: sname:sdom:assesscalc:symb.time => time
650:
651: sname:sdom:assesscalc:symb => filename___=___Adata___;___Bdata___;___ ...
652:
653: =cut
654:
655: ########################################################
656: ########################################################
657: sub load_cached_export_rows {
658: %Exportrows = undef;
659: my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.
660: $ENV{'request.course.id'},
661: $current_domain,$current_name,undef);
662: if ($tmp[0]!~/^error/) {
663: my %tmp = @tmp;
664: my $default_filename = $ENV{'course.'.$ENV{'request.course.id'}.
665: '.spreadsheet_default_assesscalc'};
666: # We only got one key, so we will access it directly.
667: while (my ($key,$sheetdata) = each(%tmp)) {
668: my ($sname,$sdom,$sheettype,$symb) = split(':',$key);
669: if ($symb =~ /\.time$/) {
670: $symb =~ s/\.time$//;
671: $Exportrows{$symb}->{'time'} = $sheetdata;
672: } else {
673: $sheetdata =~ s/^(.*)___=___//;
674: my $filename = $1;
675: $filename = $default_filename if (! defined($filename));
676: my @Data = split('___;___',$sheetdata);
677: $Exportrows{$symb}->{$filename} = \@Data;
678: }
679: }
680: }
681: }
682:
683: #############################################
684: #############################################
685:
686: =pod
687:
688: =item &export_data
689:
690: Returns the export data associated with the spreadsheet. Computes the
691: spreadsheet only if necessary.
692:
693: =cut
694:
695: #############################################
696: #############################################
697: sub export_data {
698: my $self = shift;
699: my $symb = $self->{'symb'};
1.5 matthew 700: if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} ||
701: ! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) ||
1.1 matthew 702: ! $self->check_expiration_time($Exportrows{$symb}->{'time'}) ||
703: ! exists($Exportrows{$symb}->{$self->{'filename'}}) ||
704: ! defined($Exportrows{$symb}->{$self->{'filename'}})) {
705: $self->compute();
706: }
707: my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}};
708: if ($Data[0] =~ /^(.*)___=___/) {
709: $self->{'sheetname'} = $1;
710: $Data[0] =~ s/^(.*)___=___//;
711: }
712: for (my $i=0;$i<$#Data;$i++) {
713: $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i]));
714: }
715: return @Data;
716: }
717:
718: #############################################
719: #############################################
720:
721: =pod
722:
723: =item &save_export_data()
724:
725: Writes the export data for this spreadsheet to the students cache.
726:
727: =cut
728:
729: #############################################
730: #############################################
731: sub save_export_data {
732: my $self = shift;
1.7 matthew 733: return if ($self->temporary());
1.1 matthew 734: my $student = $self->{'name'}.':'.$self->{'domain'};
735: my $symb = $self->{'symb'};
736: if (! exists($Exportrows{$symb}) ||
737: ! exists($Exportrows{$symb}->{$self->{'filename'}})) {
738: return;
739: }
740: my $key = join(':',($self->{'name'},$self->{'domain'},'assesscalc',$symb));
741: my $timekey = $key.'.time';
742: my $newstore= join('___;___',@{$Exportrows{$symb}->{$self->{'filename'}}});
743: $newstore = $self->{'filename'}.'___=___'.$newstore;
744: my $result = &Apache::lonnet::put
745: ('nohist_calculatedsheets_'.$ENV{'request.course.id'},
746: { $key => $newstore,
747: $timekey => $Exportrows{$symb}->{'time'} },
748: $self->{'domain'},
749: $self->{'name'});
750:
751: return;
752: }
753:
754: 1;
755:
756: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>