From 331c512a10723d3254ee243a75a4a132a17eec92 Mon Sep 17 00:00:00 2001 From: mchurch Date: Mon, 25 Apr 2005 03:56:02 +0000 Subject: [PATCH] Added the ability to mark all posts in a forum as read. --- mod/forum/index.php | 12 +++++-- mod/forum/lib.php | 24 +++++++++++++- mod/forum/markposts.php | 72 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 mod/forum/markposts.php diff --git a/mod/forum/index.php b/mod/forum/index.php index 393d64f802b..58de2b4a12c 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -138,7 +138,10 @@ $groupid = ($groupmode==SEPARATEGROUPS && !isteacheredit($course->id)) ? $currentgroup : false; $unread = forum_tp_count_forum_unread_posts($USER->id, $forum->id, $groupid); if ($unread > 0) { - $unreadlink = ''.$unread.''; + $unreadlink = ''.$unread.''; + $unreadlink .= ' ' . + 'mark read'; } else { $unreadlink = ''.$unread.''; } @@ -274,9 +277,12 @@ $groupid = ($groupmode==SEPARATEGROUPS && !isteacheredit($course->id)) ? $currentgroup : false; $unread = forum_tp_count_forum_unread_posts($USER->id, $forum->id, $groupid); if ($unread > 0) { - $unreadlink = ''.$unread.''; + $unreadlink = ''.$unread.''; + $unreadlink .= ' ' . + 'mark read'; } else { - $unreadlink = ''.$unread.''; + $unreadlink = ''.$unread.''; } $trackedlink = ''.get_string('yes').''; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 5b01eb0ab63..b4f23a6de06 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3157,8 +3157,30 @@ function forum_tp_mark_post_read($userid, &$post, $forumid) { } } -function forum_tp_mark_forum_read($userid, $forumid) { +function forum_tp_mark_forum_read($userid, $forumid, $groupid=false) { /// We need a proper LEFT JOIN in here to find posts without read records + global $CFG; + + $cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0; + + $groupsel = ''; + if ($groupid !== false) { + $groupsel = ' AND (d.groupid = '.$groupid.' OR d.groupid = -1)'; + } + + $sql = 'SELECT p.id as postid, d.id as discussionid, d.forum as forumid '. + 'FROM '.$CFG->prefix.'forum_posts p '. + 'LEFT JOIN '.$CFG->prefix.'forum_discussions d ON p.discussion = d.id '. + 'LEFT JOIN '.$CFG->prefix.'forum_read r ON r.postid = p.id AND r.userid = '.$userid.' '. + 'WHERE d.forum = '.$forumid.$groupsel. + ' AND p.modified >= '.$cutoffdate.' AND r.id is NULL'; + + if ($posts = get_records_sql($sql)) { + foreach ($posts as $post) { + forum_tp_add_read_record($userid, $post->postid, $post->discussionid, $post->forumid); + } + return true; + } } function forum_tp_is_post_read($userid, &$post) { diff --git a/mod/forum/markposts.php b/mod/forum/markposts.php new file mode 100644 index 00000000000..dc5dc2043e5 --- /dev/null +++ b/mod/forum/markposts.php @@ -0,0 +1,72 @@ +course)) { + error("Forum doesn't belong to a course!"); + } + + if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) { + $cm->id = NULL; + } + + $user = $USER; + + require_course_login($course, false, $cm); + + if (isguest()) { // Guests can't change forum + $wwwroot = $CFG->wwwroot.'/login/index.php'; + if (!empty($CFG->loginhttps)) { + $wwwroot = str_replace('http','https', $wwwroot); + } + + $strforums = get_string('modulenameplural', 'forum'); + if ($course->category) { + print_header($course->shortname, $course->fullname, + "id\">$course->shortname -> + id\">$strforums -> + id\">".format_string($forum->name,true)."", '', '', true, "", navmenu($course, $cm)); + } else { + print_header($course->shortname, $course->fullname, + "id\">$strforums -> + id\">".format_string($forum->name,true)."", '', '', true, "", navmenu($course, $cm)); + } + notice_yesno(get_string('noguesttracking', 'forum').'

'.get_string('liketologin'), + $wwwroot, $_SERVER['HTTP_REFERER']); + print_footer($course); + exit; + } + + $returnto = forum_go_back_to("index.php?id=$course->id"); + + $info->name = fullname($user); + $info->forum = format_string($forum->name); + + if ($mark == 'read') { + if (forum_tp_mark_forum_read($user->id, $forum->id)) { + add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id); + redirect($returnto); + } else { + error("Could not mark that forum read.", $_SERVER["HTTP_REFERER"]); + } + +// } else { // subscribe +// if (forum_tp_start_tracking($forum->id, $user->id)) { +// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id); +// redirect($returnto, get_string("nowtracking", "forum", $info), 1); +// } else { +// error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]); +// } + } + +?>