You are here

function privatemsg_limits_sql_sent in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_limits/privatemsg_limits.module \privatemsg_limits_sql_sent()
  2. 7.2 privatemsg_limits/privatemsg_limits.module \privatemsg_limits_sql_sent()

SQL Function for amount of messages/threads a user has written in a timeframe.

Parameters

array $fragments Query array:

user $account User object:

int $timeframe how many seconds to consider.:

File

privatemsg_limits/privatemsg_limits.module, line 289
Privatemsg Quota module

Code

function privatemsg_limits_sql_sent($account, $timeframe) {
  $query = db_select('pm_message', 'pm');
  if (variable_get('privatemsg_limits_send_object', 'message') == 'thread') {
    $query
      ->addExpression('MAX(pm.timestamp)', 'timestamp');
    $query
      ->join('pm_index', 'pmi', 'pmi.mid = pm.mid');
    $query
      ->groupBy('pmi.thread_id');
  }
  else {
    $query
      ->addField('pm', 'timestamp');
  }
  return $query
    ->condition('pm.author', $account->uid)
    ->condition('pm.timestamp', REQUEST_TIME - $timeframe, '>')
    ->orderBy('timestamp', 'ASC');
}