You are here

function invite_user_autocomplete in Invite 7.2

Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.

1 string reference to 'invite_user_autocomplete'
invite_menu in ./invite.module
Implements hook_menu().

File

./invite.pages.inc, line 190
Page callbacks for invite module.

Code

function invite_user_autocomplete($string = '') {
  $matches = array();
  if ($string) {
    $result = db_select('users')
      ->fields('users', array(
      'name',
      'mail',
    ))
      ->condition(db_or()
      ->condition('name', db_like($string) . '%', 'LIKE')
      ->condition('mail', db_like($string) . '%', 'LIKE'))
      ->range(0, 10)
      ->execute();
    foreach ($result as $account) {
      $matches[$account->name] = check_plain($account->name . ' (' . $account->mail . ')');
    }
  }
  drupal_json_output($matches);
}