Permalink
Browse files

More robust personal forum tracking logic. Added personal forum tracking

option setting to forum view page.
  • Loading branch information...
1 parent 2bc9f15 commit 45293cd330baa77901a0251e6be7db62825255c5 mchurch committed Apr 25, 2005
Showing with 36 additions and 20 deletions.
  1. +6 −6 mod/forum/index.php
  2. +12 −12 mod/forum/lib.php
  3. +1 −0 mod/forum/markposts.php
  4. +3 −2 mod/forum/settracking.php
  5. +14 −0 mod/forum/view.php
View
@@ -45,7 +45,7 @@
$generaltable->head[] = $strunreadposts;
$generaltable->align[] = 'center';
- if (forum_tp_is_tracked()) {
+ if (forum_tp_can_track_forums($USER->id)) {
$untracked = forum_tp_get_untracked_forums($USER->id);
}
$generaltable->head[] = $strtracking;
@@ -140,8 +140,8 @@
if ($unread > 0) {
$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>';
+ '<a title="'.get_string('markallread', 'forum').'" href="markposts.php?id='.
+ $forum->id.'&mark=read">'.get_string('markread', 'forum').'</a></span>';
} else {
$unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
}
@@ -273,14 +273,14 @@
}
if ($CFG->forum_trackreadposts) {
- if (forum_tp_is_tracked() && !isset($untracked[$forum->id])) {
+ if (forum_tp_can_track_forums($USER->id) && !isset($untracked[$forum->id])) {
$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></span>';
$unreadlink .= ' <span style="font-size: 75%">' .
- '<a title="Mark all read" href="markposts.php?id='.
- $forum->id.'&mark=read">mark read</a></span>';
+ '<a title="'.get_string('markallread', 'forum').'" href="markposts.php?id='.
+ $forum->id.'&mark=read">'.get_string('markread', 'forum').'</a></span>';
} else {
$unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a></span>';
}
View
@@ -1535,7 +1535,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
$strmarkunread = get_string('markunread', 'forum');
}
- if ($CFG->forum_trackreadposts && forum_tp_is_tracked($post->forum, $USER->id)) {
+ if (forum_tp_can_track_forums($USER->id) && forum_tp_is_tracked($post->forum, $USER->id)) {
if ($post_read == -99) { // If we don't know yet...
/// The front page can display a news item post to non-logged in users. This should
/// always appear as 'read'.
@@ -2588,7 +2588,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis
$strdatestring = get_string('strftimerecentfull');
/// Check if the forum is tracked.
- if ($CFG->forum_trackreadposts) {
+ if (forum_tp_can_track_forums($USER->id)) {
$forumtracked = forum_tp_is_tracked($forum->id, $USER->id);
} else {
$forumtracked = false;
@@ -2740,7 +2740,7 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode, $can
$post->subject = format_string($post->subject);
$forumtracked = forum_tp_is_tracked($forum->id, $USER->id);
- if ($CFG->forum_trackreadposts && $forumtracked) {
+ if (forum_tp_can_track_forums($USER->id) && $forumtracked) {
$user_read_array = forum_tp_get_discussion_read_records($USER->id, $post->discussion);
} else {
$user_read_array = array();
@@ -3314,22 +3314,22 @@ function forum_tp_get_untracked_forums($userid) {
return get_records('forum_track_prefs', 'userid', $userid, '', 'forumid,userid');
}
-/// Tells whether a specific forum is tracked, or if no forum specified, whether
-/// it is configured to allow tracking.
+/// Tells whether a user can track forums based on config variables.
+function forum_tp_can_track_forums($courseid=false, $forumid=false) {
+ global $USER, $CFG;
+
+ return ($CFG->forum_trackreadposts && $USER->trackforums);
+}
+
+/// Tells whether a specific forum is tracked.
function forum_tp_is_tracked($forumid=0, $userid=false) {
global $USER, $CFG;
if ($userid === false) {
$userid = $USER->id;
}
- if (!$CFG->forum_trackreadposts || !$USER->trackforums) {
- return false;
- } else if (empty($forumid)) {
- return true;
- } else {
- return (get_record('forum_track_prefs', 'userid', $userid, 'forumid', $forumid) === false);
- }
+ return (get_record('forum_track_prefs', 'userid', $userid, 'forumid', $forumid) === false);
}
function forum_tp_start_tracking($forumid, $userid=false) {
@@ -60,6 +60,7 @@
error("Could not mark that forum read.", $_SERVER["HTTP_REFERER"]);
}
+/// FUTURE - Add ability to mark them as unread.
// } 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);
@@ -5,7 +5,8 @@
require_once("../../config.php");
require_once("lib.php");
- require_variable($id); // The forum to subscribe or unsubscribe to
+ require_variable($id); // The forum to subscribe or unsubscribe to
+ optional_variable($returnpage, 'index.php'); // Page to return to.
if (! $forum = get_record("forum", "id", $id)) {
error("Forum ID was incorrect");
@@ -46,7 +47,7 @@
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);
View
@@ -153,6 +153,20 @@
echo "<span class=\"helplink\"><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></span>";
}
+ if (forum_tp_can_track_forums($USER->id)) {
+ if (forum_tp_is_tracked($forum->id, $USER->id)) {
+ $trtitle = get_string('notrackforum', 'forum');
+ $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" href="settracking.php?id='.
+ $forum->id.'&returnpage=view.php">'.get_string('notrackforum', 'forum').'</a>';
+ } else {
+ $trtitle = get_string('trackforum', 'forum');
+ $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" href="settracking.php?id='.
+ $forum->id.'&returnpage=view.php">'.get_string('trackforum', 'forum').'</a>';
+ }
+ echo "<br />";
+ echo "<span class=\"helplink\">$trackedlink</span>";
+ }
+
echo '</td>';
}

0 comments on commit 45293cd

Please sign in to comment.