You are here

function webform_civicrm_user_cid in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_utils.inc \webform_civicrm_user_cid()

Lookup a uf ID from contact ID or vice-versa

Parameters

$id: uf or contact ID - defaults to current user:

$type: what type of ID is supplied: With no arguments passed in, this function will return the contact_id of the current logged-in user

3 calls to webform_civicrm_user_cid()
webform_civicrm_configure_form_builder in ./webform_civicrm_admin.inc
Form to configure CiviCRM options for a Webform Called indirectly from hook_menu() for D7-D6 compatibility
webform_civicrm_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
_webform_civicrm_webform_frontend_form_alter in ./webform_civicrm_forms.inc
Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.

File

./webform_civicrm_utils.inc, line 887
Webform CiviCRM module's common utility functions. The code in this file is cross-compatible with D6/Civi3 and D7/Civi4 Drupal-version-specific functions belong in webform_civicrm_dx_functions.inc

Code

function webform_civicrm_user_cid($id = NULL, $type = 'uf') {
  if (!$id) {
    global $user;
    $id = $user->uid;
  }

  // Lookup current domain for multisite support
  static $domain = 0;
  if (!$domain) {
    $domain = webform_civicrm_api('domain', 'get', array(
      'current_domain' => 1,
      'return.id' => 1,
    ));
    $domain = webform_civicrm_aval($domain, 'id', 1);
  }
  $result = webform_civicrm_api('uf_match', 'get', array(
    $type . '_id' => $id,
  ));
  if (!empty($result['values'])) {
    foreach ($result['values'] as $val) {
      if ($val['domain_id'] == $domain) {
        break;
      }
    }
    return $type == 'uf' ? $val['contact_id'] : $val['uf_id'];
  }
}