Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added enable/disable forum tracking in a user profile.

  • Loading branch information...
commit 9e2b1877e025a7bcabd5e85cb0b06fb52bf546d4 1 parent 38be9b3
mchurch authored
2  course/lib.php
View
@@ -1028,7 +1028,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
$groupid = ($groupmode == SEPARATEGROUPS && !isteacheredit($course->id)) ?
get_current_group($course->id) : false;
- if (!isset($untracked[$mod->instance])) {
+ if (forum_tp_is_tracked() && !isset($untracked[$mod->instance])) {
$unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
if ($unread) {
echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
1  lang/en/moodle.php
View
@@ -1031,6 +1031,7 @@
$string['topicoutline'] = 'Topic outline';
$string['topicshow'] = 'Show this topic to $a';
$string['total'] = 'Total';
+$string['trackforums'] = 'Track read/unread posts';
$string['trysearching'] = 'Try searching instead.';
$string['turneditingoff'] = 'Turn editing off';
$string['turneditingon'] = 'Turn editing on';
5 mod/forum/db/mysql.php
View
@@ -201,6 +201,11 @@ function forum_upgrade($oldversion) {
) COMMENT=\'Tracks each users untracked forums.\';');
}
+ if ($oldversion < 2005042301) { // Add user tracking prefs field.
+ modify_database('','ALTER TABLE prefix_user ADD
+ `trackforums` TINYINT( 1 ) UNSIGNED DEFAULT \'1\' NOT NULL AFTER `autosubscribe` ;');
+ }
+
return true;
}
8 mod/forum/db/postgres7.php
View
@@ -133,6 +133,14 @@ 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 SERIAL PRIMARY KEY,
+ userid integer default 0 NOT NULL,
+ forumid integer default 0 NOT NULL
+ );');
+ }
+
return true;
}
15 mod/forum/db/postgres7.sql
View
@@ -144,6 +144,21 @@ CREATE INDEX prefix_forum_user_post_idx ON prefix_forum_read (userid, postid);
# --------------------------------------------------------
+
+#
+# Table structure for table `forum_track_prefs`
+#
+
+CREATE TABLE prefix_forum_track_prefs (
+ id SERIAL PRIMARY KEY,
+ userid integer NOT NULL default '0',
+ forumid integer NOT NULL default '0'
+);
+
+CREATE INDEX user_forum_idx ON prefix_forum_track_prefs (userid, forumid);
+
+
+# --------------------------------------------------------
#
# Dumping data for table `log_display`
#
8 mod/forum/index.php
View
@@ -45,7 +45,9 @@
$generaltable->head[] = $strunreadposts;
$generaltable->align[] = 'center';
- $untracked = forum_tp_get_untracked_forums($USER->id);
+ if (forum_tp_is_tracked()) {
+ $untracked = forum_tp_get_untracked_forums($USER->id);
+ }
$generaltable->head[] = $strtracking;
$generaltable->align[] = 'center';
}
@@ -132,7 +134,7 @@
}
if ($CFG->forum_trackreadposts) {
- if (!isset($untracked[$forum->id])) {
+ if (forum_tp_is_tracked() && !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) {
@@ -268,7 +270,7 @@
}
if ($CFG->forum_trackreadposts) {
- if (!isset($untracked[$forum->id])) {
+ if (forum_tp_is_tracked() && !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) {
14 mod/forum/lib.php
View
@@ -3286,14 +3286,22 @@ 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;
+/// Tells whether a specific forum is tracked, or if no forum specified, whether
+/// it is configured to allow tracking.
+function forum_tp_is_tracked($forumid=0, $userid=false) {
+ global $USER, $CFG;
if ($userid === false) {
$userid = $USER->id;
}
- return (get_record('forum_track_prefs', 'userid', $userid, 'forumid', $forumid) === false);
+ 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);
+ }
}
function forum_tp_start_tracking($forumid, $userid=false) {
2  mod/forum/version.php
View
@@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2005042300;
+$module->version = 2005042301;
$module->requires = 2005031000; // Requires this Moodle version
$module->cron = 60;
Please sign in to comment.
Something went wrong with that request. Please try again.