You are here

protected function wf_crm_webform_base::saveCustomValues in Webform CiviCRM Integration 7.4

Saves a set of custom values for specific entity Id.

Parameters

int $entity_id:

array $params:

bool $skipEmpty:

1 call to wf_crm_webform_base::saveCustomValues()
wf_crm_webform_base::saveCustomData in includes/wf_crm_webform_base.inc
Save custom data for an entity

File

includes/wf_crm_webform_base.inc, line 802

Class

wf_crm_webform_base
Class wf_crm_webform_base

Code

protected function saveCustomValues($entity_id, array $params, $skipEmpty = FALSE) {
  if ($skipEmpty) {

    // Remove empty values from $params array. Useful to not save empty values
    // with 'Create only' mode.
    foreach ($params as $key => $value) {
      $checkValue = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $value);
      if (empty($checkValue)) {
        unset($params[$key]);
      }
    }
  }
  $result = CRM_Core_BAO_CustomValueTable::setValues($params);

  // Prevent wholesale failure by saving each param individually if there was an error while trying to save them all at once
  if (!empty($result['is_error'])) {
    $bt = debug_backtrace();
    array_shift($params);
    foreach ($params as $k => $v) {
      $single_param = array(
        'entityID' => $entity_id,
        $k => $v,
      );
      $result = CRM_Core_BAO_CustomValueTable::setValues($single_param);
      if (!empty($result['is_error'])) {
        $file = explode('/', $bt[0]['file']);
        watchdog('webform_civicrm', 'The CiviCRM "CustomValueTable::setValues" function returned the error: "%msg" when called by line !line of !file with the following parameters: "!params"', array(
          '%msg' => $result['error_message'],
          '!line' => $bt[0]['line'],
          '!file' => array_pop($file),
          '!params' => print_r($single_param, TRUE),
        ), WATCHDOG_ERROR);
      }
    }
  }
}