You are here

function hosting_client_autocomplete in Hosting 7.3

Same name and namespace in other branches
  1. 5 client/hosting_client.module \hosting_client_autocomplete()
  2. 6.2 client/hosting_client.module \hosting_client_autocomplete()
  3. 7.4 client/hosting_client.module \hosting_client_autocomplete()

Retrieve autocomplete suggestions.

1 string reference to 'hosting_client_autocomplete'
hosting_client_menu in client/hosting_client.module
Implements hook_menu().

File

client/hosting_client.module, line 1081

Code

function hosting_client_autocomplete($type, $keyword) {
  $matches = array();
  if ($type == 'client') {

    // @todo Confirm that these are equivalent, especially the db_rewrite_sql -> addTag('node_access')
    // $query = db_query(db_rewrite_sql("SELECT * FROM {node} n WHERE type = '%s' AND title LIKE '%s%%'"), $type, addcslashes($keyword, '\%_'));
    $query = db_select('node', 'n')
      ->condition('type', $type);
    $query
      ->addField('n', 'title');
    $query = $query
      ->condition('title', '%' . $keyword . '%', 'LIKE')
      ->addTag('node_access');
    $result = $query
      ->execute();
    foreach ($result as $client) {
      $matches[$client->title] = $client->title;
    }
  }
  drupal_json_output($matches);
  exit;
}