function privatemsg_sql_messages

1 privatemsg.module privatemsg_sql_messages(&$fragments, $threads, $account = NULL, $load_all = FALSE)
7-1 privatemsg.module privatemsg_sql_messages($threads, $account = NULL, $load_all = FALSE)
7-2 privatemsg.module privatemsg_sql_messages($threads, $account = NULL, $load_all = FALSE)
6-2 privatemsg.module privatemsg_sql_messages(&$fragments, $threads, $account = NULL, $load_all = FALSE)

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 1095
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') // Order by timestamp first.
  ->orderBy('pm.timestamp', 'ASC') // 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.
  ->orderBy('pmi.mid', 'ASC');
  if ($account) {
    $query->condition('pmi.recipient', $account->uid)->condition('pmi.type', array('hidden', 'user'));
  }
  return $query;
}