--- loncom/interface/loncoursedata.pm 2015/03/10 02:45:56 1.196 +++ loncom/interface/loncoursedata.pm 2016/04/25 23:00:58 1.197 @@ -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 @@ sub ensure_current_full_data { 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 @@ Inputs: $starttime, $endtime, $table 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.