function wf_crm_state_abbr in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/utils.inc \wf_crm_state_abbr()
- 7.3 webform_civicrm_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_webform_ajax::county in includes/
wf_crm_webform_ajax.inc - Populate a county list based on chosen state
- wf_crm_webform_base::loadContact in includes/
wf_crm_webform_base.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_webform_postprocess::saveContactLocation in includes/
wf_crm_webform_postprocess.inc - Save location data for a contact
File
- includes/
utils.inc, line 169 - 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);
}