You are here

function getlocations_search_term_autocomplete in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_search/getlocations_search.module \getlocations_search_term_autocomplete()

autocomplete for taxonomy terms

Parameters

string $string:

Return value

Returns term names

1 string reference to 'getlocations_search_term_autocomplete'
getlocations_search_menu in modules/getlocations_search/getlocations_search.module
Implements hook_menu().

File

modules/getlocations_search/getlocations_search.module, line 1226
getlocations_search.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_search_term_autocomplete($string) {
  $matches = array();

  // Taxonomy which holds locative info
  $getlocations_search_defaults = getlocations_search_defaults();
  $vid = FALSE;
  if (is_numeric($getlocations_search_defaults['vocab']) && $getlocations_search_defaults['vocab'] > 0) {
    $vid = $getlocations_search_defaults['vocab'];
  }
  if ($vid) {
    $query = db_select('taxonomy_term_data', 't');
    $query
      ->fields('t', array(
      'name',
    ))
      ->where("LOWER(name) LIKE LOWER(:st)", array(
      ':st' => $string . '%',
    ))
      ->condition('t.vid', $vid, '=')
      ->range(0, 15);
    $result = $query
      ->execute();
    foreach ($result as $row) {
      $matches[$row->name] = check_plain($row->name);
    }
  }
  drupal_json_output($matches);
}