From cf84431be03434e4f565cb1718b99c6ba9a49224 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sun, 30 May 2004 17:25:26 +0000 Subject: [PATCH] Can now break off posts into a new discussion, see bug 673 --- lang/en/forum.php | 7 ++-- mod/forum/lib.php | 25 ++++++++++++-- mod/forum/post.php | 78 ++++++++++++++++++++++++++++++++++++++++++++ mod/forum/prune.html | 20 ++++++++++++ 4 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 mod/forum/prune.html diff --git a/lang/en/forum.php b/lang/en/forum.php index 3a7985223d..e9111b5824 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -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.

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'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 26282b8ddc..affd53e6bb 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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 .= " | wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum").""; + $output .= "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum").""; } $output .= "  "; } else { @@ -1250,6 +1250,12 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link echo "wwwroot/mod/forum/post.php?edit=$post->id\">$stredit | "; } } + + if (isteacheredit($courseid) and $post->parent) { + echo "wwwroot/mod/forum/post.php?prune=$post->id\" title=\"".get_string('pruneheading', 'forum').'">'. + get_string("prune", "forum")." | "; + } + if ($ownpost or $isteacher) { if (!record_exists("forum_posts", "parent", $post->id)) { echo "wwwroot/mod/forum/post.php?delete=$post->id\">$strdelete"; @@ -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; +} + ?> diff --git a/mod/forum/post.php b/mod/forum/post.php index 3cb52a5ece..b5dc779c88 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -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", + "id>$course->shortname -> + id\">$strforums -> + id\">$forum->name -> + id\">$post->subject -> ". + get_string("prune", "forum"), '', "", true, "", navmenu($course, $cm)); + + print_heading(get_string('pruneheading', 'forum')); + echo '

'; + + include('prune.html'); + + forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false); + } + + die; + + } else { error("No operation specified"); diff --git a/mod/forum/prune.html b/mod/forum/prune.html new file mode 100644 index 0000000000..1f25b93962 --- /dev/null +++ b/mod/forum/prune.html @@ -0,0 +1,20 @@ +
+ + + + + + + + + + + +

:

+ +
+ + + +
+
-- 2.39.5