Improvements to forum groups.

New forum_discussions->groupid now stores the group ID for the
discussion.
This commit is contained in:
moodler 2004-01-23 12:09:25 +00:00
parent d26924c4ec
commit 02509fe667
11 changed files with 35 additions and 23 deletions

View File

@ -129,6 +129,7 @@
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

View File

@ -96,6 +96,10 @@ function forum_upgrade($oldversion) {
}
}
}
if ($oldversion < 2004012200) {
table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
}
return true;

View 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)

View File

@ -39,6 +39,9 @@ function forum_upgrade($oldversion) {
}
}
}
if ($oldversion < 2004012200) {
table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
}
return true;

View 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'
);

View File

@ -102,17 +102,10 @@
$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");
@ -121,9 +114,7 @@
}
} else if ($groupmode == VISIBLEGROUPS) {
if (mygroupid($course->id) == $group->id) {
$canreply = true;
}
$canreply = (mygroupid($course->id) == $discussion->groupid);
}
}

View 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;

View File

@ -105,6 +105,7 @@
<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>

View File

@ -138,6 +138,7 @@
$post->parent = 0;
$post->subject = "";
$post->userid = $USER->id;
$post->groupid = get_current_group($course->id);
$post->message = "";
$post->format = $defaultformat;
@ -161,6 +162,15 @@
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;

View File

@ -200,6 +200,7 @@
$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']['#']);

View File

@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2004011404;
$module->version = 2004012200;
$module->cron = 60;
?>