[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Mon, 14 Oct 2002 19:06:22 -0000
matthew Mon Oct 14 15:06:22 2002 EDT
Modified files:
/loncom/interface loncoursedata.pm
Log:
Added &get_classlist, which gets the classlist for the current class in
a simple manner and does not bother with caching at all. It will get
data from a students environment if the classlist does not contain the
needed information. The data is *not* rewritten to the classlist at this
time.
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.34 loncom/interface/loncoursedata.pm:1.35
--- loncom/interface/loncoursedata.pm:1.34 Wed Oct 9 13:25:23 2002
+++ loncom/interface/loncoursedata.pm Mon Oct 14 15:06:21 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# (Publication Handler
#
-# $Id: loncoursedata.pm,v 1.34 2002/10/09 17:25:23 matthew Exp $
+# $Id: loncoursedata.pm,v 1.35 2002/10/14 19:06:21 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1387,7 +1387,83 @@
return 'OK';
}
+################################################
+################################################
+
+=pod
+
+=item &get_classlist();
+
+Retrieve the classist of a given class or of the current class. Student
+information is returned from the classlist.db file and, if needed,
+from the students environment.
+
+Optional arguments are $cid, $cdom, and $cnum (course id, course domain,
+and course number, respectively). Any omitted arguments will be taken
+from the current environment ($ENV{'request.course.id'},
+$ENV{'course.'.$cid.'.domain'}, and $ENV{'course.'.$cid.'.num'}).
+
+Returns a reference to a hash which contains:
+ keys '$sname:$sdom'
+ values [$end,$start,$id,$section,$fullname]
+
+=cut
+
+################################################
+################################################
+
+sub get_classlist {
+ my ($cid,$cdom,$cnum) = @_;
+ $cid = $cid || $ENV{'request.course.id'};
+ $cdom = $cdom || $ENV{'course.'.$cid.'.domain'};
+ $cnum = $cnum || $ENV{'course.'.$cid.'.num'};
+ my $now = time;
+ #
+ my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum);
+ while (my ($student,$info) = each(%classlist)) {
+ return undef if ($student =~ /^(con_lost|error|no_such_host)/i);
+ my ($sname,$sdom) = split(/:/,$student);
+ my @Values = split(/:/,$info);
+ my ($end,$start,$id,$section,$fullname);
+ if (@Values > 2) {
+ ($end,$start,$id,$section,$fullname) = @Values;
+ } else { # We have to get the data ourselves
+ ($end,$start) = @Values;
+ $section = &Apache::lonnet::usection($sdom,$sname,$cid);
+ my %info=&Apache::lonnet::get('environment',
+ ['firstname','middlename',
+ 'lastname','generation','id'],
+ $sdom, $sname);
+ my ($tmp) = keys(%info);
+ if ($tmp =~/^(con_lost|error|no_such_host)/i) {
+ $fullname = 'not available';
+ $id = 'not available';
+ } else {
+ $fullname = &ProcessFullName(@info{qw/lastname generation
+ firstname middlename/});
+ $id = $info{'id'};
+ }
+ # At this point, if we have the data (check for 'not available's
+ # we could put it back into the classlist.db file.
+ # We have not decided to do that yet.
+ }
+ my $status='Expired';
+ if(((!$end) || $now < $end) && ((!$start) || ($now > $start))) {
+ $status='Active';
+ }
+ $classlist{$student} =
+ [$sdom,$sname,$end,$start,$id,$section,$fullname,$status];
+ }
+ if (wantarray()) {
+ return (\%classlist,['domain','username','end','start','id',
+ 'section','fullname','status']);
+ } else {
+ return \%classlist;
+ }
+}
+
# ----- END HELPER FUNCTIONS --------------------------------------------
1;
__END__
+