File:
[LON-CAPA] /
loncom /
interface /
spreadsheet /
classcalc.pm
Revision
1.1:
download - view:
text,
annotated -
select for diffs
Fri May 16 20:55:11 2003 UTC (21 years, 3 months ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Nearly complete reworking of spreadsheet.
lonspreadsheet.pm holds a few utility functions and the handler, which
creates a spreadsheet and tells it to display itself.
Spreadsheet.pm is the base definition of the spreadsheet object.
classcalc.pm, studentcalc.pm, and assesscalc.pm are implementations of the
spreadsheets.
There are missing pieces - excel and csv output, limiting by section
permissions, the ability to add extra 'header' rows to the student and
course level sheets, and students are still allowed to view the assessment
level sheets (will disable this soon).
Computing and editing of the spreadsheet have been tested and have been
given a preliminary seal of approval.
1: #
2: # $Id: classcalc.pm,v 1.1 2003/05/16 20:55:11 matthew Exp $
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: classcalc
34:
35: =head1 SYNOPSIS
36:
37: =head1 DESCRIPTION
38:
39: =over 4
40:
41: =cut
42:
43: ###################################################
44: ### CourseSheet ###
45: ###################################################
46: package Apache::classcalc;
47:
48: use strict;
49: use Apache::Constants qw(:common :http);
50: use Apache::loncoursedata();
51: use Apache::lonhtmlcommon();
52: use Apache::Spreadsheet;
53: use Apache::studentcalc;
54: use HTML::Entities();
55: use Spreadsheet::WriteExcel;
56: use Apache::lonnet;
57: use Time::HiRes;
58:
59: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
60:
61: sub get_classlist {
62: my $self = shift;
63: # Retrieve the classlist
64: my @Students = ();
65: my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist
66: ($self->{'cid'},$self->{'cdom'},$self->{'cnum'});
67: while (my ($student,$student_data) = each (%$classlist)) {
68: my $studenthash = ();
69: for (my $i=0; $i< scalar(@$field_names);$i++) {
70: my $field = $field_names->[$i];
71: $studenthash->{$field}=$student_data->[$i];
72: }
73: # This is where we can skip students because they are in
74: # the wrong section, have expired or pending roles, whatever...
75: push (@Students,$studenthash);
76: }
77: my @SortedStudents = sort { $a->{'fullname'} cmp $b->{'fullname'} } @Students;
78: return @SortedStudents;
79: }
80:
81: sub get_title {
82: my $self = shift;
83: my $title = '<h2>'.$self->{'coursedesc'}."</h2>\n";
84: # Section info should be included
85: return $title;
86: }
87:
88: sub parent_link {
89: return '';
90: }
91:
92: sub outsheet_html {
93: my $self = shift;
94: my ($r) = @_;
95: ###################################
96: # Determine table structure
97: ###################################
98: my $num_uneditable = 26;
99: my $num_left = 52-$num_uneditable;
100: my $tableheader =<<"END";
101: <table border="2">
102: <tr>
103: <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
104: <td bgcolor="#FFDDDD" colspan="$num_uneditable">
105: <b><font size="+1">Import</font></b></td>
106: <td colspan="$num_left">
107: <b><font size="+1">Calculations</font></b></td>
108: </tr><tr>
109: END
110: my $label_num = 0;
111: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
112: if ($label_num<$num_uneditable) {
113: $tableheader.='<th bgcolor="#FFDDDD">';
114: } else {
115: $tableheader.='<th>';
116: }
117: $tableheader.="<b><font size=+1>$_</font></b></th>";
118: $label_num++;
119: }
120: $tableheader.="</tr>\n";
121: #
122: $r->print($tableheader);
123: #
124: # Print out template row
125: $r->print('<tr><td>Template</td><td> </td>'.
126: $self->html_template_row($num_uneditable)."</tr>\n");
127: #
128: # Print out summary/export row
129: $r->print('<tr><td>Summary</td><td>0</td>'.
130: $self->html_export_row()."</tr>\n");
131: #
132: # Prepare to output rows
133: $tableheader =<<"END";
134: <table border="2">
135: <tr><th>Row</th>
136: <th>student</th><th>username</th><th>domain</th>
137: <th>section</th><th>status</th>
138: END
139: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
140: if ($label_num<$num_uneditable) {
141: $tableheader.='<th bgcolor="#FFDDDD">';
142: } else {
143: $tableheader.='<th>';
144: }
145: $tableheader.="<b><font size=+1>$_</font></b></th>";
146: }
147: #
148: my $num_output = 0;
149: foreach my $student ($self->get_classlist()) {
150: if ($num_output++ % 50 == 0) {
151: $r->print("</table>\n".$tableheader);
152: }
153: my $rownum = $self->get_row_number_from_key
154: ($student->{'username'}.':'.$student->{'domain'});
155: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
156: '&sdomain='.$student->{'domain'}.'">';
157: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
158: $r->print('<tr>'.'<td>'.$rownum.'</td>'.
159: '<td>'.$link.$student->{'fullname'}.'</a></td>'.
160: '<td>'.$student->{'username'}.'</td>'.
161: '<td>'.$student->{'domain'} .'</td>'.
162: '<td>'.$student->{'section'} .'</td>'.
163: '<td>'.$student->{'status'} .'</td>'.
164: $self->html_row($num_uneditable,$rownum)."</tr>\n");
165: }
166: $r->print("</table>\n");
167: return;
168: }
169:
170: sub outsheet_csv {
171: my $self = shift;
172: my ($r) = @_;
173: }
174:
175: sub outsheet_excel {
176: my $self = shift;
177: my ($r) = @_;
178: }
179:
180: sub outsheet_recursive_excel {
181: my $self = shift;
182: my ($r) = @_;
183: }
184:
185: sub display {
186: my $self = shift;
187: my ($r) = @_;
188: $self->compute($r);
189: # display as html/csv/excel/etc....
190: $self->outsheet_html($r);
191: return;
192: }
193:
194: sub compute {
195: my $self = shift;
196: my ($r) = @_;
197: $self->initialize_safe_space();
198: my %c = $self->constants();
199: my %f = $self->formulas();
200: my @Students = $self->get_classlist();
201: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
202: ($r,'Spreadsheet Computation Status',
203: 'Spreadsheet Computation', scalar(@Students));
204: &Apache::studentcalc::initialize_package();
205: foreach my $student ($self->get_classlist()) {
206: my $sname = $student->{'username'}.':'.$student->{'domain'};
207: my $studentsheet = Apache::studentcalc->new
208: ($student->{'username'},$student->{'domain'},undef);
209: my @exportdata = $studentsheet->export_data();
210: my $rownum = $self->get_row_number_from_key($sname);
211: $f{'A'.$rownum} = $sname;
212: $self->{'row_source'}->{$rownum} = $sname;
213: $c{'A'.$rownum} = shift(@exportdata);
214: foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
215: my $cell = $_.$rownum;
216: my $data = shift(@exportdata);
217: if (defined($data)) {
218: $f{$cell} = 'import';
219: $c{$cell} = $data;
220: }
221: }
222: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
223: 'last student');
224: }
225: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
226: $r->rflush();
227: $self->constants(\%c);
228: $self->formulas(\%f);
229: $self->calcsheet();
230: }
231:
232: 1;
233:
234: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>