Skip to content

Commit

Permalink
Added enable/disable forum tracking in a user profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchurch committed Apr 24, 2005
1 parent 38be9b3 commit 9e2b187
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion course/lib.php
Expand Up @@ -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.'">';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions mod/forum/db/mysql.php
Expand Up @@ -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;

}
Expand Down
8 changes: 8 additions & 0 deletions mod/forum/db/postgres7.php
Expand Up @@ -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;

}
Expand Down
15 changes: 15 additions & 0 deletions mod/forum/db/postgres7.sql
Expand Up @@ -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`
#
Expand Down
8 changes: 5 additions & 3 deletions mod/forum/index.php
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions mod/forum/lib.php
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Expand Up @@ -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;

Expand Down

0 comments on commit 9e2b187

Please sign in to comment.