You are here

function privatemsg_sql_messages in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_sql_messages()
  2. 6 privatemsg.module \privatemsg_sql_messages()
  3. 7.2 privatemsg.module \privatemsg_sql_messages()

Query definition to load messages of one or multiple threads.

Parameters

$threads: Array with one or multiple thread id's.

$account: User object for which the messages are being loaded.

$load_all: Deleted messages are only loaded if this is set to TRUE.

See also

hook_query_privatemsg_messages_alter()

Related topics

File

./privatemsg.module, line 1109
Allows users to send private messages to other users.

Code

function privatemsg_sql_messages($threads, $account = NULL, $load_all = FALSE) {
  $query = db_select('pm_index', 'pmi');
  $query
    ->addField('pmi', 'mid');
  $query
    ->join('pm_message', 'pm', 'pm.mid = pmi.mid');
  if (!$load_all) {
    $query
      ->condition('pmi.deleted', 0);
  }

  // If there are multiple inserts during the same second (tests, for example)
  // sort by mid second to have them in the same order as they were saved.
  $query
    ->condition('pmi.thread_id', $threads)
    ->groupBy('pm.timestamp')
    ->groupBy('pmi.mid')
    ->orderBy('pm.timestamp', 'ASC')
    ->orderBy('pmi.mid', 'ASC');
  if ($account) {
    $query
      ->condition('pmi.recipient', $account->uid)
      ->condition('pmi.type', array(
      'hidden',
      'user',
    ));
  }
  return $query;
}