]> git.mjollnir.org Git - moodle.git/commitdiff
Included forum_get_participants() function.
authorstronk7 <stronk7>
Sun, 7 Sep 2003 21:28:31 +0000 (21:28 +0000)
committerstronk7 <stronk7>
Sun, 7 Sep 2003 21:28:31 +0000 (21:28 +0000)
mod/forum/lib.php

index 51b8777c783c20a56c1dcf1a02e861772cb226c4..eccee98eb6f91976894a31ff1039479c5e466ef8 100644 (file)
@@ -2105,5 +2105,48 @@ function forum_set_display_mode($mode=0) {
     }
 }
 
+function forum_get_participants($forumid) {
+//Returns the users with data in one forum
+//(users with records in forum_subscriptions, forum_posts and forum_ratings, students)
+
+    global $CFG;
+
+    //Get students from forum_subscriptions
+    $st_subscriptions = get_records_sql("SELECT DISTINCT u.*
+                                         FROM {$CFG->prefix}user u,
+                                              {$CFG->prefix}forum_subscriptions s
+                                         WHERE s.forum = '$forumid' and
+                                               u.id = s.userid");
+    //Get students from forum_posts
+    $st_posts = get_records_sql("SELECT DISTINCT u.*
+                                 FROM {$CFG->prefix}user u,
+                                      {$CFG->prefix}forum_discussions d,
+                                      {$CFG->prefix}forum_posts p
+                                 WHERE d.forum = '$forumid' and
+                                       p.discussion = d.id and
+                                       u.id = p.userid");
+
+    //Get students from forum_ratings
+    $st_ratings = get_records_sql("SELECT DISTINCT u.*
+                                   FROM {$CFG->prefix}user u,
+                                        {$CFG->prefix}forum_discussions d,    
+                                        {$CFG->prefix}forum_posts p,
+                                        {$CFG->prefix}forum_ratings r
+                                   WHERE d.forum = '$forumid' and          
+                                         p.discussion = d.id and
+                                         r.post = p.id and
+                                         u.id = r.userid");
+
+    //Add st_posts to st_subscriptions
+    foreach ($st_posts as $st_post) {
+        $st_subscriptions[$st_post->id] = $st_post;
+    }
+    //Add st_ratings to st_subscriptions
+    foreach ($st_ratings as $st_rating) { 
+        $st_subscriptions[$st_rating->id] = $st_rating;
+    }
+    //Return st_subscriptions array (it contains an array of unique users)
+    return ($st_subscriptions);
+}
 
 ?>