function wf_crm_user_cid in Webform CiviCRM Integration 7.3
Same name and namespace in other branches
- 7.5 includes/utils.inc \wf_crm_user_cid()
- 7.4 includes/utils.inc \wf_crm_user_cid()
Lookup a uf ID from contact ID or vice-versa With no arguments passed in, this function will return the contact_id of the current logged-in user
Parameters
$id: (optional) uf or contact ID - defaults to current user
$type: (optional) what type of ID is supplied - defaults to user id
Return value
null
3 calls to wf_crm_user_cid()
- wf_crm_contact_access in ./
contact_component.inc - Load contact name if user has permission. Else return FALSE.
- wf_crm_find_contact in ./
contact_component.inc - Find an existing contact based on matching criteria Used to autopopulate a webform existing contact field
- 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 1147 - Webform CiviCRM module's common utility functions.
Code
function wf_crm_user_cid($id = NULL, $type = 'uf') {
static $current_user = NULL;
if (!$id) {
if ($current_user !== NULL) {
return $current_user;
}
global $user;
$id = $user_lookup = $user->uid;
}
if (!$id || !is_numeric($id)) {
return NULL;
}
// Lookup current domain for multisite support
static $domain = 0;
if (!$domain) {
$domain = wf_civicrm_api('domain', 'get', array(
'current_domain' => 1,
'return.id' => 1,
));
$domain = wf_crm_aval($domain, 'id', 1);
}
$result = wf_civicrm_api('uf_match', 'get', array(
$type . '_id' => $id,
));
if (!empty($result['values'])) {
foreach ($result['values'] as $val) {
if ($val['domain_id'] == $domain) {
break;
}
}
if (!empty($user_lookup)) {
$current_user = $val['contact_id'];
}
return $type == 'uf' ? $val['contact_id'] : $val['uf_id'];
}
}