From 7be61a22e8e658547f2e4bec976ca98a236d8f06 Mon Sep 17 00:00:00 2001
From: stronk7 <stronk7>
Date: Sun, 7 Sep 2003 22:09:23 +0000
Subject: [PATCH] Included survey_get_participants() function.

---
 mod/survey/lib.php | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/mod/survey/lib.php b/mod/survey/lib.php
index 119c7e4efa..40e6d6e5a9 100644
--- a/mod/survey/lib.php
+++ b/mod/survey/lib.php
@@ -410,4 +410,33 @@ function survey_print_graph($url) {
     }
 }
 
+function survey_get_participants($surveyid) {
+//Returns the users with data in one survey
+//(users with records in survey_analysis and survey_answers, students)
+
+    global $CFG;
+
+    //Get students from survey_analysis
+    $st_analysis = get_records_sql("SELECT DISTINCT u.*    
+                                    FROM {$CFG->prefix}user u,
+                                         {$CFG->prefix}survey_analysis a
+                                    WHERE a.survey = '$surveyid' and
+                                          u.id = a.userid");
+    //Get students from survey_answers
+    $st_answers = get_records_sql("SELECT DISTINCT u.*    
+                                   FROM {$CFG->prefix}user u,
+                                        {$CFG->prefix}survey_answers a
+                                   WHERE a.survey = '$surveyid' and
+                                         u.id = a.userid");
+
+    //Add st_answers to st_analysis
+    if ($st_answers) {
+        foreach ($st_answers as $st_answer) {
+            $st_analysis[$st_answer->id] = $st_answer;
+        }
+    }
+    //Return st_analysis array (it contains an array of unique users)
+    return ($st_analysis);
+}
+
 ?>
-- 
2.39.5