function _wf_crm_fill_contact_ref in Webform CiviCRM Integration 7.3
Recursive function to fill ContactRef fields with contact IDs Called during webform submission
Parameters
$data array: CRM data to update (reference)
$cids array: All known contact ids for this form
$values null|array: Leave blank - used internally to recurse through data
$depth int: Leave blank - used internally to track recursion level
1 call to _wf_crm_fill_contact_ref()
- 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_forms.inc, line 1421
Code
function _wf_crm_fill_contact_ref(&$data, $cids, $values = NULL, $depth = 0) {
$order = array(
'ent',
'c',
'table',
'n',
'name',
);
static $ent = '';
static $c = '';
static $table = '';
static $n = '';
if ($values === NULL) {
$values = $data;
}
foreach ($values as $key => $val) {
${$order[$depth]} = $key;
if ($depth < 4 && is_array($val)) {
_wf_crm_fill_contact_ref($data, $cids, $val, $depth + 1);
}
elseif ($depth == 4 && $val) {
$fields = wf_crm_get_fields();
if (wf_crm_aval($fields, "{$table}_{$name}:data_type") === 'ContactReference') {
if (is_array($val)) {
$data[$ent][$c][$table][$n][$name] = array();
foreach ($val as $v) {
if (is_numeric($v) && !empty($cids[$v])) {
$data[$ent][$c][$table][$n][$name][] = $cids[$v];
}
}
}
else {
unset($data[$ent][$c][$table][$n][$name]);
if (!empty($cids[$val])) {
$data[$ent][$c][$table][$n][$name] = $cids[$val];
}
}
}
}
}
}