You are here

function imagepicker_user_autocomplete in Image Picker 7

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_user_autocomplete()
  2. 6.2 imagepicker.admin.inc \imagepicker_user_autocomplete()

Retrieve a pipe delimited string of autocomplete suggestions for existing users

1 string reference to 'imagepicker_user_autocomplete'
imagepicker_menu in ./imagepicker.module
Implement hook_menu().

File

./imagepicker.admin.inc, line 1735
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function imagepicker_user_autocomplete($string = '') {
  $matches = array();
  if ($string) {
    if (arg(4) == 'import' or arg(4) == 'orphans') {
      $query = db_select('users', 'u');
      $query
        ->fields('u', array(
        'uid',
        'name',
      ));
      $query
        ->where("LOWER(u.name) LIKE LOWER(:st)", array(
        ':st' => $string . '%',
      ));
      $query
        ->condition('u.status', 1);
      $query
        ->range(0, 10);
    }
    else {
      $query = db_select('users', 'u');
      $query
        ->fields('u', array(
        'name',
      ));
      $query
        ->distinct();
      $query
        ->join('imagepicker', 'i', 'u.uid = i.uid');
      $query
        ->where("LOWER(u.name) LIKE LOWER(:st)", array(
        ':st' => $string . '%',
      ));
      $query
        ->condition('u.status', 1);
      $query
        ->range(0, 10);
    }
    $result = $query
      ->execute();
    foreach ($result as $account) {
      if (arg(4) == 'import' or arg(4) == 'orphans') {
        $user = user_load($account->uid);
        if (user_access('use imagepicker', $user)) {
          $matches[$account->name] = check_plain($account->name);
        }
      }
      else {
        $matches[$account->name] = check_plain($account->name);
      }
    }
  }
  drupal_json_output($matches);
}