function privatemsg_user_autocomplete

7-1 privatemsg.module privatemsg_user_autocomplete($fragment, $names, $limit)
7-2 privatemsg.module privatemsg_user_autocomplete($fragment, $names, $limit)
6-2 privatemsg.module privatemsg_user_autocomplete($fragment, $names, $limit)

Implements callback_recipient_autocomplete().

1 string reference to 'privatemsg_user_autocomplete'

File

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

Code

function privatemsg_user_autocomplete($fragment, $names, $limit) {
  // First, load all possible uids.
  $uids = _privatemsg_assemble_query('autocomplete', $fragment, $names)->range(0, $limit)->execute()->fetchCol();
  $query = _privatemsg_assemble_query('autocomplete', $fragment, $names);
  $query->preExecute();
  $query->getArguments();
  // Load the corresponding users, make sure to not load any duplicates.
  $accounts = user_load_multiple(array_unique($uids));

  // Return them in an array with the correct recipient key.
  $suggestions = array();
  foreach ($accounts as $account) {
    $account->type = 'user';
    $account->recipient = $account->uid;
    $suggestions[privatemsg_recipient_key($account)] = $account;
  }
  return $suggestions;

}