--- loncom/interface/loncoursedata.pm 2006/08/08 19:02:04 1.174 +++ loncom/interface/loncoursedata.pm 2007/01/11 21:09:39 1.179 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.174 2006/08/08 19:02:04 albertel Exp $ +# $Id: loncoursedata.pm,v 1.179 2007/01/11 21:09:39 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -369,8 +369,11 @@ sub init_dbs { { 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 @@ sub init_dbs { 'PRIMARY KEY' => ['student_id'], 'KEY' => [{ columns => ['student (100)', 'section (100)', - 'status (15)',]},], + 'start', + 'end']},], }; # my $groupnames_table_def = { @@ -906,18 +910,21 @@ sub populate_student_table { &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); @@ -1139,7 +1146,6 @@ sub update_full_student_data { &setup_table_names($courseid); # my $student_id = &get_student_id($sname,$sdom); - my @group_ids = &get_students_groupids($student_id); my $student = $sname.':'.$sdom; # my $returnstatus = 'okay'; @@ -1171,6 +1177,8 @@ sub update_full_student_data { while (my ($key,$value) = each(%studentdata)) { next if ($key =~ /^(\d+):(resource$|subnum$|keys:)/); my ($transaction,$symb,$parameter) = split(':',$key); + $symb = &unescape($symb); + $parameter = &unescape($parameter); my $symb_id = &get_symb_id($symb); if ($parameter eq 'timestamp') { # We can deal with 'timestamp' right away @@ -1422,25 +1430,23 @@ sub update_student_data { &setup_table_names($courseid); # my $student_id = &get_student_id($sname,$sdom); - my @group_ids = &get_students_groupids($student_id); my $student = $sname.':'.$sdom; # my $returnstatus = 'okay'; # # Download students data my $time_of_retrieval = time; - my @tmp = &Apache::lonnet::currentdump($courseid,$sdom,$sname); - if ((scalar(@tmp) > 0) && ($tmp[0] =~ /^error:/)) { + my %student_data = &Apache::lonnet::currentdump($courseid,$sdom,$sname); + if (&Apache::lonnet::error(%student_data)) { &Apache::lonnet::logthis('error getting data for '. $sname.':'.$sdom.' in course '.$courseid. - ':'.$tmp[0]); - $returnstatus = 'error getting data'; + ':'.(%student_data)[0]); + $returnstatus =(%student_data)[0] ; return ($returnstatus,undef); } - if (scalar(@tmp) < 1) { + if (scalar(keys(%student_data)) < 1) { return ('no data',undef); } - my %student_data = @tmp; my @Results = &store_student_data($sname,$sdom,$courseid,\%student_data); # # Set the students update time @@ -1474,7 +1480,6 @@ sub store_student_data { my ($sname,$sdom,$courseid,$student_data) = @_; # my $student_id = &get_student_id($sname,$sdom); - my @group_ids = &get_students_groupids($student_id); my $student = $sname.':'.$sdom; # my $returnstatus = 'okay'; @@ -1670,8 +1675,11 @@ sub ensure_current_data { ($sdom,$sname,$courseid.'.db', $Apache::lonnet::perlvar{'lonUsersDir'}); # + if ($modifiedtime == -1) { + return ('no data',undef); + } + my $student_id = &get_student_id($sname,$sdom); - my @group_ids = &get_students_groupids($student_id); my @Result = &Apache::lonmysql::get_rows($student_table, "student_id ='$student_id'"); my $data = undef; @@ -1720,7 +1728,6 @@ sub ensure_current_full_data { $Apache::lonnet::perlvar{'lonUsersDir'}); # my $student_id = &get_student_id($sname,$sdom); - my @group_ids = &get_students_groupids($student_id); my @Result = &Apache::lonmysql::get_rows($student_table, "student_id ='$student_id'"); my $updatetime; @@ -1915,7 +1922,7 @@ sub get_current_state { } else { if ($status ne 'okay' && $status ne '') { &Apache::lonnet::logthis('status = '.$status); - return (); + return ('error: '.$status,undef); } my $returnhash = &get_student_data_from_performance_cache($sname,$sdom, $symb,$courseid); @@ -2024,14 +2031,8 @@ sub get_problem_statistics { $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; @@ -2046,6 +2047,12 @@ sub get_problem_statistics { 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; @@ -2272,7 +2279,20 @@ sub limit_by_section_and_status { } 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); } @@ -2728,7 +2748,7 @@ sub get_response_data { if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { # Clear the \'s from around the submission for (my $i =0;$i[$i]->[3] =~ s/(\'$|^\')//g; + $dataset->[$i]->[&RD_submission()] =~ s/(\'$|^\')//g; } return $dataset; } @@ -2756,7 +2776,6 @@ sub get_response_data_by_student { # my $student_id = &get_student_id($student->{'username'}, $student->{'domain'}); - my @group_ids = &get_students_groupids($student_id); # my $dbh = &Apache::lonmysql::get_dbh(); return undef if (! defined($dbh)); @@ -2790,7 +2809,7 @@ sub get_response_data_by_student { if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { # Clear the \'s from around the submission for (my $i =0;$i[$i]->[2] =~ s/(\'$|^\')//g; + $dataset->[$i]->[&RDs_submission] =~ s/(\'$|^\')//g; } return $dataset; }