Skip to content

Commit

Permalink
forums/trackreads: Small optimizations to forum_tp_can_track_forums()
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlanghoff committed Sep 2, 2005
1 parent 63b8c59 commit e1a3a68
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mod/forum/lib.php
Expand Up @@ -3459,6 +3459,12 @@ function forum_tp_get_untracked_forums($userid, $courseid=false) {
function forum_tp_can_track_forums($forum=false, $user=false) {
global $USER, $CFG;

// if possible, avoid expensive
// queries
if (empty($CFG->forum_trackreadposts)) {
return false;
}

if ($user === false) {
/// Must be logged in and not a guest.
$isauser = isloggedin() && !isguest();
Expand All @@ -3473,15 +3479,14 @@ function forum_tp_can_track_forums($forum=false, $user=false) {
} else {
/// Work toward always passing an object...
if (is_numeric($forum)) {
$forum = get_record('forum', 'id', $forum);
$forum = get_record('forum', 'id', $forum, '','','','', 'id,trackingtype');
}

$forumallows = ($forum->trackingtype == FORUM_TRACKING_OPTIONAL);
$forumforced = ($forum->trackingtype == FORUM_TRACKING_ON);
}

return ($isauser && $CFG->forum_trackreadposts &&
($forumforced || ($forumallows && !empty($user->trackforums))));
return ($isauser && ($forumforced || ($forumallows && !empty($user->trackforums))));
}

/**
Expand Down

0 comments on commit e1a3a68

Please sign in to comment.