function privatemsg_sql_participants in Privatemsg 7
Same name and namespace in other branches
- 6.2 privatemsg.module \privatemsg_sql_participants()
- 6 privatemsg.module \privatemsg_sql_participants()
- 7.2 privatemsg.module \privatemsg_sql_participants()
Load all participants of a thread.
Parameters
$thread_id: Thread id from which the participants should be loaded.
$account: User account that should be considered when loading participants.
See also
hook_query_privatemsg_participants_alter()
Related topics
File
- ./
privatemsg.module, line 1145 - Allows users to send private messages to other users.
Code
function privatemsg_sql_participants($thread_id, $account = NULL) {
$query = db_select('pm_index', 'pmi');
$query
->leftJoin('users', 'u', "u.uid = pmi.recipient AND pmi.type IN ('user', 'hidden')");
$query
->fields('pmi', array(
'recipient',
'type',
))
->fields('u', array(
'name',
))
->condition('pmi.thread_id', $thread_id);
// If an account is provided, limit participants.
if ($account) {
$query
->condition(db_or()
->condition('pmi.type', 'hidden', '<>')
->condition(db_and()
->condition('pmi.type', 'hidden')
->condition('pmi.recipient', $account->uid)));
// Only load recipients of messages which are visible for that user.
$query
->where('(SELECT 1 FROM {pm_index} pmiu WHERE pmi.mid = pmiu.mid AND pmiu.recipient = :recipient LIMIT 1) = 1', array(
':recipient' => $account->uid,
));
}
else {
// If not, only limit participants to visible ones.
$query
->condition('pmi.type', 'hidden', '<>');
}
return $query
->groupBy('pmi.recipient')
->groupBy('u.name')
->groupBy('pmi.type');
}