From 83da3d286ca6126b49aa0358f5f9117654a102a5 Mon Sep 17 00:00:00 2001 From: vyshane Date: Tue, 26 Sep 2006 08:37:56 +0000 Subject: [PATCH] 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. --- mod/forum/discuss.php | 26 ++++++++++++++++++-------- mod/forum/lib.php | 16 ++++++++++++++-- mod/forum/rsslib.php | 13 +++++++++++++ mod/forum/view.php | 27 +++++++++++++++++++++------ 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index cabb402b202..36620ce4f22 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -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); } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 4d1b13498fc..1bc243216a6 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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 "
"; - popup_form("discuss.php?d=$discussion&mode=", $FORUM_LAYOUT_MODES, "mode", $mode, ""); + if ($forumtype == 'single') { + popup_form("view.php?f=$id&mode=", $FORUM_LAYOUT_MODES, "mode", $mode, ""); + } else { + popup_form("discuss.php?d=$id&mode=", $FORUM_LAYOUT_MODES, "mode", $mode, ""); + } echo "
\n"; } diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index 01dd46f443b..02166cfbf77 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -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. diff --git a/mod/forum/view.php b/mod/forum/view.php index 95541c176fb..509023ecf08 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -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 ''; /// 2 ways to do this, 1. we can changed the setup_and_print_groups functions