Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the user forum tracking settings.

  • Loading branch information...
commit 38994d6ff74fdba07738d7b943750f8805c1f739 1 parent e2448b5
mchurch authored
View
10 mod/forum/db/mysql.php
@@ -191,6 +191,16 @@ function forum_upgrade($oldversion) {
$wtm->update( 'forum_posts','message','format',$sql );
}
+ if ($oldversion < 2005042300) { // Add tracking prefs table
+ modify_database('','CREATE TABLE prefix_forum_track_prefs (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `userid` int(10) NOT NULL default \'0\',
+ `forumid` int(10) NOT NULL default \'0\',
+ PRIMARY KEY (`id`),
+ KEY `user_forum_idx` (`userid`,`forumid`)
+ ) COMMENT=\'Tracks each users untracked forums.\';');
+ }
+
return true;
}
View
11 mod/forum/db/mysql.sql
@@ -137,6 +137,17 @@ CREATE TABLE prefix_forum_read (
) COMMENT='Tracks each users read posts';
#
+# Table structure for table `forum_track_prefs`
+#
+CREATE TABLE prefix_forum_track_prefs (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `userid` int(10) NOT NULL default '0',
+ `forumid` int(10) NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ KEY `user_forum_idx` (`userid`,`forumid`)
+) COMMENT='Tracks each users untracked forums.';
+
+#
# Dumping data for table `log_display`
#
View
48 mod/forum/index.php
@@ -30,6 +30,7 @@
$strdiscussions = get_string("discussions", "forum");
$strsubscribed = get_string("subscribed", "forum");
$strunreadposts = get_string("unreadposts", "forum");
+ $strtracking = get_string('tracking', 'forum');
$strrss = get_string("rss");
$searchform = forum_search_form($course);
@@ -43,6 +44,10 @@
if ($CFG->forum_trackreadposts) {
$generaltable->head[] = $strunreadposts;
$generaltable->align[] = 'center';
+
+ $untracked = forum_tp_get_untracked_forums($USER->id);
+ $generaltable->head[] = $strtracking;
+ $generaltable->align[] = 'center';
}
if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) {
@@ -127,12 +132,20 @@
}
if ($CFG->forum_trackreadposts) {
- $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>';
+ if (!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>';
+ } else {
+ $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ }
+ $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" ' .
+ 'href="settracking.php?id='.$forum->id.'">'.get_string('yes').'</a>';
} else {
- $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ $unreadlink = 'n/a';
+ $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" ' .
+ 'href="settracking.php?id='.$forum->id.'">'.get_string('no').'</a>';
}
}
@@ -188,6 +201,7 @@
$row = array ($forumlink, $forum->intro, $discussionlink);
if ($CFG->forum_trackreadposts) {
$row[] = $unreadlink;
+ $row[] = $trackedlink; // Tracking.
}
$row[] = $sublink;
if (!empty($rsslink)) {
@@ -198,6 +212,7 @@
$row = array ($forumlink, $forum->intro, $discussionlink);
if ($CFG->forum_trackreadposts) {
$row[] = $unreadlink;
+ $row[] = $trackedlink; // Tracking.
}
if (!empty($rsslink)) {
$row[] = $rsslink;
@@ -215,6 +230,9 @@
if ($CFG->forum_trackreadposts) {
$learningtable->head[] = $strunreadposts;
$learningtable->align[] = 'center';
+
+ $learningtable->head[] = $strtracking;
+ $learningtable->align[] = 'center';
}
if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) {
@@ -250,12 +268,20 @@
}
if ($CFG->forum_trackreadposts) {
- $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>';
+ if (!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>';
+ } else {
+ $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ }
+ $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" ' .
+ 'href="settracking.php?id='.$forum->id.'">'.get_string('yes').'</a>';
} else {
- $unreadlink = '<span class="read"><a href="view.php?f='.$forum->id.'">'.$unread.'</a>';
+ $unreadlink = 'n/a';
+ $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" ' .
+ 'href="settracking.php?id='.$forum->id.'">'.get_string('no').'</a>';
}
}
@@ -324,6 +350,7 @@
$row = array ($printsection, $forumlink, $forum->intro, $discussionlink);
if ($CFG->forum_trackreadposts) {
$row[] = $unreadlink;
+ $row[] = $trackedlink; // Tracking.
}
$row[] = $sublink;
if (!empty($rsslink)) {
@@ -335,6 +362,7 @@
$row = array ($printsection, $forumlink, $forum->intro, $discussionlink);
if ($CFG->forum_trackreadposts) {
$row[] = $unreadlink;
+ $row[] = $trackedlink; // Tracking.
}
if (!empty($rsslink)) {
$row[] = $rsslink;
View
45 mod/forum/lib.php
@@ -3056,6 +3056,8 @@ function forum_add_user($userid, $courseid) {
}
}
+/// Functions to do with read tracking.
+
function forum_tp_add_read_record($userid, $postid, $discussionid=-1, $forumid=-1) {
if (($readrecord = forum_tp_get_read_records($userid, $postid)) === false) {
/// New read record
@@ -3265,6 +3267,49 @@ function forum_tp_delete_read_records($userid=-1, $postid=-1, $discussionid=-1,
}
}
+/// Get a list of forums not being tracked by the user.
+function forum_tp_get_untracked_forums($userid) {
+ return get_records('forum_track_prefs', 'userid', $userid, '', 'forumid,userid');
+}
+
+function forum_tp_is_tracked($forumid, $userid=false) {
+ global $USER;
+
+ if ($userid === false) {
+ $userid = $USER->id;
+ }
+
+ return (get_record('forum_track_prefs', 'userid', $userid, 'forumid', $forumid) === false);
+}
+
+function forum_tp_start_tracking($forumid, $userid=false) {
+ global $USER;
+
+ if ($userid === false) {
+ $userid = $USER->id;
+ }
+
+ return delete_records('forum_track_prefs', 'userid', $userid, 'forumid', $forumid);
+}
+
+function forum_tp_stop_tracking($forumid, $userid=false) {
+ global $USER;
+
+ if ($userid === false) {
+ $userid = $USER->id;
+ }
+
+ $track_prefs = new stdClass;
+ $track_prefs->userid = $userid;
+ $track_prefs->forumid = $forumid;
+ if (insert_record('forum_track_prefs', $track_prefs)) {
+ return forum_tp_delete_read_records($userid, -1, -1, $forumid);
+ } else {
+ return false;
+ }
+}
+
+
/// Clean old records from the forum_read table.
function forum_tp_clean_read_records() {
global $CFG;
View
71 mod/forum/settracking.php
@@ -0,0 +1,71 @@
+<?php
+
+// Set tracking option for the forum.
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id); // The forum to subscribe or unsubscribe to
+
+ 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 tracking
+ $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 ( forum_tp_is_tracked($forum->id, $user->id) ) {
+ if (forum_tp_stop_tracking($forum->id, $user->id)) {
+ add_to_log($course->id, "forum", "stop tracking", "view.php?f=$forum->id", $forum->id, $cm->id);
+ redirect($returnto, get_string("nownottracking", "forum", $info), 1);
+ } else {
+ error("Could not stop tracking that forum", $_SERVER["HTTP_REFERER"]);
+ }
+
+ } else { // subscribe
+ if (forum_tp_start_tracking($forum->id, $user->id)) {
+ add_to_log($course->id, "forum", "start tracking", "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"]);
+ }
+ }
+
+?>
View
2  mod/forum/version.php
@@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2005041100;
+$module->version = 2005042300;
$module->requires = 2005031000; // Requires this Moodle version
$module->cron = 60;
Please sign in to comment.
Something went wrong with that request. Please try again.