Can now break off posts into a new discussion, see bug 673

This commit is contained in:
gustav_delius
2004-05-30 17:25:26 +00:00
parent 4c62719001
commit cf84431be0
4 changed files with 126 additions and 4 deletions
+5 -2
View File
@@ -27,7 +27,7 @@ $string['deletedpost'] = 'The post has been deleted';
$string['deletesure'] = 'Are you sure you want to delete this post?';
$string['discussion'] = 'Discussion';
$string['discussionmoved'] = 'This discussion has been moved to \'$a\'.';
$string['discussions'] = 'Discussions';
$string['discussionname'] = 'Discussion name';
$string['discussionsstartedby'] = 'Discussions started by $a';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by $a';
$string['discussthistopic'] = 'Discuss this topic';
@@ -86,7 +86,8 @@ $string['parent'] = 'Show parent';
$string['parentofthispost'] = 'Parent of this post';
$string['postadded'] = 'Your post was successfully added.<P>You have $a to edit it if you want to make any changes.';
$string['postincontext'] = 'See this post in context';
$string['postmailinfo'] = 'This is a copy of a message posted on the $a website.
$string['postmailinfo'] = 'This is a copy of a message posted on the $a website.
To add your reply via the website, click on this link:';
$string['postrating1'] = 'Mostly Separate Knowing';
$string['postrating2'] = 'Separate and Connected';
@@ -94,6 +95,8 @@ $string['postrating3'] = 'Mostly Connected Knowing';
$string['posts'] = 'Posts';
$string['postupdated'] = 'Your post was updated';
$string['processingpost'] = 'Processing post $a';
$string['prune'] = 'Break off';
$string['pruneheading'] = 'Break off post and move to a new discussion';
$string['rate'] = 'Rate';
$string['rating'] = 'Rating';
$string['ratingeveryone'] = 'Everyone can rate posts';
+23 -2
View File
@@ -890,7 +890,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
$postdata = "p.*";
}
return get_records_sql("SELECT $postdata, d.timemodified, d.usermodified,
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_discussions d,
{$CFG->prefix}forum_posts p,
@@ -1121,7 +1121,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
}
}
if ($reply) {
$output .= " | <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "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 {
@@ -1250,6 +1250,12 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?edit=$post->id\">$stredit</a> | ";
}
}
if (isteacheredit($courseid) and $post->parent) {
echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?prune=$post->id\" title=\"".get_string('pruneheading', 'forum').'">'.
get_string("prune", "forum")."</a> | ";
}
if ($ownpost or $isteacher) {
if (!record_exists("forum_posts", "parent", $post->id)) {
echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">$strdelete</a>";
@@ -2149,6 +2155,9 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
} else {
$ownpost=false;
}
// Use discussion name instead of subject of first post
$discussion->subject = $discussion->name;
switch ($forum_style) {
case "minimal":
if (!empty($CFG->filterall)) {
@@ -2452,4 +2461,16 @@ function forum_print_recent_mod_activity($activity, $course, $detail=false) {
return;
}
function forum_change_discussionid($postid, $discussionid) {
/// recursively sets the discussion field to $discussionid on $postid and all its children
/// used when pruning a post
set_field('forum_posts', 'discussion', $discussionid, 'id', $postid);
if ($posts = get_records('forum_posts', 'parent', $postid)) {
foreach ($posts as $post) {
forum_change_discussionid($post->id, $discussionid);
}
}
return true;
}
?>
+78
View File
@@ -322,6 +322,84 @@
die;
} else if (isset($prune)) { // Teacher is pruning
if (! $post = forum_get_post_full($prune)) {
error("Post ID was incorrect");
}
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
error("This post is not part of a discussion!");
}
if (! $forum = get_record("forum", "id", $discussion->forum)) {
error("The forum number was incorrect ($discussion->forum)");
}
if (!isteacher($forum->course)) {
error("You can't prune discussions!");
}
if (!$post->parent) {
error('This is already the first post in the discussion');
}
if (isset($_REQUEST['name'])) { // User has confirmed the prune
$newdiscussion->course = $discussion->course;
$newdiscussion->forum = $discussion->forum;
$newdiscussion->name = $name;
$newdiscussion->firstpost = $post->id;
$newdiscussion->userid = $discussion->userid;
$newdiscussion->groupid = $discussion->groupid;
$newdiscussion->assessed = $discussion->assessed;
$newdiscussion->usermodified = $post->userid;
if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
error('Could not create new discussion');
}
set_field('forum_posts', 'parent', 0, 'id', $post->id);
forum_change_discussionid($post->id, $newid);
// set timemodified to time of last post in each discussion
$lastpost = get_record_sql("SELECT MAX(modified) AS time
FROM {$CFG->prefix}forum_posts
WHERE discussion = '$discussion->id'");
set_field('forum_discussions', 'timemodified', $lastpost->time, 'id', $discussion->id);
$lastpost = get_record_sql("SELECT MAX(modified) AS time
FROM {$CFG->prefix}forum_posts
WHERE discussion = '$newid'");
set_field('forum_discussions', 'timemodified', $lastpost->time, 'id', $newid);
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
$cm->id = 0;
}
add_to_log($discussion->course, "forum", "prune post",
"discuss.php?d=$newid", "$post->id", $cm->id);
redirect(forum_go_back_to("discuss.php?d=$newid"),
get_string("prunedpost", "forum"), 1);
} else { // User just asked to prune something
$course = get_record('course', 'id', $forum->course);
$strforums = get_string("modulenameplural", "forum");
print_header("$course->shortname: $discussion->name: $post->subject", "$course->fullname",
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
<A HREF=\"../forum/index.php?id=$course->id\">$strforums</A> ->
<A HREF=\"view.php?f=$forum->id\">$forum->name</A> ->
<A HREF=\"discuss.php?d=$discussion->id\">$post->subject</A> -> ".
get_string("prune", "forum"), '', "", true, "", navmenu($course, $cm));
print_heading(get_string('pruneheading', 'forum'));
echo '<CENTER>';
include('prune.html');
forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
}
die;
} else {
error("No operation specified");
+20
View File
@@ -0,0 +1,20 @@
<form name="prune" method="get" action="post.php" enctype="multipart/form-data">
<table border="0" cellpadding="5">
<tr valign="top">
<td align=right><p><b><?php print_string("discussionname", "forum"); ?>:</b></p></td>
<td>
<input type="text" name="name" size=60 value="<?php p($post->subject) ?>">
</td>
</tr>
<tr>
<td align=center colspan=2>
<input type="hidden" name=prune value="<?php p($prune) ?>">
<input type="hidden" name=confirm value="<?php p($prune) ?>">
<input type="submit" value="<?php print_string('prune', 'forum'); ?>">
</td>
</tr>
</table>
</form>