You are here

function getlocations_blocks_country_get in Get Locations 7.2

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

Return value

array Provides an array for a countries dropdown

1 call to getlocations_blocks_country_get()
getlocations_blocks_country_form in modules/getlocations_blocks/getlocations_blocks.module

File

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

Code

function getlocations_blocks_country_get() {
  $settings = getlocations_blocks_get_var();
  $countries = array();
  if ($settings['country_full']) {
    $countries = getlocations_get_countries_list();
  }
  else {

    // need to make a list of existing countries, these are stored as 2 letter codes so need to be converted
    $query = db_select('getlocations_fields', 'f');
    $query
      ->fields('f', array(
      'country',
    ));
    if ($settings['country_filter'] && $settings['country_filter'] == 'field_name' && $settings['country_filter_fieldname']) {

      #      $query->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
      $query
        ->condition('f.field_name', $settings['country_filter_fieldname']);
    }
    elseif ($settings['country_filter'] && $settings['country_filter'] == 'bundle' && $settings['country_filter_bundle']) {

      #      $query->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
      $query
        ->join('field_config_instance', 'i', 'f.field_name=i.field_name');
      $query
        ->condition('i.bundle', $settings['country_filter_bundle']);
    }
    $result = $query
      ->execute();
    foreach ($result as $row) {
      $country = getlocations_get_country_name($row->country);
      $countries[$row->country] = $country;
    }
    asort($countries);
  }
  $newcountries = array(
    '' => t('Select a country'),
  );
  $newcountries += $countries;
  return $newcountries;
}