[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 04 Jul 2006 21:31:03 -0000
raeburn Tue Jul 4 17:31:03 2006 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
get_sections() can now include an optional status filter (active,future and/or previous). Sections only associated with non-student roles no longer included in returned sectioncount hash, where all roles with the section affiliation have been deleted. get_course_users() now returns section information in a comma separated list, which includes 'none' if a sectionless role satisfies the status,role and section filters. The list of sections put in the userdata hash is used to address bug 4885 (loncoursegroups).
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.418 loncom/interface/loncommon.pm:1.419
--- loncom/interface/loncommon.pm:1.418 Mon Jul 3 09:39:16 2006
+++ loncom/interface/loncommon.pm Tue Jul 4 17:31:02 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.418 2006/07/03 13:39:16 albertel Exp $
+# $Id: loncommon.pm,v 1.419 2006/07/04 21:31:02 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3962,20 +3962,28 @@
Determines all the sections for a course including
sections with students and sections containing other roles.
-Incoming parameters: domain, course number,
-reference to array containing roles for which sections should
-be gathered (optional). If the third argument is undefined,
-sections are gathered for any role.
+Incoming parameters:
+
+1. domain
+2. course number
+3. reference to array containing roles for which sections should
+be gathered (optional).
+4. reference to array containing status types for which sections
+should be gathered (optional).
+
+If the third argument is undefined, sections are gathered for any role.
+If the fourth argument is undefined, sections are gathered for any status.
+Permissible values are 'active' or 'future' or 'previous'.
Returns section hash (keys are section IDs, values are
number of users in each section), subject to the
-optional roles filter.
+optional roles filter, optional status filter
=cut
###############################################
sub get_sections {
- my ($cdom,$cnum,$possible_roles) = @_;
+ my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
if (!defined($cdom) || !defined($cnum)) {
my $cid = $env{'request.course.id'};
@@ -3986,16 +3994,32 @@
}
my %sectioncount;
+ my $now = time;
if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
my $sec_index = &Apache::loncoursedata::CL_SECTION();
my $status_index = &Apache::loncoursedata::CL_STATUS();
+ my $start_index = &Apache::loncoursedata::CL_START();
+ my $end_index = &Apache::loncoursedata::CL_END();
+ my $status;
while (my ($student,$data) = each(%$classlist)) {
- my ($section,$status) = ($data->[$sec_index],
- $data->[$status_index]);
- unless ($section eq '-1' || $section =~ /^\s*$/) {
- $sectioncount{$section}++;
+ my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
+ $data->[$status_index],
+ $data->[$start_index],
+ $data->[$end_index]);
+ if ($stu_status eq 'Active') {
+ $status = 'active';
+ } elsif ($end < $now) {
+ $status = 'previous';
+ } elsif ($start > $now) {
+ $status = 'future';
+ }
+ if ($section ne '-1' && $section !~ /^\s*$/) {
+ if ((!defined($possible_status)) || (($status ne '') &&
+ (grep/^\Q$status\E$/,@{$possible_status}))) {
+ $sectioncount{$section}++;
+ }
}
}
}
@@ -4004,14 +4028,31 @@
if ($user !~ /^(\w{2})/) { next; }
my ($role) = ($user =~ /^(\w{2})/);
if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
- my $section;
+ my ($section,$status);
if ($role eq 'cr' &&
$user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
$section=$1;
}
if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
if (!defined($section) || $section eq '-1') { next; }
- $sectioncount{$section}++;
+ my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
+ if ($end == -1 && $start == -1) {
+ next; #deleted role
+ }
+ if (!defined($possible_status)) {
+ $sectioncount{$section}++;
+ } else {
+ if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
+ $status = 'active';
+ } elsif ($end < $now) {
+ $status = 'future';
+ } elsif ($start > $now) {
+ $status = 'previous';
+ }
+ if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
+ $sectioncount{$section}++;
+ }
+ }
}
return %sectioncount;
}
@@ -4050,6 +4091,7 @@
sub get_course_users {
my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
my %idx = ();
+ my %seclists;
$idx{udom} = &Apache::loncoursedata::CL_SDOM();
$idx{uname} = &Apache::loncoursedata::CL_SNAME();
@@ -4066,6 +4108,10 @@
foreach my $student (keys(%{$classlist})) {
my $match = 0;
my $secmatch = 0;
+ my $section = $$classlist{$student}[$idx{section}];
+ if ($section eq '') {
+ $section = 'none';
+ }
if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
if (grep/^all$/,@{$sections}) {
$secmatch = 1;
@@ -4074,15 +4120,15 @@
$secmatch = 1;
}
} else {
- if (grep(/^\Q$$classlist{$student}[$idx{section}]\E$/,
- @{$sections})) {
+ if (grep(/^\Q$section\E$/,@{$sections})) {
$secmatch = 1;
}
}
if (!$secmatch) {
next;
}
- }
+ }
+ push (@{$seclists{$student}},$section);
if (defined($$types{'active'})) {
if ($$classlist{$student}[$idx{status}] eq 'Active') {
push(@{$$users{st}{$student}},'active');
@@ -4131,18 +4177,27 @@
next;
}
}
+ if ($usec eq '') {
+ $usec = 'none';
+ }
if ($uname ne '' && $udom ne '') {
my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role,
$usec);
foreach my $type (keys(%{$types})) {
if ($status eq $type) {
- @{$$users{$role}{$user}} = $type;
+ if (!grep/^\Q$type\E$/,@{$$users{$role}{$user}}) {
+ push(@{$$users{$role}{$user}},$type);
+ }
$match = 1;
}
}
- if (($match) && (ref($userdata) eq 'HASH') &&
- (!exists($$userdata{$uname.':'.$udom}))) {
- &get_user_info($udom,$uname,\%idx,$userdata);
+ if (($match) && (ref($userdata) eq 'HASH')) {
+ if (!exists($$userdata{$uname.':'.$udom})) {
+ &get_user_info($udom,$uname,\%idx,$userdata);
+ }
+ if (!grep/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}}) {
+ push(@{$seclists{$uname.':'.$udom}},$usec);
+ }
}
}
}
@@ -4156,10 +4211,17 @@
if (defined($userdata) &&
!exists($$userdata{$owner.':'.$cdom})) {
&get_user_info($cdom,$owner,\%idx,$userdata);
+ if (!grep/^none$/,@{$seclists{$owner.':'.$cdom}}) {
+ push(@{$seclists{$owner.':'.$cdom}},'none');
+ }
}
}
}
}
+ foreach my $user (keys(%seclists)) {
+ @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
+ $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
+ }
}
return;
}