From 058a2215efcadc3a6640a1a5fb7d7ae7587ff065 Mon Sep 17 00:00:00 2001
From: stronk7 <stronk7>
Date: Sun, 7 Sep 2003 21:36:03 +0000
Subject: [PATCH] Included journal_get_participants() function.

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

diff --git a/mod/journal/lib.php b/mod/journal/lib.php
index d126a26f6d..a8451b4f18 100644
--- a/mod/journal/lib.php
+++ b/mod/journal/lib.php
@@ -428,4 +428,33 @@ function journal_print_feedback($course, $entry, $grades) {
     echo "</TD></TR></TABLE>";
 }
 
+function journal_get_participants($journalid) {
+//Returns the users with data in one journal
+//(users with records in journal_entries, students and teachers)
+
+    global $CFG;
+
+    //Get students
+    $students = get_records_sql("SELECT DISTINCT u.*
+                                 FROM {$CFG->prefix}user u,
+                                      {$CFG->prefix}journal_entries j
+                                 WHERE j.journal = '$journalid' and
+                                       u.id = j.userid");
+    //Get teachers
+    $teachers = get_records_sql("SELECT DISTINCT u.*
+                                 FROM {$CFG->prefix}user u,
+                                      {$CFG->prefix}journal_entries j
+                                 WHERE j.journal = '$journalid' and
+                                       u.id = j.teacher");
+
+    //Add teachers to students
+    if ($teachers) {
+        foreach ($teachers as $teacher) {
+            $students[$teacher->id] = $teacher;
+        }
+    }
+    //Return students array (it contains an array of unique users)
+    return ($students);
+}
+
 ?>
-- 
2.39.5