function privatemsg_sql_participants in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg.module \privatemsg_sql_participants()
- 7.2 privatemsg.module \privatemsg_sql_participants()
- 7 privatemsg.module \privatemsg_sql_participants()
Load all participants of a thread.
Parameters
$fragments: Query fragments array.
$thread_id: Thread id from which the participants should be loaded.
Related topics
File
- ./
privatemsg.module, line 1186 - Allows users to send private messages to other users.
Code
function privatemsg_sql_participants(&$fragments, $thread_id, $account = NULL) {
$fragments['primary_table'] = '{pm_index} pmi';
// Only load each participant once since they are listed as recipient for
// every message of that thread.
$fragments['select'][] = 'pmi.recipient';
$fragments['select'][] = 'u.name';
$fragments['select'][] = 'pmi.type';
$fragments['inner_join'][] = "LEFT JOIN {users} u ON (u.uid = pmi.recipient AND pmi.type IN ('user', 'hidden'))";
$fragments['where'][] = 'pmi.thread_id = %d';
$fragments['query_args']['where'][] = $thread_id;
// If an account is provided, limit participants.
if ($account) {
$fragments['where'][] = "(pmi.type <> 'hidden') OR (pmi.type = 'hidden' AND pmi.recipient = %d)";
$fragments['query_args']['where'][] = $account->uid;
// Only load recipients of messages which are visible for that user.
$fragments['where'][] = '(SELECT 1 FROM {pm_index} pmiu WHERE pmi.mid = pmiu.mid AND pmiu.recipient = %d LIMIT 1) = 1';
$fragments['query_args']['where'][] = $account->uid;
}
else {
// If not, only limit participants to visible ones.
$fragments['where'][] = "pmi.type <> 'hidden'";
}
$fragments['group_by'][] = 'pmi.recipient';
$fragments['group_by'][] = 'u.name';
$fragments['group_by'][] = 'pmi.type';
}