[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 04 Oct 2005 16:34:44 -0000
raeburn Tue Oct 4 12:34:44 2005 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Added get_course_users() to retrieve information about users with roles in a course. Used by interface/lonnotify.pm to build recipient list.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.274 loncom/interface/loncommon.pm:1.275
--- loncom/interface/loncommon.pm:1.274 Fri Sep 16 12:01:18 2005
+++ loncom/interface/loncommon.pm Tue Oct 4 12:34:40 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.274 2005/09/16 16:01:18 raeburn Exp $
+# $Id: loncommon.pm,v 1.275 2005/10/04 16:34:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3054,6 +3054,79 @@
###############################################
+=pod
+
+=item get_course_users
+
+Retrieves usernames:domains for users in the specified course
+with specific role(s), and access status.
+
+Incoming parameters:
+1. course_id
+2. course domain
+3. course number
+4. access status: users must have - either active,
+previous, future, or all.
+5. reference to array of permissible roles
+6. reference to results object (hash of hashes).
+Keys of top level hash are roles.
+Keys of inner hashes are username:domain, with
+values set to access type.
+
+=cut
+
+###############################################
+
+sub get_course_users {
+ my ($course_id,$cdom,$cnum,$types,$roles,$users) = @_;
+ if (grep/^st$/,@{$roles}) {
+ my $statusidx = &Apache::loncoursedata::CL_STATUS;
+ my $startidx = &Apache::loncoursedata::CL_START;
+ my $endidx = &Apache::loncoursedata::CL_END;
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($course_id,$cdom,$cnum);
+ foreach my $student (keys (%{$classlist})) {
+ if (defined($$types{'active'})) {
+ if ($$classlist{$student}[$statusidx] eq 'Active') {
+ push(@{$$users{st}{$student}},'active');
+ }
+ }
+ if (defined($$types{'previous'})) {
+ if ($$classlist{$student}[$endidx] <= time) {
+ push(@{$$users{st}{$student}},'previous');
+ }
+ }
+ if (defined($$types{'future'})) {
+ if (($$classlist{$student}[$startidx] > 0) && ($$classlist{$student}[$endidx] > time) || ($$classlist{$student}[$endidx] == 0) || ($$classlist{$student}[$endidx] eq '')) {
+ push(@{$$users{st}{$student}},'future');
+ }
+ }
+ }
+ }
+ if ((@{$roles} > 0) && (@{$roles} ne "st")) {
+ my ($cdom,$cnum) = split/_/,$course_id;
+ my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
+ foreach my $person (@coursepersonnel) {
+ my ($role,$user) = ($person =~ /^([^:]*):([^:]+:[^:]+)/);
+ $user =~ s/:$//;
+ if (($role) && (grep/^$role$/,@{$roles})) {
+ my ($uname,$udom) = split/:/,$user;
+ if ($uname ne '' && $udom ne '') {
+ my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role);
+ foreach my $type (keys %{$types}) {
+ if ($status eq $type) {
+ $$users{$role}{$user} = $type;
+ }
+ }
+ }
+ }
+ }
+ }
+ return;
+}
+
+
+
+###############################################
sub get_posted_cgi {
my $r=shift;