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

raeburn raeburn at source.lon-capa.org
Mon Apr 25 19:00:58 EDT 2016


raeburn		Mon Apr 25 23:00:58 2016 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm lonstatistics.pm 
  Log:
  - Ensure course's "temporary" MySQL tables for groupnames and studentgroups 
    are current when Chart or Statistics web GUI are used in course with groups.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.196 loncom/interface/loncoursedata.pm:1.197
--- loncom/interface/loncoursedata.pm:1.196	Tue Mar 10 02:45:56 2015
+++ loncom/interface/loncoursedata.pm	Mon Apr 25 23:00:58 2016
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.196 2015/03/10 02:45:56 raeburn Exp $
+# $Id: loncoursedata.pm,v 1.197 2016/04/25 23:00:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1291,6 +1291,104 @@
     return $status;
 }
 
+sub ensure_current_groups {
+    my ($courseid) = @_;  
+    my ($cdom,$cnum);
+    if (defined($courseid)) {
+        my %coursehash = &Apache::lonnet::coursedescription($courseid);
+        $cdom = $coursehash{'domain'};
+        $cnum = $coursehash{'num'};
+    } elsif ($env{'request.course.id'}) {
+        $courseid = $env{'request.course.id'};
+        $cdom = $env{'course.'.$courseid.'.domain'};
+        $cnum = $env{'course.'.$courseid.'.num'};
+    }
+    if ($cdom eq '' || $cnum eq '') {
+        return 'error: invalid course';
+    }
+    &ensure_tables_are_set_up($courseid);
+    # Get the update time for the groupnames table
+    my $getuserdir = 1;
+    my $modifiedtime = &Apache::lonnet::GetFileTimestamp
+        ($cdom,$cnum,'coursegroups.db',$getuserdir);
+    my %tableinfo = &Apache::lonmysql::table_information($groupnames_table);
+    my $updatetime;
+    if ($tableinfo{'Update_time'}) {
+        $updatetime = $tableinfo{'Update_time'};
+    }
+    print STDERR "1. updatetime is ||$updatetime|| and modifidtime is ||$modifiedtime||\n"; 
+    if (! defined($updatetime) || $modifiedtime > $updatetime) {
+        my (%groups_in_sql,%removegroups,$addgroup);
+        my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
+        my @Result = &Apache::lonmysql::get_rows($groupnames_table);
+        foreach my $row (@Result) {
+            my ($id,$name) = @{$row};
+            unless (exists($curr_groups{$name})) {
+                $groups_in_sql{$name}=$id;
+            } elsif ($id) {
+                $removegroups{$id} = $name;
+            }
+        }
+        foreach my $group (keys(%curr_groups)) {
+            unless (exists($groups_in_sql{$group})) {
+                $addgroup = 1;
+                last;
+            }
+        }
+        if (keys(%removegroups)) {
+            my $dbh = &Apache::lonmysql::get_dbh();
+            foreach my $group_id (keys(%removegroups)) {
+                my $command = 'DELETE FROM '.$groupnames_table.' WHERE group_id='.
+                              $group_id;
+                $dbh->do($command);
+                if ($dbh->err()) {
+                    &Apache::lonnet::logthis("error ".$dbh->errstr().
+                                             " occurred executing \n".
+                                             "SQL command: $command");
+                }
+            }
+        }
+        if ($addgroup) {
+            &populate_groupnames_table($courseid);
+        }
+    }
+    return;
+}
+
+sub ensure_current_students_groups {
+    my ($courseid) = @_;
+    my ($cdom,$cnum);
+    if (defined($courseid)) {
+        my %coursehash = &Apache::lonnet::coursedescription($courseid);
+        $cdom = $coursehash{'domain'};
+        $cnum = $coursehash{'num'};
+    } elsif ($env{'request.course.id'}) {
+        $courseid = $env{'request.course.id'};
+        $cdom = $env{'course.'.$courseid.'.domain'};
+        $cnum = $env{'course.'.$courseid.'.num'};
+    }
+    &ensure_tables_are_set_up($courseid);
+    # Get the update time for the groupnames table
+    my $getuserdir = 1;
+    my $modifiedtime = &Apache::lonnet::GetFileTimestamp
+        ($cdom,$cnum,'groupmembership.db',$getuserdir);
+    my %tableinfo = &Apache::lonmysql::table_information($students_groups_table);
+    my $updatetime;
+    if ($tableinfo{'Update_time'}) {
+        $updatetime = $tableinfo{'Update_time'};
+    }
+    print STDERR "2. updatetime is ||$updatetime|| and modifidtime is ||$modifiedtime||\n";
+    if ((!defined($updatetime)) || ($modifiedtime > $updatetime)) {
+        if (&Apache::lonmysql::drop_table($students_groups_table)) {
+            if (&init_dbs($courseid)) {
+                return "error creating $students_groups_table\n";
+            } else {
+                &populate_students_groups_table($courseid);
+            }
+        }
+    }
+    return;
+}
 
 sub get_student_data_from_performance_cache {
     my ($sname,$sdom,$symb,$courseid)=@_;
@@ -2989,7 +3087,7 @@
 Returns: $time_limits
 
 
-=item C<&limit_by_section_and_status()C<
+=item C<&limit_by_section_and_status()C>
 
 Build SQL WHERE condition which limits the data collected by section and
 student status.
Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.161 loncom/interface/lonstatistics.pm:1.162
--- loncom/interface/lonstatistics.pm:1.161	Tue Mar 10 00:47:18 2015
+++ loncom/interface/lonstatistics.pm	Mon Apr 25 23:00:58 2016
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstatistics.pm,v 1.161 2015/03/10 00:47:18 raeburn Exp $
+# $Id: lonstatistics.pm,v 1.162 2016/04/25 23:00:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -366,7 +366,7 @@
 
 sub get_students {
     if (! @Students) {
-        &PrepareClasslist()
+        &PrepareClasslist();
     }
     return @Students;
 }
@@ -582,6 +582,14 @@
         &PrepareClasslist();
     }
     #
+    # Make sure course's groupnames and studentgroups tables
+    # are up to date.
+    #
+    if (@Groups) {
+        &Apache::loncoursedata::ensure_current_groups();
+        &Apache::loncoursedata::ensure_current_students_groups();
+    }
+    #
     # Build the form element
     my $Str = "\n";
     $Str .= '<select name="'.$elementname.'" ';




More information about the LON-CAPA-cvs mailing list