You are here

function _user_stats_last_post in User Stats 5

Same name and namespace in other branches
  1. 6 user_stats.module \_user_stats_last_post()
  2. 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 534
User Stats provides commonly requested user statistics for themers. These are:

Code

function _user_stats_last_post($account) {
  $sql = "SELECT MAX(created) FROM {node} WHERE status=%d AND uid=%d";
  $post_count_content_types = variable_get('user_stats_included_content_types', array());
  if (!empty($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, $account->uid));
  $sql = "SELECT MAX(timestamp) FROM {comments} c\n    INNER JOIN {node} n ON c.nid=n.nid\n    WHERE c.status=%d AND c.uid=%d";
  if (!empty($post_count_content_types)) {
    $where = ' AND n.type IN (' . $content_types . ')';
    $sql .= $where;
  }
  $max_comments = db_result(db_query($sql, COMMENT_PUBLISHED, $account->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;
      }
    }
  }
}