protected function wf_crm_webform_base::getCustomData in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/wf_crm_webform_base.inc \wf_crm_webform_base::getCustomData()
Get custom data for an entity
Parameters
$entity_id: Numeric id of entity
$entity_type: Type of crm entity. 'contact' is assumed
$normalize: Default true: if true shift all arrays to start at index 1
Return value
array
4 calls to wf_crm_webform_base::getCustomData()
- 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_base::saveCustomData in includes/
wf_crm_webform_base.inc - Save custom data for an entity
- wf_crm_webform_preprocess::loadParticipants in includes/
wf_crm_webform_preprocess.inc - Load participant data for a contact
- wf_crm_webform_preprocess::populateExistingEntity in includes/
wf_crm_webform_preprocess.inc - Populate existing entity data
File
- includes/
wf_crm_webform_base.inc, line 666
Class
- wf_crm_webform_base
- Class wf_crm_webform_base
Code
protected function getCustomData($entity_id, $entity_type = NULL, $normalize = TRUE) {
static $parents = array();
if (empty($parents)) {
// Create matching table to sort fields by group
foreach (wf_crm_get_fields() as $key => $value) {
list($group, $field) = explode('_', $key, 2);
if (substr($field, 0, 7) == 'custom_') {
$parents[$field] = $group;
}
}
}
$params = array(
'entityID' => $entity_id,
);
if ($entity_type) {
$params['entityType'] = ucfirst($entity_type);
}
$result = CRM_Core_BAO_CustomValueTable::getValues($params);
if (!empty($result['is_error'])) {
return array();
}
unset($result['is_error'], $result['entityID']);
$values = array();
// Convert multi-value strings to arrays and sort by group
foreach ($result as $key => $value) {
$pieces = explode('_', $key);
if ($pieces[0] == 'custom') {
$name = 'custom_' . $pieces[1];
if (empty($pieces[2])) {
$pieces[2] = $normalize ? 1 : 0;
}
if (isset($parents[$name])) {
$values[$parents[$name]][$pieces[2]][$name] = $value;
}
}
}
if ($normalize) {
// Normalize array keys
foreach ($values as &$value) {
array_unshift($value, 0);
unset($value[0]);
}
}
return $values;
}