version 1.198, 2016/04/26 13:51:38
|
version 1.204, 2018/03/13 16:48:18
|
Line 1396 sub ensure_current_students_groups {
|
Line 1396 sub ensure_current_students_groups {
|
return; |
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)) { |
|
&update_student_table($cdom,$cnum); |
|
} |
|
return; |
|
} |
|
|
|
sub update_student_table { |
|
my ($cdom,$cnum) = @_; |
|
return unless (($cdom ne '') && ($cnum ne '')); |
|
my (%roster,%sqldata); |
|
my $classlist = &get_classlist($cdom,$cnum); |
|
while (my ($student,$data) = each (%$classlist)) { |
|
my ($section,$start,$end) = ($data->[&CL_SECTION()], |
|
$data->[&CL_START()], |
|
$data->[&CL_END()]); |
|
if ($section eq '' || $section =~ /^\s*$/) { |
|
$section = 'none'; |
|
} |
|
if ($start eq '') { $start = 0; } |
|
if ($end eq '') { $end = 0; } |
|
$roster{$student}{'section'} = $section; |
|
$roster{$student}{'start'} = $start; |
|
$roster{$student}{'end'} = $end; |
|
} |
|
my $dbh = &Apache::lonmysql::get_dbh(); |
|
my $statement = "SELECT student_id,student,section,start,end FROM $student_table"; |
|
my $sth = $dbh->prepare($statement); |
|
$sth->execute(); |
|
if ($sth->err()) { |
|
&Apache::lonnet::logthis("Unable to execute MySQL request:"); |
|
&Apache::lonnet::logthis("\n".$statement."\n"); |
|
&Apache::lonnet::logthis("error is:".$sth->errstr()); |
|
return undef; |
|
} |
|
foreach my $row (@{$sth->fetchall_arrayref}) { |
|
my ($id,$student,$section,$start,$end) = (@$row); |
|
if (ref($roster{$student}) eq 'HASH') { |
|
if (($roster{$student}{'section'} ne $section) || |
|
($roster{$student}{'start'} ne $start) || |
|
($roster{$student}{'end'} ne $end)) { |
|
$sqldata{$id} = { |
|
section => $roster{$student}{'section'}, |
|
start => $roster{$student}{'start'}, |
|
end => $roster{$student}{'end'}, |
|
}; |
|
} |
|
} |
|
} |
|
$sth->finish(); |
|
if (keys(%sqldata)) { |
|
foreach my $id (sort { $a <=> $b } keys(%sqldata)) { |
|
my $request = "UPDATE $student_table SET section='$sqldata{$id}{section}'". |
|
", start='$sqldata{$id}{start}'". |
|
", end='$sqldata{$id}{end}' WHERE student_id='$id'"; |
|
$dbh->do($request); |
|
} |
|
} |
|
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)=@_; |
my $student = $sname.':'.$sdom if (defined($sname) && defined($sdom)); |
my $student = $sname.':'.$sdom if (defined($sname) && defined($sdom)); |
Line 1591 sub get_problem_statistics {
|
Line 1677 sub get_problem_statistics {
|
# |
# |
$request = 'SELECT MAX(tries),MIN(tries) FROM '.$stats_table. |
$request = 'SELECT MAX(tries),MIN(tries) FROM '.$stats_table. |
' WHERE awarded>0'; |
' WHERE awarded>0'; |
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
|
my ($max,$min) = &execute_SQL_request($dbh,$request); |
my ($max,$min) = &execute_SQL_request($dbh,$request); |
# |
# |
$request = 'SELECT SUM(awarded) FROM '.$stats_table; |
$request = 'SELECT SUM(awarded) FROM '.$stats_table; |
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
|
my ($Solved) = &execute_SQL_request($dbh,$request); |
my ($Solved) = &execute_SQL_request($dbh,$request); |
# |
# |
$request = 'SELECT SUM(awarded) FROM '.$stats_table. |
$request = 'SELECT SUM(awarded) FROM '.$stats_table. |
" WHERE solved='correct_by_override'"; |
" WHERE solved='correct_by_override'"; |
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
|
my ($solved) = &execute_SQL_request($dbh,$request); |
my ($solved) = &execute_SQL_request($dbh,$request); |
# |
# |
$Solved -= $solved; |
$Solved -= $solved; |
Line 1689 sub populate_weight_table {
|
Line 1766 sub populate_weight_table {
|
my @resources; |
my @resources; |
foreach my $seq (@sequences) { |
foreach my $seq (@sequences) { |
push(@resources,$navmap->retrieveResources($seq, |
push(@resources,$navmap->retrieveResources($seq, |
sub {shift->is_problem();}, |
sub {shift->is_gradable();}, |
0,0,0)); |
0,0,0)); |
} |
} |
if (! scalar(@resources)) { |
if (! scalar(@resources)) { |
Line 1847 sub rank_students_by_scores_on_resources
|
Line 1924 sub rank_students_by_scores_on_resources
|
$limits =~ s/( AND )$//; # Remove extra conjunction |
$limits =~ s/( AND )$//; # Remove extra conjunction |
$request .= "WHERE $limits"; |
$request .= "WHERE $limits"; |
} |
} |
$request .= " $award_clause GROUP BY a.student_id ORDER BY score"; |
$request .= " $award_clause GROUP BY a.student_id ORDER BY score, b.student"; |
#&Apache::lonnet::logthis('request = '.$/.$request); |
#&Apache::lonnet::logthis('request = '.$/.$request); |
my $sth = $dbh->prepare($request) or die "Can't prepare $request"; |
my $sth = $dbh->prepare($request) or die "Can't prepare $request"; |
$sth->execute(); |
$sth->execute(); |
Line 2398 sub CL_STATUS { return 7; }
|
Line 2475 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_CREDITS { return 10; } |
sub CL_CREDITS { return 10; } |
sub CL_GROUP { return 11; } |
sub CL_INSTSEC { return 11; } |
sub CL_PERMANENTEMAIL { return 12; } |
sub CL_GROUP { return 12; } |
sub CL_ROLE { return 13; } |
sub CL_PERMANENTEMAIL { return 13; } |
sub CL_EXTENT { return 14; } |
sub CL_ROLE { return 14; } |
sub CL_PHOTO { return 15; } |
sub CL_EXTENT { return 15; } |
sub CL_THUMBNAIL { return 16; } |
sub CL_PHOTO { return 16; } |
sub CL_AUTHORQUOTA { return 17; } |
sub CL_THUMBNAIL { return 17; } |
sub CL_AUTHORUSAGE { return 18; } |
sub CL_AUTHORQUOTA { return 18; } |
|
sub CL_AUTHORUSAGE { return 19; } |
|
|
sub get_classlist { |
sub get_classlist { |
my ($cdom,$cnum) = @_; |
my ($cdom,$cnum) = @_; |
Line 2425 sub get_classlist {
|
Line 2503 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,$credits); |
my ($end,$start,$id,$section,$fullname,$type,$lockedtype,$credits,$instsec); |
if (@Values > 2) { |
if (@Values > 2) { |
($end,$start,$id,$section,$fullname,$type,$lockedtype,$credits) = @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 2467 sub get_classlist {
|
Line 2545 sub get_classlist {
|
} |
} |
$classlist{$student} = |
$classlist{$student} = |
[$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type, |
[$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type, |
$lockedtype,$credits]; |
$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', |
'section','fullname','status','type', |
'lockedtype','credits']); |
'lockedtype','credits','instsec']); |
} else { |
} else { |
return \%classlist; |
return \%classlist; |
} |
} |
Line 3203 $env{'course.'.$cid.'.domain'}, and $env
|
Line 3281 $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, |
values [$sdom,$sname,$end,$start,$id,$section,$fullname,$status,$type, |
$lockedtype,$credits] |
$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 |