function advanced_forum_markasread in Advanced Forum 7.2
Same name and namespace in other branches
- 5 advanced_forum.module \advanced_forum_markasread()
- 6.2 includes/mark-read.inc \advanced_forum_markasread()
- 6 advanced_forum.module \advanced_forum_markasread()
Marks all posts in forums or in a given forum as read by the current user.
1 string reference to 'advanced_forum_markasread'
- advanced_forum_menu in ./
advanced_forum.module - Implements hook_menu().
File
- includes/
mark-read.inc, line 31 - Holds functions relating to the Mark Forum/All Read functionality.
Code
function advanced_forum_markasread($tid = NULL) {
global $user;
$vid = variable_get('forum_nav_vocabulary', 0);
// Don't bother trying to mark things read for anonymous users.
if (empty($user->uid)) {
return;
}
// Delete all entries in the history table for the current $uid and
// optionally a forum term id.
// Subquery to find nids to delete from history table.
$query_node = db_select('node', 'n');
$query_node
->join('forum', 'f', 'n.vid = f.vid');
$query_node
->join('taxonomy_term_data', 't', 'f.tid = t.tid');
$query_node
->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
if (isset($tid)) {
$query_node
->condition('f.tid', $tid);
}
$query_node
->condition('t.vid', $vid);
$query_node
->addField('n', 'nid');
// Select query objects are one-shot, so clone for INSERT below.
$query_history_insert = clone $query_node;
// Delete values based upon sub-query.
$query = db_delete('history')
->condition('uid', $user->uid)
->condition('nid', $query_node, 'IN')
->execute();
// Now insert the nids into the history table.
$query_history_insert
->addExpression(':uid', 'uid', array(
':uid' => $user->uid,
));
$query_history_insert
->addExpression(':time', 'timestamp', array(
':time' => REQUEST_TIME,
));
db_insert('history')
->fields(array(
'nid',
'uid',
'timestamp',
))
->from($query_history_insert)
->execute();
drupal_goto(empty($tid) ? 'forum' : 'forum/' . $tid);
}