Diff for /loncom/interface/loncoursedata.pm between versions 1.192 and 1.200

version 1.192, 2011/10/03 13:11:39 version 1.200, 2016/08/14 16:13:21
Line 58  use Digest::MD5(); Line 58  use Digest::MD5();
   
 =pod   =pod 
   
 =head 2 make_into_hash  =head2 make_into_hash
   
 Turn a colon separated string into a hash and return a reference  Turn a colon separated string into a hash and return a reference
 to it.  Numbering from 0 even elements are keys and odd elements  to it.  Numbering from 0 even elements are keys and odd elements
Line 1251  sub ensure_current_data { Line 1251  sub ensure_current_data {
     }      }
   
     my $student_id = &get_student_id($sname,$sdom);      my $student_id = &get_student_id($sname,$sdom);
       &get_students_groupids($student_id);
     my @Result = &Apache::lonmysql::get_rows($student_table,      my @Result = &Apache::lonmysql::get_rows($student_table,
                                              "student_id ='$student_id'");                                               "student_id ='$student_id'");
     my $data = undef;      my $data = undef;
Line 1277  sub ensure_current_full_data { Line 1278  sub ensure_current_full_data {
         ($sdom,$sname,$courseid.'.db',$getuserdir);          ($sdom,$sname,$courseid.'.db',$getuserdir);
     #      #
     my $student_id = &get_student_id($sname,$sdom);      my $student_id = &get_student_id($sname,$sdom);
       &get_students_groupids($student_id);
     my @Result = &Apache::lonmysql::get_rows($student_table,      my @Result = &Apache::lonmysql::get_rows($student_table,
                                              "student_id ='$student_id'");                                               "student_id ='$student_id'");
     my $updatetime;      my $updatetime;
Line 1289  sub ensure_current_full_data { Line 1291  sub ensure_current_full_data {
     return $status;      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';
       }
       &setup_table_names($courseid);
       my @CurrentTables = &Apache::lonmysql::tables_in_db();
       unless (grep(/^\Q$groupnames_table\E$/,@CurrentTables)) {
           return;
       }
       # 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'};
       }
       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'};
       }
       &setup_table_names($courseid);
       my @CurrentTables = &Apache::lonmysql::tables_in_db();
       unless (grep(/^\Q$students_groups_table\E$/,@CurrentTables)) {
           return;
       }
       # 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'};
       }
       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 ensure_current_sections {
       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'};
       }
       &setup_table_names($courseid);
       my @CurrentTables = &Apache::lonmysql::tables_in_db();
       unless (grep(/^\Q$student_table\E$/,@CurrentTables)) {
           return;
       }
       # Get the update time for the student table
       my $getuserdir = 1;
       my $modifiedtime = &Apache::lonnet::GetFileTimestamp
           ($cdom,$cnum,'classlist.db',$getuserdir);
       my %tableinfo = &Apache::lonmysql::table_information($student_table);
       my $updatetime;
       if ($tableinfo{'Update_time'}) {
           $updatetime = $tableinfo{'Update_time'};
       }
       if ((!defined($updatetime)) || ($modifiedtime > $updatetime)) {
           if (&Apache::lonmysql::drop_table($student_table)) {
               if (&init_dbs($courseid)) {
                   return "error creating $student_table\n";
               } else {
                   &populate_student_table($courseid);
               }
           }
       }
       return;
   }
   
 sub get_student_data_from_performance_cache {  sub get_student_data_from_performance_cache {
     my ($sname,$sdom,$symb,$courseid)=@_;      my ($sname,$sdom,$symb,$courseid)=@_;
Line 2291  sub CL_FULLNAME { return 6; } Line 2435  sub CL_FULLNAME { return 6; }
 sub CL_STATUS   { return 7; }  sub CL_STATUS   { return 7; }
 sub CL_TYPE     { return 8; }  sub CL_TYPE     { return 8; }
 sub CL_LOCKEDTYPE   { return 9; }  sub CL_LOCKEDTYPE   { return 9; }
 sub CL_GROUP    { return 10; }  sub CL_CREDITS  { return 10; }
 sub CL_PERMANENTEMAIL { return 11; }  sub CL_INSTSEC { return 11; }
 sub CL_ROLE     { return 12; }  sub CL_GROUP    { return 12; }
 sub CL_EXTENT   { return 13; }  sub CL_PERMANENTEMAIL { return 13; }
 sub CL_PHOTO   { return 14; }  sub CL_ROLE     { return 14; }
 sub CL_THUMBNAIL { return 15; }  sub CL_EXTENT   { return 15; }
   sub CL_PHOTO   { return 16; }
   sub CL_THUMBNAIL { return 17; }
   sub CL_AUTHORQUOTA { return 18; }
   sub CL_AUTHORUSAGE { return 19; }
   
 sub get_classlist {  sub get_classlist {
     my ($cdom,$cnum) = @_;      my ($cdom,$cnum) = @_;
Line 2316  sub get_classlist { Line 2464  sub get_classlist {
         }          }
         my ($sname,$sdom) = split(/:/,$student);          my ($sname,$sdom) = split(/:/,$student);
         my @Values = split(/:/,$info);          my @Values = split(/:/,$info);
         my ($end,$start,$id,$section,$fullname,$type,$lockedtype);          my ($end,$start,$id,$section,$fullname,$type,$lockedtype,$credits,$instsec);
         if (@Values > 2) {          if (@Values > 2) {
             ($end,$start,$id,$section,$fullname,$type,$lockedtype) = @Values;              ($end,$start,$id,$section,$fullname,$type,$lockedtype,$credits,$instsec) = @Values;
         } else { # We have to get the data ourselves          } else { # We have to get the data ourselves
             ($end,$start) = @Values;              ($end,$start) = @Values;
             $section = &Apache::lonnet::getsection($sdom,$sname,$cid);              $section = &Apache::lonnet::getsection($sdom,$sname,$cid);
Line 2357  sub get_classlist { Line 2505  sub get_classlist {
             $status='Future';              $status='Future';
         }          }
         $classlist{$student} =           $classlist{$student} = 
             [$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type,$lockedtype];              [$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type,
                $lockedtype,$credits,$instsec];
     }      }
     if (wantarray()) {      if (wantarray()) {
         return (\%classlist,['domain','username','end','start','id',          return (\%classlist,['domain','username','end','start','id',
                              'section','fullname','status','type','lockedtype']);                               'section','fullname','status','type',
                                'lockedtype','credits','instsec']);
     } else {      } else {
         return \%classlist;          return \%classlist;
     }      }
Line 2982  Inputs: $starttime, $endtime, $table Line 3132  Inputs: $starttime, $endtime, $table
 Returns: $time_limits  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  Build SQL WHERE condition which limits the data collected by section and
 student status.  student status.
Line 3091  $env{'course.'.$cid.'.domain'}, and $env Line 3241  $env{'course.'.$cid.'.domain'}, and $env
   
 Returns a reference to a hash which contains:  Returns a reference to a hash which contains:
  keys    '$sname:$sdom'   keys    '$sname:$sdom'
  values  [$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type,$lockedtype]   values  [$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type,
             $lockedtype,$credits,$instsec]
   
 The constant values CL_SDOM, CL_SNAME, CL_END, etc. can be used  The constant values CL_SDOM, CL_SNAME, CL_END, etc. can be used
 as indices into the returned list to future-proof clients against  as indices into the returned list to future-proof clients against

Removed from v.1.192  
changed lines
  Added in v.1.200


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>