You are here

function getlocations_blocks_province_autocomplete in Get Locations 7

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

autocomplete for province

Parameters

string $string:

Return value

array provinces

1 string reference to 'getlocations_blocks_province_autocomplete'
getlocations_blocks_menu in modules/getlocations_blocks/getlocations_blocks.module
Implements hook_menu().

File

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

Code

function getlocations_blocks_province_autocomplete($string = '') {
  $settings = getlocations_blocks_get_var();
  $matches = array();
  if ($string) {
    $query = db_select('getlocations_fields', 'f');
    $query
      ->fields('f', array(
      'province',
    ));
    if ($settings['province_filter'] && $settings['province_filter'] == 'field_name' && $settings['province_filter_fieldname']) {
      $query
        ->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
      $query
        ->where("LOWER(f.province) LIKE LOWER(:st)", array(
        ':st' => $string . '%',
      ));
      $query
        ->condition('e.field_name', $settings['province_filter_fieldname']);
    }
    elseif ($settings['province_filter'] && $settings['province_filter'] == 'bundle' && $settings['province_filter_bundle']) {
      $query
        ->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
      $query
        ->join('field_config_instance', 'i', 'e.field_name=i.field_name');
      $query
        ->where("LOWER(f.province) LIKE LOWER(:st)", array(
        ':st' => $string . '%',
      ));
      $query
        ->condition('i.bundle', $settings['province_filter_bundle']);
    }
    else {
      $query
        ->where("LOWER(f.province) LIKE LOWER(:st)", array(
        ':st' => $string . '%',
      ));
    }
    $query
      ->range(0, 15);
    $result = $query
      ->execute();
    foreach ($result as $row) {
      $matches[$row->province] = check_plain($row->province);
    }
  }
  drupal_json_output($matches);
}