Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the ability to mark all posts in a forum as read.

  • Loading branch information...
commit 331c512a10723d3254ee243a75a4a132a17eec92 1 parent 77e75a7
mchurch authored
Showing with 104 additions and 4 deletions.
  1. +9 −3 mod/forum/index.php
  2. +23 −1 mod/forum/lib.php
  3. +72 −0 mod/forum/markposts.php
View
12 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 = '<span class="unread"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ $unreadlink = '<span class="unread"><a href="view.php?f='.$forum->id.'">'.$unread.'</a></span>';
+ $unreadlink .= ' <span style="font-size: 75%">' .
+ '<a title="Mark all read" href="markposts.php?id='.
+ $forum->id.'&mark=read">mark read</a></span>';
} else {
$unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
}
@@ -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 = '<span class="unread"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ $unreadlink = '<span class="unread"><a href="view.php?f='.$forum->id.'">'.$unread.'</a></span>';
+ $unreadlink .= ' <span style="font-size: 75%">' .
+ '<a title="Mark all read" href="markposts.php?id='.
+ $forum->id.'&mark=read">mark read</a></span>';
} else {
- $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a></span>';
}
$trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" ' .
'href="settracking.php?id='.$forum->id.'">'.get_string('yes').'</a>';
View
24 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) {
View
72 mod/forum/markposts.php
@@ -0,0 +1,72 @@
+<?php
+
+// Set tracking option for the forum.
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id); // The forum to mark
+ require_variable($mark); // Read or unread?
+
+ if (! $forum = get_record("forum", "id", $id)) {
+ error("Forum ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $forum->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,
+ "<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\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
+ } else {
+ print_header($course->shortname, $course->fullname,
+ "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
+ <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
+ }
+ notice_yesno(get_string('noguesttracking', 'forum').'<br /><br />'.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"]);
+// }
+ }
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.