function privatemsg_sql_messages in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg.module \privatemsg_sql_messages()
- 7.2 privatemsg.module \privatemsg_sql_messages()
- 7 privatemsg.module \privatemsg_sql_messages()
Query definition to load messages of one or multiple threads.
Parameters
$fragments: Query fragments array.
$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.
Related topics
File
- ./
privatemsg.module, line 1151 - Allows users to send private messages to other users.
Code
function privatemsg_sql_messages(&$fragments, $threads, $account = NULL, $load_all = FALSE) {
$fragments['primary_table'] = '{pm_index} pmi';
$fragments['select'][] = 'pmi.mid';
$fragments['where'][] = 'pmi.thread_id IN (' . db_placeholders($threads) . ')';
$fragments['query_args']['where'] += $threads;
$fragments['inner_join'][] = 'INNER JOIN {pm_message} pm ON (pm.mid = pmi.mid)';
if ($account) {
$fragments['where'][] = "pmi.recipient = %d AND pmi.type IN ('user', 'hidden')";
$fragments['query_args']['where'][] = $account->uid;
}
if (!$load_all) {
// Also load deleted messages when requested.
$fragments['where'][] = 'pmi.deleted = 0';
}
// Only load each mid once.
$fragments['group_by'][] = 'pmi.mid';
$fragments['group_by'][] = 'pm.timestamp';
// Order by timestamp first.
$fragments['order_by'][] = '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.
$fragments['order_by'][] = 'pmi.mid ASC';
}