[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 01 May 2006 05:27:33 -0000


raeburn		Mon May  1 01:27:33 2006 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  Functions to retrieve information about group affiliation of students. Groups for students are classified as previous, future, active or aftercourse.  The aftercourse category includes groups in which a student's membership has expired, but in which the expiration time was less than 24 hours before the default access end date for the course, for students for whom access to the course has expired.     
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.165 loncom/interface/loncoursedata.pm:1.166
--- loncom/interface/loncoursedata.pm:1.165	Sat Apr 29 14:00:17 2006
+++ loncom/interface/loncoursedata.pm	Mon May  1 01:27:28 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.165 2006/04/29 18:00:17 albertel Exp $
+# $Id: loncoursedata.pm,v 1.166 2006/05/01 05:27:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2874,9 +2874,90 @@
     }
 }
 
+sub get_group_memberships {
+    my ($classlist,$cdom,$cnum) = @_;
+    my $cid = $cdom.'_'.$cnum;
+    if (!defined($cdom) || !defined($cnum)) {
+        $cid =  $env{'request.course.id'};
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+    }
+    my (%classgroups,%studentgroups);
+    my $now = time;
+    my $access_end = $env{'course.'.$cid.'.default_enrollment_end_date'};
+    my (%curr_groups,%groupmemberhash);
+    my $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom,
+                                                     $cnum);
+    if ($numgroups) {
+        %groupmemberhash = &Apache::lonnet::get_group_membership($cdom,$cnum);
+        foreach my $student (keys(%{$classlist})) {
+            %{$classgroups{$student}} = ();
+            my $hasgroup = 0;
+            foreach my $status ('previous','future','active','aftercourse') {
+                %{$classgroups{$student}{$status}} = ();
+            }
+            foreach my $group (keys(%curr_groups)) {
+                if (defined($groupmemberhash{$group.':'.$student})) {
+                    my ($end,$start) = split(/:/,$groupmemberhash{$group.':'.
+                                                                    $student});
+                    if ($start == -1) {
+                        next;
+                    } else {
+                        $studentgroups{$group} ++;
+                        $hasgroup = 1;
+                        if ($end && $end < $now) {
+                            $classgroups{$student}{'previous'}{$group} =
+                                         $groupmemberhash{$group.':'.$student};
+                            if ($classlist->{$student}[&CL_STATUS()] eq 'Expired') {
+                                if ($access_end && $access_end < $now) {
+                                    if ($access_end - $end < 86400) {
+                                        $classgroups{$student}{'aftercourse'}{$group} = $groupmemberhash{$group.':'.$student};
+                                    }
+                                }
+                            }
+                        } elsif ($now > $start) {
+                            if (!$end || $end > $now) {
+                                $classgroups{$student}{'active'}{$group} =
+                                         $groupmemberhash{$group.':'.$student};
+                            }
+                        } else {
+                            $classgroups{$student}{'future'}{$group} =
+                                         $groupmemberhash{$group.':'.$student};
+                        }
+                    }
+                }
+            }
+            if (!$hasgroup) {
+                $studentgroups{'none'} ++;
+            }
+        }
+    }
+    return (\%classgroups,\%studentgroups);
+}
+                                                                                   
+sub get_students_groups {
+    my ($student,$enrollment_status,$classgroups) = @_;
+    my @studentsgroups = ();
+    if (ref($$classgroups{$student}{'active'}) eq 'HASH') {
+        push(@studentsgroups,keys(%{$$classgroups{$student}{'active'}}));
+    }
+    if ($enrollment_status eq 'Any') {
+        foreach my $status ('previous','future') {
+            if (ref($$classgroups{$student}{$status}) eq 'HASH') {
+                push(@studentsgroups,keys(%{$$classgroups{$student}{$status}}));
+            }
+        }
+    } else {
+        if (ref($$classgroups{$student}{'aftercourse'}) eq 'HASH') {
+            push(@studentsgroups,keys(%{$$classgroups{$student}{'aftercourse'}}));
+        }
+    }
+    return @studentsgroups;
+}
+
+
 # ----- END HELPER FUNCTIONS --------------------------------------------
 
 1;
 __END__
 
-