[LON-CAPA-cvs] cvs: loncom /homework grades.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 16 Oct 2002 19:23:49 -0000
matthew Wed Oct 16 15:23:49 2002 EDT
Modified files:
/loncom/homework grades.pm
Log:
Rewrote &getclasslist to use loncoursedata::get_classlist() and changed its
return values since most were not used.
Removed &reformat_classlist as this functionality is in
loncoursedata::get_classlist().
Modified all calls to &getclasslist to reflect new return values and to
only bother keeping the values they need (assigning unused return values
to undef).
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.55 loncom/homework/grades.pm:1.56
--- loncom/homework/grades.pm:1.55 Wed Oct 16 15:13:57 2002
+++ loncom/homework/grades.pm Wed Oct 16 15:23:48 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.55 2002/10/16 19:13:57 matthew Exp $
+# $Id: grades.pm,v 1.56 2002/10/16 19:23:48 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -111,62 +111,32 @@
#--- section, ids and fullnames for each user.
sub getclasslist {
my ($getsec,$hideexpired) = @_;
- my $now = time;
- my %classlist=&Apache::lonnet::dump('classlist',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- my ($tmp) = keys(%classlist);
+ my $classlist=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
- return if ($tmp =~ /^(con_lost|error|no_such_host)/i);
-
- # codes to check for fields in the classlist
- # should contain end:start:id:section:fullname
- for (keys %classlist) {
- my (@fields) = split(/:/,$classlist{$_});
- %classlist = &reformat_classlist(\%classlist) if (scalar(@fields) <= 2);
- last;
- }
-
- my (@holdsec,@sections,%allids,%stusec,%fullname);
- foreach (keys(%classlist)) {
- my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_});
+ return if (! defined($classlist));
+ #
+ my %sections;
+ my %fullnames;
+ foreach (keys(%$classlist)) {
+ # the following undefs are for 'domain', and 'username' respectively.
+ my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
+ @{$classlist->{$_}};
# still a student?
- if (($hideexpired) && ($end) && ($end < $now)) {
- next;
- }
+ if (($hideexpired) && ($status ne 'Active')) {
+ delete ($classlist->{$_});
+ next;
+ }
$section = ($section ne '' ? $section : 'no');
- push @holdsec,$section;
if ($getsec eq 'all' || $getsec eq $section) {
- push (@{ $classlist{$getsec} }, $_);
- $allids{$_} =$id;
- $stusec{$_} =$section;
- $fullname{$_}=$fullname;
- }
+ $sections{$section}++;
+ $fullnames{$_}=$fullname;
+ } else {
+ delete($classlist->{$_});
+ }
}
my %seen = ();
- foreach my $item (@holdsec) {
- push (@sections, $item) unless $seen{$item}++;
- }
- return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
-}
-
-# add id, section and fullname to the classlist.db
-# done to maintain backward compatibility with older versions
-sub reformat_classlist {
- my ($classlist) = shift;
- foreach (sort keys(%$classlist)) {
- my ($unam,$udom) = split(/:/);
- my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
- my $fullname = &get_fullname ($unam,$udom);
- my %userid = &Apache::lonnet::idrget($udom,($unam));
- $$classlist{$_} = $$classlist{$_}.':'.$userid{$unam}.':'.$section.':'.$fullname;
- }
- my $putresult = &Apache::lonnet::put
- ('classlist',\%$classlist,
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
- return %$classlist;
+ my @sections = sort(keys(%sections));
+ return ($classlist,\@sections,\%fullnames);
}
#find user domain
@@ -267,8 +237,8 @@
'<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br><br>'."\n";
my ($string,$contents,$matches) = ('','',0);
- my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0');
-
+ my (undef,undef,$fullname) = &getclasslist('all','0');
+
foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
my ($uname,$udom)=split(/\:/);
if ($receipt eq
@@ -393,7 +363,7 @@
'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
'value="'.$viewgrade.'" />'."\n";
- my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0');
+ my (undef,undef,$fullname) = &getclasslist($getsec,'0');
$gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
'<table border="0"><tr bgcolor="#e6ffff">'.
@@ -840,7 +810,6 @@
if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
$ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
- my ($classlist,$seclist,$ids,$stusec,$fullname);
# header info
if ($counter == 0) {
@@ -941,9 +910,10 @@
# If this is handgraded, then check for collaborators
my @col_fullnames;
+ my ($classlist,$fullname);
if ($ENV{'form.handgrade'} eq 'yes') {
my @col_list;
- ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0');
+ ($classlist,undef,$fullname) = &getclasslist('all','0');
for (keys (%$handgrade)) {
my $ncol = &Apache::lonnet::EXT('resource.'.$_.
'.maxcollaborators',$symb,$udom,$uname);
@@ -1301,7 +1271,7 @@
$laststu = $firststu if ($ctr > $ngrade);
}
- my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
+ my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
my (@parsedlist,@nextlist);
my ($nextflg) = 0;
foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
@@ -1682,7 +1652,7 @@
#get info for each student
#list all the students - with points and grade status
- my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
+ my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
my $ctr = 0;
foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
my ($uname,$udom) = split(/:/);
@@ -1767,7 +1737,7 @@
'ungraded' =>'ungraded_attempted',
'nothing' => '',
);
- my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
+ my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
my (@partid);
my %weight = ();
@@ -2185,7 +2155,7 @@
#--- Menu for grading a section or the whole class ---
sub view_edit_entire_class_form {
my ($symb,$url)=@_;
- my ($classlist,$sections) = &getclasslist('all','0');
+ my ($classlist,$sections,undef) = &getclasslist('all','0');
my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
$result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
$result.=' <b>Grade Entire Section or Class</b></td></tr>'."\n";