function _user_stats_last_post in User Stats 6
Same name and namespace in other branches
- 5 user_stats.module \_user_stats_last_post()
- 7 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 490 - 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=%d AND uid=%d";
$all_content_types = node_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;
$max_node = db_result(db_query($sql, 1, $uid));
$sql = "SELECT MAX(timestamp) FROM {comments} c ";
$where = " WHERE c.status=%d AND c.uid=%d ";
$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;
$max_comments = db_result(db_query($sql, COMMENT_PUBLISHED, $uid));
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;
}
}
}
}