function getlocations_blocks_postalcode_autocomplete in Get Locations 7
Same name and namespace in other branches
- 7.2 modules/getlocations_blocks/getlocations_blocks.module \getlocations_blocks_postalcode_autocomplete()
autocomplete for postal codes
Parameters
string $string:
Return value
array postal codes
1 string reference to 'getlocations_blocks_postalcode_autocomplete'
- getlocations_blocks_menu in modules/
getlocations_blocks/ getlocations_blocks.module - Implements hook_menu().
File
- modules/
getlocations_blocks/ getlocations_blocks.module, line 775 - getlocations_blocks.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_blocks_postalcode_autocomplete($string = '') {
$settings = getlocations_blocks_get_var();
$matches = array();
if ($string) {
$query = db_select('getlocations_fields', 'f');
$query
->fields('f', array(
'postal_code',
));
if ($settings['postalcode_filter'] && $settings['postalcode_filter'] == 'field_name' && $settings['postalcode_filter_fieldname']) {
$query
->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
$query
->where("LOWER(f.postal_code) LIKE LOWER(:st)", array(
':st' => $string . '%',
));
$query
->condition('e.field_name', $settings['postalcode_filter_fieldname']);
}
elseif ($settings['postalcode_filter'] && $settings['postalcode_filter'] == 'bundle' && $settings['postalcode_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.postal_code) LIKE LOWER(:st)", array(
':st' => $string . '%',
));
$query
->condition('i.bundle', $settings['postalcode_filter_bundle']);
}
else {
$query
->where("LOWER(f.postal_code) LIKE LOWER(:st)", array(
':st' => $string . '%',
));
}
$query
->range(0, 15);
$result = $query
->execute();
foreach ($result as $row) {
$matches[$row->postal_code] = check_plain($row->postal_code);
}
}
drupal_json_output($matches);
}