]> git.mjollnir.org Git - moodle.git/commitdiff
Improvements to forum groups.
authormoodler <moodler>
Fri, 23 Jan 2004 12:09:25 +0000 (12:09 +0000)
committermoodler <moodler>
Fri, 23 Jan 2004 12:09:25 +0000 (12:09 +0000)
New forum_discussions->groupid now stores the group ID for the
discussion.

mod/forum/backuplib.php
mod/forum/db/mysql.php
mod/forum/db/mysql.sql
mod/forum/db/postgres7.php
mod/forum/db/postgres7.sql
mod/forum/discuss.php
mod/forum/lib.php
mod/forum/post.html
mod/forum/post.php
mod/forum/restorelib.php
mod/forum/version.php

index 9b3228f37b63dc964aae75feed4f71cafd92cbf0..93fb789ea446b778c8d9e8c2ed0033276e9c0425 100644 (file)
                 fwrite ($bf,full_tag("NAME",6,false,$for_dis->name));
                 fwrite ($bf,full_tag("FIRSTPOST",6,false,$for_dis->firstpost));
                 fwrite ($bf,full_tag("USERID",6,false,$for_dis->userid));
+                fwrite ($bf,full_tag("GROUPID",6,false,$for_dis->groupid));
                 fwrite ($bf,full_tag("ASSESSED",6,false,$for_dis->assessed));
                 fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$for_dis->timemodified));
                 //Now print posts to xml
index 876fb243735a03e082f6da6ecb62cd84aa145c28..2b3f14a8b1213b6940026c8d7f785960a8a12ffe 100644 (file)
@@ -96,6 +96,10 @@ function forum_upgrade($oldversion) {
           }
       }
   }
+
+  if ($oldversion < 2004012200) {
+      table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
+  }
   
   return true;
 
index 66d0522268dd7baa18975a57ea72b65f0fbe4f53..4af670d89cdab5ad874a50a5e7162ed69a03de84 100644 (file)
@@ -33,6 +33,7 @@ CREATE TABLE prefix_forum_discussions (
   name varchar(255) NOT NULL default '',
   firstpost int(10) unsigned NOT NULL default '0',
   userid int(10) unsigned NOT NULL default '0',
+  groupid int(10) unsigned NOT NULL default '0',
   assessed tinyint(1) NOT NULL default '1',
   timemodified int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (id)
index f1e272e0a4d0f1f4289fa104df696002767f420e..e01ac76a5b8f30089a413e87e0d9014e4f567098 100644 (file)
@@ -39,6 +39,9 @@ function forum_upgrade($oldversion) {
           }
       }
   }
+  if ($oldversion < 2004012200) {
+      table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
+  }
 
   return true;
 
index 2e7095c640117e5d63bc984bdfe9c7d820967438..12abc5cded8e82c5f79b34dfee3a7d888a7cca35 100644 (file)
@@ -31,6 +31,7 @@ CREATE TABLE prefix_forum_discussions (
   name varchar(255) NOT NULL default '',
   firstpost integer NOT NULL default '0',
   userid integer NOT NULL default '0',
+  groupid integer NOT NULL default '0',
   assessed integer NOT NULL default '1',
   timemodified integer NOT NULL default '0'
 );
index 7271bb8b94f113dbd7c7915f15176a462065131b..ffdc43fcd96a035dfbd78e484d6a5ebebb261e2a 100644 (file)
     $groupmode = groupmode($course, $cm);
 
     if ($groupmode and !isteacheredit($course->id)) {   // Groups must be kept separate
-        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 ($groupmode == SEPARATEGROUPS) {
             require_login();
 
-            if (mygroupid($course->id) == $group->id) {
+            if (mygroupid($course->id) == $discussion->groupid) {
                 $canreply = true;
             } else {
                 print_heading("Sorry, you can't see this discussion because you are not in this group");
             }
 
         } else if ($groupmode == VISIBLEGROUPS) {
-            if (mygroupid($course->id) == $group->id) {
-                $canreply = true;
-            }
+            $canreply = (mygroupid($course->id) == $discussion->groupid);
         }
     }
 
index 77da89770cb02d49c4c4ced11a34b36fffd8159c..bd8c2efe6422257e4066d526ba181d42cb9fbafc 100644 (file)
@@ -897,6 +897,11 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
     } else {
         $userselect = "";
     }
+    if ($currentgroup) {
+        $groupselect = " AND d.groupid = '$currentgroup' ";
+    } else  {
+        $groupselect = "";
+    }
     if (empty($forumsort)) {
         $forumsort = "d.timemodified DESC";
     }
@@ -905,18 +910,11 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
     } 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 $grouptable
+                                   {$CFG->prefix}user u 
                              WHERE d.forum = '$forum' 
                                AND p.discussion = d.id 
                                AND p.parent = 0 
@@ -1144,12 +1142,12 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
     if ($ownpost) {
         $output .= "<a href=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum")."</a>";
         if ($reply) {
-            $output .= " | <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</a>";
+            $output .= " | <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum")."</a>";
         }
         $output .= "&nbsp;&nbsp;";
     } else {
         if ($reply) {
-            $output .= "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</a>&nbsp;&nbsp;";
+            $output .= "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum")."</a>&nbsp;&nbsp;";
         }
     }
 
@@ -1840,7 +1838,8 @@ function forum_add_discussion($discussion) {
         set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
     }
 
-    // Now do the real module entry
+    // Now do the main entry for the discussion, 
+    // linking to this first post
 
     $discussion->firstpost    = $post->id;
     $discussion->timemodified = $timenow;
index dabf7893e6530c00b93b56c0b910a5b5becfdf27..a496b727f75597e56dc5802ec13dd3ccbe47261f 100644 (file)
     <input type="hidden" name=discussion value="<?php p($post->discussion) ?>">
     <input type="hidden" name=parent     value="<?php p($post->parent) ?>">
     <input type="hidden" name=userid     value="<?php p($post->userid) ?>">
+    <input type="hidden" name=groupid    value="<?php p($post->groupid) ?>">
     <input type="hidden" name=edit       value="<?php p($post->edit) ?>">
     <input type="submit" value="<?php print_string("savechanges"); ?>">
     </td>
index 54cae5361d054c85ac3cd5ae3265d1d1f7548177..c0b97b83651913917cd8e27c2c574feb209fd707 100644 (file)
         $post->parent = 0;
         $post->subject = "";
         $post->userid = $USER->id;
+        $post->groupid = get_current_group($course->id);
         $post->message = "";
         $post->format = $defaultformat;
 
         if (! forum_user_can_post($forum)) {
             error("Sorry, but you can not post in this forum.");
         }
+
+        if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+            if (groupmode($course, $cm) and !isteacheredit($course->id)) {   // Make sure user can post here
+                if (mygroupid($course->id) != $discussion->groupid) {
+                    error("Sorry, but you can not post in this discussion.");
+                }
+            }
+        }
+
         // Load up the $post variable.
 
         $post->course  = $course->id;
index aee54b682e21fb9e60bfe5abdec98b92cab936e3..1a43726b7c0a47efc6b418b80a54a9e2b2962af9 100644 (file)
             $discussion->name = backup_todb($dis_info['#']['NAME']['0']['#']);
             $discussion->firstpost = backup_todb($dis_info['#']['FIRSTPOST']['0']['#']);
             $discussion->userid = backup_todb($dis_info['#']['USERID']['0']['#']);
+            $discussion->groupid = backup_todb($dis_info['#']['GROUPID']['0']['#']);
             $discussion->assessed = backup_todb($dis_info['#']['ASSESSED']['0']['#']);
             $discussion->timemodified = backup_todb($dis_info['#']['TIMEMODIFIED']['0']['#']);
 
index 7f1122084dba332c8801009c6d9ed47d266325b3..bd4dc68e5661c3dfdbcf58b1258c014918e80433 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004011404;
+$module->version  = 2004012200;
 $module->cron     = 60;
 
 ?>