[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 24 Oct 2003 13:34:45 -0000


matthew		Fri Oct 24 09:34:45 2003 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  Added &get_response_time_data.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.105 loncom/interface/loncoursedata.pm:1.106
--- loncom/interface/loncoursedata.pm:1.105	Mon Oct 20 16:42:39 2003
+++ loncom/interface/loncoursedata.pm	Fri Oct 24 09:34:45 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.105 2003/10/20 20:42:39 matthew Exp $
+# $Id: loncoursedata.pm,v 1.106 2003/10/24 13:34:45 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1039,7 +1039,8 @@
         $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) {
@@ -2061,6 +2062,49 @@
     if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) {
         return $dataset;
     }
+}
+
+sub get_response_time_data {
+    my ($students,$symb,$response,$courseid) = @_;
+    return undef if (! defined($symb) || 
+                     ! defined($response));
+    $courseid = $ENV{'request.course.id'} if (! defined($courseid));
+    #
+    &setup_table_names($courseid);
+    my $symb_id = &get_symb_id($symb);
+    my $response_id = &get_part_id($response);
+    #
+    my $dbh = &Apache::lonmysql::get_dbh();
+    return undef if (! defined($dbh));
+    my $request = 'SELECT '.
+        'a.student_id, a.awarddetail, b.timestamp '.
+        'FROM '.$fulldump_response_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.response_id='.$response_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;
+    }
+
 }
 
 ################################################