Permalink
Browse files

Added the ability to mark discussions read.

  • Loading branch information...
1 parent 07e1a0e commit 20a3dad5746a765991139e5233efbd2d5070f387 mchurch committed Apr 25, 2005
Showing with 51 additions and 11 deletions.
  1. +2 −2 mod/forum/index.php
  2. +31 −2 mod/forum/lib.php
  3. +18 −7 mod/forum/markposts.php
View
@@ -139,7 +139,7 @@
$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></span>';
- $unreadlink .= ' <span style="font-size: 75%">' .
+ $unreadlink .= ' <span style="font-size: 0.7em">' .
'<a title="'.get_string('markallread', 'forum').'" href="markposts.php?id='.
$forum->id.'&mark=read">'.get_string('markread', 'forum').'</a></span>';
} else {
@@ -278,7 +278,7 @@
$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></span>';
- $unreadlink .= ' <span style="font-size: 75%">' .
+ $unreadlink .= ' <span style="font-size: 0.7em">' .
'<a title="'.get_string('markallread', 'forum').'" href="markposts.php?id='.
$forum->id.'&mark=read">'.get_string('markread', 'forum').'</a></span>';
} else {
View
@@ -1792,13 +1792,22 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
if ($CFG->forum_trackreadposts) {
echo '<td class="replies">';
if ($forumtracked) {
- echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#unread">';
if ($post->unread > 0) {
+ echo '<table align="center" cellpadding="0" cellspacing="0" border="0"><tr><td>';
+ echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#unread">';
echo '<span class="unread">'.$post->unread.'</span>';
+ echo '</a>';
+ echo '&nbsp;</td><td align="center">';
+ echo '<span class="lastpost">'.
+ '<a title="'.get_string('markalldread', 'forum').'" href="markposts.php?id='.
+ $forum->id.'&d='.$post->discussion.'&mark=read&returnpage=view.php">' .
+ get_string('markreadbutton', 'forum').'</a></span>';
+ echo '</td></tr></table>';
} else {
+ echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#unread">';
echo $post->unread;
+ echo '</a>';
}
- echo '</a>';
} else {
echo 'n/a';
}
@@ -3183,6 +3192,26 @@ function forum_tp_mark_forum_read($userid, $forumid, $groupid=false) {
}
}
+function forum_tp_mark_discussion_read($userid, $discussionid, $forumid) {
+/// Marks a whole discussion as read, for a given user
+ global $CFG;
+
+ $cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
+
+ $sql = 'SELECT p.id as postid, p.discussion as discussionid '.
+ 'FROM '.$CFG->prefix.'forum_posts p '.
+ 'LEFT JOIN '.$CFG->prefix.'forum_read r ON r.postid = p.id AND r.userid = '.$userid.' '.
+ 'WHERE p.discussion = '.$discussionid.' '.
+ '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, $forumid);
+ }
+ return true;
+ }
+}
+
function forum_tp_is_post_read($userid, &$post) {
return (forum_tp_is_post_old($post) ||
(get_record('forum_read', 'userid', $userid, 'postid', $post->id) !== false));
View
@@ -5,8 +5,10 @@
require_once("../../config.php");
require_once("lib.php");
- require_variable($id); // The forum to mark
- require_variable($mark); // Read or unread?
+ require_variable($id); // The forum to mark
+ require_variable($mark); // Read or unread?
+ optional_variable($d); // Discussion to mark.
+ optional_variable($returnpage, 'index.php'); // Page to return to.
if (! $forum = get_record("forum", "id", $id)) {
error("Forum ID was incorrect");
@@ -47,17 +49,26 @@
exit;
}
- $returnto = forum_go_back_to("index.php?id=$course->id");
+ $returnto = forum_go_back_to($returnpage.'?id='.$course->id.'&f='.$forum->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);
+ if (!empty($d)) {
+ if (forum_tp_mark_discussion_read($user->id, $d, $forum->id)) {
+ add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id);
+ redirect($returnto);
+ } else {
+ error("Could not mark that forum read.", $_SERVER["HTTP_REFERER"]);
+ }
} else {
- error("Could not mark that forum read.", $_SERVER["HTTP_REFERER"]);
+ 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"]);
+ }
}
/// FUTURE - Add ability to mark them as unread.

0 comments on commit 20a3dad

Please sign in to comment.