function privatemsg_sql_participants

1 privatemsg.module privatemsg_sql_participants(&$fragments, $thread_id)
7-1 privatemsg.module privatemsg_sql_participants($thread_id, $account = NULL)
7-2 privatemsg.module privatemsg_sql_participants($thread_id, $account = NULL)
6-2 privatemsg.module privatemsg_sql_participants(&$fragments, $thread_id, $account = NULL)

Load all participants of a thread.


$thread_id: Thread id from which the participants should be loaded.

$account: User account that should be considered when loading participants.

See also


Related topics


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


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('')->groupBy('pmi.type');