You are here

function getlocations_blocks_province_get in Get Locations 7

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

Return value

array Provides an array for a province dropdown

1 call to getlocations_blocks_province_get()
getlocations_blocks_province_form in modules/getlocations_blocks/getlocations_blocks.module

File

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

Code

function getlocations_blocks_province_get() {
  $settings = getlocations_blocks_get_var();
  $matches = array(
    '' => t('Select a province'),
  );
  $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
      ->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
      ->condition('i.bundle', $settings['province_filter_bundle']);
  }
  $result = $query
    ->execute();
  foreach ($result as $row) {
    if ($row->province) {
      $matches[$row->province] = getlocations_apoclean($row->province);
    }
  }
  ksort($matches);
  return $matches;
}