You are here

function wf_crm_get_states in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/utils.inc \wf_crm_get_states()

Get list of states, keyed by abbreviation rather than ID. FIXME use the api for this.

Parameters

null|int|string $param:

4 calls to wf_crm_get_states()
wf_crm_admin_component::alterForm in includes/wf_crm_admin_component.inc
Alter back-end webform component edit forms. Called by hook_form_alter() whenever editing a webform component.
wf_crm_webform_ajax::stateProvince in includes/wf_crm_webform_ajax.inc
Populate a state list based on chosen country
wf_crm_webform_postprocess::validateThisPage in includes/wf_crm_webform_postprocess.inc
Recursive validation callback for webform page submission
wf_crm_webform_preprocess::addResources in includes/wf_crm_webform_preprocess.inc
Add necessary js & css to the form

File

includes/utils.inc, line 128
Webform CiviCRM module's common utility functions.

Code

function wf_crm_get_states($param = NULL) {
  $ret = array();
  if (!$param || $param == 'default') {
    $config = CRM_Core_Config::singleton();
    if (!$param && !empty($config->provinceLimit)) {
      $param = implode(',', $config->provinceLimit);
    }
    else {
      $param = (int) $config->defaultContactCountry;
    }
  }
  else {
    $param = (int) $param;
  }
  $sql = "SELECT name AS label, UPPER(abbreviation) AS value FROM civicrm_state_province WHERE country_id IN ({$param}) ORDER BY name";
  $dao = CRM_Core_DAO::executeQuery($sql);
  while ($dao
    ->fetch()) {
    $ret[$dao->value] = $dao->label;
  }

  // Localize the state/province names if in an non-en_US locale
  $tsLocale = CRM_Utils_System::getUFLocale();
  if ($tsLocale != '' and $tsLocale != 'en_US') {
    $i18n = CRM_Core_I18n::singleton();
    $i18n
      ->localizeArray($ret, array(
      'context' => 'province',
    ));
    CRM_Utils_Array::asort($ret);
  }
  return $ret;
}