--- loncom/interface/loncoursedata.pm 2003/10/02 20:48:57 1.100 +++ loncom/interface/loncoursedata.pm 2003/10/30 16:20:18 1.108 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.100 2003/10/02 20:48:57 matthew Exp $ +# $Id: loncoursedata.pm,v 1.108 2003/10/30 16:20:18 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1039,7 +1039,8 @@ sub get_student_id { $have_read_student_table = 1; } if (! exists($ids_by_student{$student})) { - &Apache::lonmysql::store_row($student_table,[undef,$student,undef]); + &Apache::lonmysql::store_row($student_table, + [undef,$student,undef]); undef(%ids_by_student); my @Result = &Apache::lonmysql::get_rows($student_table); foreach (@Result) { @@ -1222,6 +1223,7 @@ sub update_full_student_data { # However, there is one wrinkle: submissions which end in # and odd number of '\' cause insert errors to occur. # Best trap this somehow... + $value =~ s/\'/\\\'/g; my ($offensive_string) = ($value =~ /(\\+)$/); if (length($offensive_string) % 2) { $value =~ s/\\$/\\\\/; @@ -1248,6 +1250,7 @@ sub update_full_student_data { $store_command .= "('".join("','",$symb_id,$part_id, $student_id, $transaction, + $data->{'tries'}, $data->{'award'}, $data->{'awarded'}, $data->{'previous'})."'),"; @@ -1276,7 +1279,6 @@ sub update_full_student_data { $store_command .= "('".join("','",$symb_id,$part_id, $resp_id,$student_id, $transaction, - $data->{'tries'}, $data->{'awarddetail'}, $data->{'response_specific'}, $data->{'response_specific_value'}, @@ -1986,9 +1988,47 @@ sub execute_SQL_request { return (); } -sub get_optionresponse_data { +sub get_student_data { + my ($students,$courseid) = @_; + $courseid = $ENV{'request.course.id'} if (! defined($courseid)); + &setup_table_names($courseid); + my $dbh = &Apache::lonmysql::get_dbh(); + return undef if (! defined($dbh)); + my $request = 'SELECT '. + 'student_id, student '. + 'FROM '.$student_table; + if (defined($students)) { + $request .= ' WHERE ('. + join(' OR ', map {'student_id='. + &get_student_id($_->{'username'}, + $_->{'domain'}) + } @$students + ).')'; + } + $request.= ' ORDER BY student_id'; + my $sth = $dbh->prepare($request); + $sth->execute(); + if ($dbh->err) { + &Apache::lonnet::logthis('error = '.$dbh->errstr()); + return undef; + } + my $dataset = $sth->fetchall_arrayref(); + if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { + return $dataset; + } +} + +sub RD_student_id { return 0; } +sub RD_awarddetail { return 1; } +sub RD_response_eval { return 2; } +sub RD_submission { return 3; } +sub RD_timestamp { return 4; } +sub RD_tries { return 5; } +sub RD_sname { return 6; } + +sub get_response_data { my ($students,$symb,$response,$courseid) = @_; - return if (! defined($symb) || + return undef if (! defined($symb) || ! defined($response)); $courseid = $ENV{'request.course.id'} if (! defined($courseid)); # @@ -1999,7 +2039,8 @@ sub get_optionresponse_data { my $dbh = &Apache::lonmysql::get_dbh(); return undef if (! defined($dbh)); my $request = 'SELECT '. - 'a.response_specific_value, a.submission, b.timestamp, c.tries '. + 'a.student_id, a.awarddetail, a.response_specific_value, '. + 'a.submission, b.timestamp, c.tries, d.student '. 'FROM '.$fulldump_response_table.' AS a '. 'LEFT JOIN '.$fulldump_timestamp_table.' AS b '. 'ON a.symb_id=b.symb_id AND a.student_id=b.student_id AND '. @@ -2007,26 +2048,80 @@ sub get_optionresponse_data { 'LEFT JOIN '.$fulldump_part_table.' AS c '. 'ON a.symb_id=c.symb_id AND a.student_id=c.student_id AND '. 'a.part_id=c.part_id AND a.transaction = c.transaction '. + 'LEFT JOIN '.$student_table.' AS d '. + 'ON a.student_id=d.student_id '. 'WHERE '. 'a.symb_id='.$symb_id.' AND a.response_id='.$response_id; if (defined($students)) { $request .= ' AND ('. - join(' OR ', map {'student_id='. + join(' OR ', map {'a.student_id='. &get_student_id($_->{'username'}, $_->{'domain'}) } @$students ).')'; } $request .= ' ORDER BY b.timestamp'; - &Apache::lonnet::logthis("request =\n".$request); +# &Apache::lonnet::logthis("request =\n".$request); my $sth = $dbh->prepare($request); $sth->execute(); + if ($dbh->err) { + &Apache::lonnet::logthis('error = '.$dbh->errstr()); + return undef; + } my $dataset = $sth->fetchall_arrayref(); if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { - return @$dataset; + return $dataset; } } +sub RT_student_id { return 0; } +sub RT_awarded { return 1; } +sub RT_tries { return 2; } +sub RT_timestamp { return 3; } + +sub get_response_time_data { + my ($students,$symb,$part,$courseid) = @_; + return undef if (! defined($symb) || + ! defined($part)); + $courseid = $ENV{'request.course.id'} if (! defined($courseid)); + # + &setup_table_names($courseid); + my $symb_id = &get_symb_id($symb); + my $part_id = &get_part_id($part); + # + my $dbh = &Apache::lonmysql::get_dbh(); + return undef if (! defined($dbh)); + my $request = 'SELECT '. + 'a.student_id, a.awarded, a.tries, b.timestamp '. + 'FROM '.$fulldump_part_table.' AS a '. + 'NATURAL LEFT JOIN '.$fulldump_timestamp_table.' AS b '. +# 'ON a.symb_id=b.symb_id AND a.student_id=b.student_id AND '. +# 'a.transaction = b.transaction '. + 'WHERE '. + 'a.symb_id='.$symb_id.' AND a.part_id='.$part_id; + if (defined($students)) { + $request .= ' AND ('. + join(' OR ', map {'a.student_id='. + &get_student_id($_->{'username'}, + $_->{'domain'}) + } @$students + ).')'; + } + $request .= ' ORDER BY b.timestamp'; +# &Apache::lonnet::logthis("request =\n".$request); + my $sth = $dbh->prepare($request); + $sth->execute(); + if ($dbh->err) { + &Apache::lonnet::logthis('error = '.$dbh->errstr()); + return undef; + } + my $dataset = $sth->fetchall_arrayref(); + if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { + return $dataset; + } + +} + ################################################ ################################################