]> git.mjollnir.org Git - moodle.git/commitdiff
First version of support in groups in the forums.
authormoodler <moodler>
Sun, 11 Jan 2004 17:46:57 +0000 (17:46 +0000)
committermoodler <moodler>
Sun, 11 Jan 2004 17:46:57 +0000 (17:46 +0000)
Still needs plenty of testing.   There is no GUI yet for turning on
the groupmode just for the forum (this will be on the course page)
but you can put a 1 (visible) or 2 (separate) in the course_modules table.

mod/forum/discuss.php
mod/forum/lib.php
mod/forum/version.php
mod/forum/view.php

index 60cf79ef42cb21fee5a2fc3913ab46b5aeebaeab..b1b3cd15f0c5131d0e69a7f303a8ab5e5b4cc46a 100644 (file)
                  "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
     }
 
+/// Check to see if groups are being used in this forum
+/// If so, make sure the current person is allowed to see this discussion
+
+    $groupmode = groupmode($course, $cm);
+
+    if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id)) {   // Groups must be kept separate
+        require_login();
+        if (!$toppost = get_record("forum_posts", "id", $discussion->firstpost)) {
+            error("Could not find the top post of the discussion");
+        }
+        if (!$group = user_group($course->id, $toppost->userid)) {   // Find the topic's group
+            error("Could not find the appropriate group of this discussion");
+        }
+        if (mygroupid($course->id) != $group->id) {
+            print_heading("Sorry, you can't see this discussion because you are not in this group");
+            print_footer();
+            die;
+        }
+    }
+
+
     echo "<table width=\"100%\"><tr><td width=\"33%\">&nbsp;</td><td width=\"33%\">";
     forum_print_mode_form($discussion->id, $displaymode);
     echo "</td><td width=\"33%\">";
index edffc746a5b179a72bf9444957e7a14235689bb0..ffbce94b207282c0e486f28dcd73a614cc0b7409 100644 (file)
@@ -237,11 +237,29 @@ function forum_cron () {
                 continue;
             }
 
+            $groupmode = false;
+            if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+                if ($groupmode = groupmode($course, $cm)) {                  // Groups are being used
+                    if (!$group = user_group($course->id, $userfrom->id)) {  // If user not in a group
+                        continue;                                            // Be safe and don't send it to anyone
+                    }
+                }
+            } 
+
+
             if ($users = forum_subscribed_users($course, $forum)) {
                 $canunsubscribe = ! forum_is_forcesubscribed($forum->id);
 
                 $mailcount=0;
                 foreach ($users as $userto) {
+                    if ($groupmode) {    // Look for a reason not to send this email
+                        if (!isteacheredit($course->id, $userto->id)) {
+                            if (!ismember($group->id, $userto->id)) {
+                                continue;
+                            }
+                        }
+                    }
+                    
                     /// Override the language and timezone of the "current" user, so that 
                     /// mail is customised for the receiver.
                     $USER->lang     = $userto->lang;
@@ -820,7 +838,8 @@ function forum_count_unrated_posts($discussionid, $userid) {
     }
 }
 
-function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC", $user=0, $fullpost=true) {
+function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC", 
+                               $user=0, $fullpost=true, $currentgroup=0) {
 /// Get all discussions in a forum
     global $CFG;
 
@@ -837,14 +856,22 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC", $us
     } else {
         $postdata = "p.*";
     }
+    if ($currentgroup) {
+        $grouptable = ", {$CFG->prefix}groups_members gm ";
+        $groupselect = " AND gm.groupid = '$currentgroup' AND u.id = gm.userid ";
+    } else  {
+        $grouptable = "";
+        $groupselect = "";
+    }
+
     return get_records_sql("SELECT $postdata, d.timemodified, u.firstname, u.lastname, u.email, u.picture
                               FROM {$CFG->prefix}forum_discussions d, 
-                                   {$CFG->prefix}forum_posts p, 
-                                   {$CFG->prefix}user u 
+                                   {$CFG->prefix}forum_posts p,
+                                   {$CFG->prefix}user u $grouptable
                              WHERE d.forum = '$forum' 
                                AND p.discussion = d.id 
                                AND p.parent = 0 
-                               AND p.userid = u.id $userselect
+                               AND p.userid = u.id $groupselect $userselect
                           ORDER BY $forumsort");
 }
 
@@ -1923,7 +1950,7 @@ function forum_user_has_posted_discussion($forumid, $userid) {
     }
 }
 
-function forum_user_can_post_discussion($forum) {
+function forum_user_can_post_discussion($forum, $currentgroup=false) {
 // $forum is an object
     global $USER;
 
@@ -1931,6 +1958,8 @@ function forum_user_can_post_discussion($forum) {
         return (! forum_user_has_posted_discussion($forum->id, $USER->id));
     } else if ($forum->type == "teacher") {
         return isteacher($forum->course);
+    } else if ($currentgroup) {
+        return (isteacheredit($forum->course) or ismember($currentgroup));
     } else if (isteacher($forum->course)) {
         return true;
     } else {
@@ -1957,7 +1986,9 @@ function forum_user_can_post($forum, $user=NULL) {
 }
 
 
-function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $forum_style="plain", $forum_sort="") {
+function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, 
+                                        $forum_style="plain", $forum_sort="", 
+                                        $currentgroup=0) {
     global $CFG, $USER;
     
     if ($forum_id) {
@@ -1981,7 +2012,7 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f
         }
     }
 
-    if (forum_user_can_post_discussion($forum)) {
+    if (forum_user_can_post_discussion($forum, $currentgroup)) {
         echo "<p align=center>";
         echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">";
         if ($forum->type == "news") {
@@ -2005,7 +2036,7 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f
         $fullpost = true;
     }
 
-    if (! $discussions = forum_get_discussions($forum->id, $forum_sort, 0, $fullpost) ) {
+    if (! $discussions = forum_get_discussions($forum->id, $forum_sort, 0, $fullpost, $currentgroup) ) {
         if ($forum->type == "news") {
             echo "<p align=center><b>(".get_string("nonews", "forum").")</b></p>";
         } else {
index af0a26b03697aa411998fef5dd9368f5d23a4b6c..8f90df7474dcc61cc911874a5529394b863fdafa 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004010100;
+$module->version  = 2004010500;
 $module->cron     = 60;
 
 ?>
index 154c8b061588831cd90c736a287de23a8e24badb..e30f7ff4624892ed972a1dcb9041f8f394b4137d 100644 (file)
@@ -8,6 +8,7 @@
     optional_variable($mode);          // Display mode (for single forum)
     optional_variable($search, "");    // search string
     optional_variable($showall, "");   // show all discussions on one page
+    optional_variable($group, "");     // choose the current group
 
     $strforums = get_string("modulenameplural", "forum");
     $strforum = get_string("modulename", "forum");
         notice(get_string("activityiscurrentlyhidden"));
     }
 
+
+/// Check to see if groups are being used in this forum
+/// and if so, set $currentgroup to reflect the current group
+
+    $groupmode = groupmode($course, $cm);   // Groups are being used
+    $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
+
+    if ($groupmode and !$currentgroup) {
+        print_heading("Sorry, but you need to be part of a group to see this forum.");
+        print_footer();
+        exit;
+    }
+
+
+/// Print settings and things in a table across the top
+
+    echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
+
+    if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+        if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+            echo '<td>';
+
+            echo '<table><tr><td>';
+            if ($groupmode == VISIBLEGROUPS) {
+                print_string('groupsvisible');
+            } else {
+                print_string('groupsseparate');
+            }
+            echo ':';
+            echo '</td><td nowrap="nowrap" align="left" width="50%">';
+            popup_form("view.php?id=$cm->id&group=", $groups, 'selectgroup', $currentgroup, "", "", "", false, "self");
+            echo '</tr></table>';
+
+            echo '</td>';
+        }
+    }
+
+
     if ($USER) {
+        echo '<td align="right">';
         $SESSION->fromdiscussion = "$FULLME";
         if (forum_is_forcesubscribed($forum->id)) {
             $streveryoneissubscribed = get_string("everyoneissubscribed", "forum");
             $strallowchoice = get_string("allowchoice", "forum");
-            echo "<div align=right>";
             helpbutton("subscription", $streveryoneissubscribed, "forum");
             echo "<font size=1>";
             if (isteacher($course->id)) {
             } else {
                 echo $streveryoneissubscribed;
             }
-            echo "</font></div>";
+            echo "</font>";
 
         } else {
             $streveryonecanchoose = get_string("everyonecanchoose", "forum");
             $strforcesubscribe = get_string("forcesubscribe", "forum");
             $strshowsubscribers = get_string("showsubscribers", "forum");
 
-            echo "<div align=right>";
             helpbutton("subscription", $streveryonecanchoose, "forum");
             echo "<font size=1>";
 
             if (isteacher($course->id)) {
                 echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>";
-                echo "</font></div><div align=right><font size=1>";
+                echo "</font><br /><font size=1>";
                 echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>";
             } else {
                 echo $streveryonecanchoose;
             }
-            echo "</font></div>";
+            echo "</font>";
 
             if (forum_is_subscribed($USER->id, $forum->id)) {
                 $subtexttitle = get_string("subscribestop", "forum");
                 $subtexttitle = get_string("subscribestart", "forum");
                 $subtext = get_string("subscribe", "forum");
             }
-            echo "<div align=right>";
+            echo "<br />";
             echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>";
-            echo "</div>";
         }
+        echo '</td>';
     }
 
+    echo '</tr></table>';
+
 
     switch ($forum->type) {
-        case "single":
+        case 'single':
             if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
                 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
                     notify("Warning! There is more than one discussion in this forum - using the most recent");
             forum_print_discussion($course, $forum, $discussion, $post, $USER->mode);
             break;
 
-        case "eachuser":
+        case 'eachuser':
             if (!empty($forum->intro)) {
                 print_simple_box(text_to_html($forum->intro), "center");
             }
-            echo "<p align=\"center\">";
+            echo '<p align="center">';
             if (forum_user_can_post_discussion($forum)) {
                 print_string("allowsdiscussions", "forum");
             } else {
-                echo "&nbsp";
+                echo '&nbsp';
             }
-            echo "</p>";
+            echo '</p>';
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, "header");
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, "header");
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
             }
             break;
 
-        case "teacher":
+        case 'teacher':
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, "header");
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, "header");
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
             }
             break;
 
         default:
             if (!empty($forum->intro)) {
-                print_simple_box(text_to_html($forum->intro), "center");
+                print_simple_box(text_to_html($forum->intro), 'center');
             }
-            echo "<p>&nbsp;</p>";
+            echo '<p>&nbsp;</p>';
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, "header");
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, "header");
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
             }
             break;
     }