You are here

function privatemsg_user_autocomplete in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_user_autocomplete()
  2. 7.2 privatemsg.module \privatemsg_user_autocomplete()

Implements callback_recipient_autocomplete().

1 string reference to 'privatemsg_user_autocomplete'
privatemsg_privatemsg_recipient_type_info in ./privatemsg.module
Implements hook_privatemsg_recipient_type_info().

File

./privatemsg.module, line 2728
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;
}