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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 28 Dec 2006 21:01:41 -0000


albertel		Thu Dec 28 16:01:41 2006 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  - bug 5003 - STAT caches not noticing change in student status
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.177 loncom/interface/loncoursedata.pm:1.178
--- loncom/interface/loncoursedata.pm:1.177	Wed Dec 20 21:51:53 2006
+++ loncom/interface/loncoursedata.pm	Thu Dec 28 16:01:39 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.177 2006/12/21 02:51:53 albertel Exp $
+# $Id: loncoursedata.pm,v 1.178 2006/12/28 21:01:39 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -369,8 +369,11 @@
                     { name => 'section',
                       type => 'VARCHAR(100) BINARY',
                       restrictions => 'NOT NULL'},
-                    { name => 'status',
-                      type => 'VARCHAR(15) BINARY',
+                    { name => 'start',
+                      type => 'INT',
+                      restrictions => 'NOT NULL'},
+                    { name => 'end',
+                      type => 'INT',
                       restrictions => 'NOT NULL'},
                     { name => 'classification',
                       type => 'VARCHAR(100) BINARY', },
@@ -382,7 +385,8 @@
         'PRIMARY KEY' => ['student_id'],
         'KEY' => [{ columns => ['student (100)',
                                 'section (100)',
-                                'status (15)',]},],
+                                'start',
+				'end']},],
     };
     #
     my $groupnames_table_def = {
@@ -906,18 +910,21 @@
     &init_dbs($courseid,0);
     my $dbh = &Apache::lonmysql::get_dbh();
     my $request = 'INSERT IGNORE INTO '.$student_table.
-        "(student,section,status) VALUES ";
+        "(student,section,start,end) VALUES ";
     my $cdom = $env{'course.'.$courseid.'.domain'};
     my $cnum = $env{'course.'.$courseid.'.num'};
     my $classlist = &get_classlist($cdom,$cnum);
     my $student_count=0;
     while (my ($student,$data) = each %$classlist) {
-        my ($section,$status) = ($data->[&CL_SECTION()],
-                                 $data->[&CL_STATUS()]);
+        my ($section,$start,$end) = ($data->[&CL_SECTION()],
+				     $data->[&CL_START()],
+				     $data->[&CL_END()]);
         if ($section eq '' || $section =~ /^\s*$/) {
             $section = 'none';
         }
-        $request .= "('".$student."','".$section."','".$status."'),";
+	if (!defined($start)) { $start = 0; }
+	if (!defined($end))   { $end   = 0; }
+        $request .= "('".$student."','".$section."','".$start."','".$end."'),";
         $student_count++;
     }
     return if ($student_count == 0);
@@ -2022,14 +2029,8 @@
     $request .= ' WHERE a.symb_id='.$symb_id.' AND a.part_id='.$part_id;
     #
     # Limit the students included to those specified
-    if (defined($Sections) && lc($Sections->[0]) ne 'all') {
-        $request .= ' AND ('.
-            join(' OR ', map { "b.section='".$_."'" } @$Sections
-                 ).')';
-    }
-    if (defined($status) && lc($status) ne 'any') {
-        $request .= " AND b.status='".$status."'";
-    }
+    my ($section_limits,$enrollment_limits)=
+        &limit_by_section_and_status($Sections,$status,'b');
     #
     # Limit by starttime and endtime
     my $time_requirements = undef;
@@ -2044,6 +2045,12 @@
     if (defined($time_requirements)) {
         $request .= ' AND '.$time_requirements;
     }
+    if (defined($section_limits)) {
+        $request .= ' AND '.$section_limits;
+    }
+    if (defined($enrollment_limits)) {
+        $request .= ' AND '.$enrollment_limits;
+    }
     # Limit by group, as required
     if (defined($group_limits)) {
         $request .= ' AND '.$group_limits;
@@ -2270,7 +2277,20 @@
     }
     my $enrollment_requirements=undef;
     if (defined($enrollment) && $enrollment ne 'Any') {
-        $enrollment_requirements = $tablename.".status='".$enrollment."'";
+	my $now = time();
+	if ( $enrollment eq 'Future' ) {
+	    $enrollment_requirements = 
+		"( $tablename.start > $now AND ".
+		"( $tablename.end = 0 OR $tablename.end > $now))";
+	} elsif ( $enrollment eq 'Active' ) {
+	    $enrollment_requirements = 
+		"(( $tablename.start = 0 OR $tablename.start < $now )  AND ".
+		" ( $tablename.end   = 0 OR $tablename.end   > $now ))";
+	} elsif ( $enrollment eq 'Expired' ) {
+	    $enrollment_requirements = 
+		"(( $tablename.start < $now )  AND ".
+		" ( $tablename.end   < $now ))";
+	}
     }
     return ($student_requirements,$enrollment_requirements);
 }