Fix for MDL-3975. Also added function in rsslib.php to delete cached RSS feeds for the source and destination forums when moving a discussion between 2 forums.

This commit is contained in:
vyshane 2006-09-26 08:37:56 +00:00
parent d292466ca6
commit 83da3d286c
4 changed files with 66 additions and 16 deletions

View File

@ -6,12 +6,13 @@
require_once("../../config.php");
require_once("lib.php");
$d = required_param('d', PARAM_INT); // Discussion ID
$parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children.
$mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread
$move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum
$mark = optional_param('mark', 0, PARAM_INT); // Used for tracking read posts if user initiated.
$postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated.
$d = required_param('d', PARAM_INT); // Discussion ID
$parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children.
$mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread
$move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum
$fromforum = optional_param('fromforum', 0, PARAM_INT); // Needs to be set when we want to move a discussion.
$mark = optional_param('mark', 0, PARAM_INT); // Used for tracking read posts if user initiated.
$postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated.
if (!$discussion = get_record("forum_discussions", "id", $d)) {
error("Discussion ID was incorrect or no longer exists");
@ -47,6 +48,14 @@
if (!empty($move)) {
if (!$sourceforum = get_record('forum', 'id', $fromforum)) {
error('Cannot find which forum this discussion is being moved from');
}
if ($sourceforum->type == 'single') {
error('Cannot move discussion from a simple single discussion forum');
}
require_capability('mod/forum:movediscussions', $modcontext);
if ($forum = get_record("forum", "id", $move)) {
@ -62,13 +71,14 @@
add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
}
$discussionmoved = true;
require_once('rsslib.php');
require_once($CFG->libdir.'/rsslib.php');
// Delete the RSS files for the 2 forums because we want to force
// the regeneration of the feeds since the discussions have been
// moved.
if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($fromforum)) {
if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($sourceforum)) {
notify('Could not purge the cached RSS feeds for the source and/or'.
'destination forum(s) - check your file permissionsforums');
}
@ -205,7 +215,7 @@
}
$section = $courseforum->section;
if ($courseforum->id != $forum->id) {
$url = "discuss.php?d=$discussion->id&move=$courseforum->id";
$url = "discuss.php?d=$discussion->id&fromforum=$discussion->forum&move=$courseforum->id";
$forummenu[$url] = format_string($courseforum->name,true);
}
}

View File

@ -2397,11 +2397,23 @@ function forum_print_rating_menu($postid, $userid, $scale) {
choose_from_menu($scale, $postid, $rating->rating, "$strrate...");
}
function forum_print_mode_form($discussion, $mode) {
/**
* Print the drop down that allows the user to select how they want to have
* the discussion displayed.
* @param $id - forum id if $forumtype is 'single',
* discussion id for any other forum type
* @param $mode - forum layout mode
* @param $forumtype - optional
*/
function forum_print_mode_form($id, $mode, $forumtype='') {
GLOBAL $FORUM_LAYOUT_MODES;
echo "<div align=\"center\">";
popup_form("discuss.php?d=$discussion&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
if ($forumtype == 'single') {
popup_form("view.php?f=$id&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
} else {
popup_form("discuss.php?d=$id&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
}
echo "</div>\n";
}

View File

@ -68,6 +68,19 @@
return $status;
}
// Given a forum object, deletes the RSS file
function forum_rss_delete_file($forum) {
global $CFG;
$rssfile = rss_file_name('forum', $forum);
if (file_exists($rssfile)) {
return unlink($rssfile);
} else {
return true;
}
}
function forum_rss_newstuff($forum, $time) {
// If there is new stuff in the forum since $time then this returns
// true. Otherwise it returns false.

View File

@ -61,7 +61,7 @@
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Print header.
@ -70,10 +70,7 @@
"$navigation ".format_string($forum->name), "", "", true, $buttontext, navmenu($course, $cm));
/// Check whether the user should be able to view this forum.
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Some capability checks.
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
notice(get_string("activityiscurrentlyhidden"));
}
@ -101,7 +98,25 @@
/// Print settings and things in a table across the top
/// Print settings and things across the top
// If it's a simple single discussion forum, we need to print the display
// mode control.
if ($forum->type == 'single') {
if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
$discussion = array_pop($discussions);
}
}
if ($discussion) {
if ($mode) {
set_user_preference("forum_displaymode", $mode);
}
$displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
forum_print_mode_form($forum->id, $displaymode, $forum->type);
}
}
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
/// 2 ways to do this, 1. we can changed the setup_and_print_groups functions