function wf_crm_state_abbr in Webform CiviCRM Integration 7.3
Same name and namespace in other branches
- 7.5 includes/utils.inc \wf_crm_state_abbr()
- 7.4 includes/utils.inc \wf_crm_state_abbr()
Match a state/province id to its abbr. and vice-versa
Parameters
$input: User input (state province id or abbr)
$ret: String: 'abbreviation' or 'id'
$country_id: Int: (optional) must be supplied if fetching id from abbr
Return value
string or integer
4 calls to wf_crm_state_abbr()
- webform_civicrm_update_6203 in ./
webform_civicrm.install - Support new state/prov chain-select feature.
- wf_crm_ajax in ./
contact_component.inc - Drupal page callback to serve AJAX requests.
- wf_crm_contact_get in ./
webform_civicrm_forms.inc - Fetch all relevant data for a given contact Used to load contacts for pre-filling a webform, and also to fill in a contact via ajax
- wf_crm_process_submission in ./
webform_civicrm_forms.inc - Webform submission handler Create/update CiviCRM contacts and related data Called by presave, insert and update webform hooks
File
- ./
webform_civicrm_utils.inc, line 521 - Webform CiviCRM module's common utility functions.
Code
function wf_crm_state_abbr($input, $ret = 'abbreviation', $country_id = NULL) {
$input_type = $ret == 'id' ? 'abbreviation' : 'id';
$sql = "SELECT {$ret} FROM civicrm_state_province WHERE {$input_type} = %1";
$vars = array(
1 => array(
$input,
$ret == 'id' ? 'String' : 'Integer',
),
);
if ($ret === 'id') {
if (!$country_id || $country_id === 'default') {
$config = CRM_Core_Config::singleton();
$country_id = (int) $config->defaultContactCountry;
}
$sql .= ' AND country_id = %2';
$vars[2] = array(
$country_id,
'Integer',
);
}
$sql .= ' LIMIT 0, 1';
return CRM_Core_DAO::singleValueQuery($sql, $vars);
}