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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 18 Feb 2004 17:33:36 -0000


matthew		Wed Feb 18 12:33:36 2004 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  Added &get_response_data_by_student and associated routines.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.117 loncom/interface/loncoursedata.pm:1.118
--- loncom/interface/loncoursedata.pm:1.117	Tue Feb 17 14:56:30 2004
+++ loncom/interface/loncoursedata.pm	Wed Feb 18 12:33:35 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.117 2004/02/17 19:56:30 matthew Exp $
+# $Id: loncoursedata.pm,v 1.118 2004/02/18 17:33:35 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2113,6 +2113,59 @@
         }
         return $dataset;
     }
+}
+
+
+sub RDs_awarddetail   { return 3; }
+sub RDs_submission    { return 2; }
+sub RDs_timestamp     { return 1; }
+sub RDs_tries         { return 0; }
+
+sub get_response_data_by_student {
+    my ($student,$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 $student_id = &get_student_id($student->{'username'},
+                                     $student->{'domain'});
+    #
+    my $dbh = &Apache::lonmysql::get_dbh();
+    return undef if (! defined($dbh));
+    my $request = 'SELECT '.
+        'c.tries, b.timestamp, a.submission, a.awarddetail '.
+        '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 '.
+        'a.transaction = b.transaction '.
+        '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.
+        ' AND a.student_id='.$student_id.' 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) {
+        # Clear the \'s from around the submission
+        for (my $i =0;$i<scalar(@$dataset);$i++) {
+            $dataset->[$i]->[2] =~ s/(\'$|^\')//g;
+        }
+        return $dataset;
+    }
+    return undef; # error occurred
 }
 
 sub RT_student_id { return 0; }