function wf_crm_user_cid in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 7.3 webform_civicrm_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
int|null
7 calls to wf_crm_user_cid()
- wf_crm_contact_access in includes/
contact_component.inc - Load contact name if user has permission. Else return FALSE.
- wf_crm_webform_base::findContact in includes/
wf_crm_webform_base.inc - Find an existing contact based on matching criteria Used to populate a webform existing contact field
- 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::fillHiddenContactFields in includes/
wf_crm_webform_postprocess.inc - Fill values for hidden ID & CS fields
- wf_crm_webform_postprocess::processActivities in includes/
wf_crm_webform_postprocess.inc - Save activity data
File
- includes/
utils.inc, line 1507 - 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', [
'current_domain' => 1,
'return' => 'id',
]);
$domain = wf_crm_aval($domain, 'id', 1);
}
$result = wf_crm_apivalues('uf_match', 'get', [
$type . '_id' => $id,
'domain_id' => $domain,
'sequential' => 1,
]);
if ($result) {
if (!empty($user_lookup)) {
$current_user = $result[0]['contact_id'];
}
return $type == 'uf' ? $result[0]['contact_id'] : $result[0]['uf_id'];
}
}