function _user_stats_last_post in User Stats 7
Same name and namespace in other branches
- 5 user_stats.module \_user_stats_last_post()
- 6 user_stats.module \_user_stats_last_post()
Helper function to get the last post created by the user.
Parameters
$account: User object.
Return value
Unix timestamp: date of the last post (node or comment).
1 call to _user_stats_last_post()
- user_stats_get_stats in ./
user_stats.module - Returns user stats.
File
- ./
user_stats.module, line 486 - User Stats provides commonly requested user statistics for themers. These are:
Code
function _user_stats_last_post($uid) {
$sql = "SELECT MAX(created) FROM {node} WHERE status=:status AND uid=:uid";
$all_content_types = node_type_get_types();
$post_count_content_types = variable_get('user_stats_included_content_types', array());
$where = "";
// If some, but not all, content types have been selected in the admin
// interface add a WHERE clause to select only them.
if (!empty($post_count_content_types) && array_keys($all_content_types) != array_keys($post_count_content_types)) {
$content_types = "'" . implode("','", $post_count_content_types) . "'";
$where = ' AND type IN (' . $content_types . ')';
}
$sql .= $where;
// TODO Please convert this statement to the D7 database API syntax.
$max_node = db_query($sql, array(
':status' => COMMENT_PUBLISHED,
':uid' => $uid,
))
->fetchField();
$sql = "SELECT MAX(c.changed) FROM {comment} c ";
$where = " WHERE c.status=:status AND c.uid=:uid ";
$join = "";
if (!empty($post_count_content_types) && array_keys($all_content_types) != array_keys($post_count_content_types)) {
$join = " INNER JOIN {node} n ON c.nid=n.nid ";
$where .= 'AND n.type IN (' . $content_types . ')';
}
$sql .= $join . $where;
// TODO Please convert this statement to the D7 database API syntax.
$max_comments = db_query($sql, array(
':status' => COMMENT_PUBLISHED,
':uid' => $uid,
))
->fetchField();
if (is_null($max_node) && is_null($max_comments)) {
return FALSE;
}
else {
if ($max_node > $max_comments) {
return $max_node;
}
else {
if ($max_node <= $max_comments) {
return $max_comments;
}
}
}
}