$contactFields = CRM_Contact_DAO_Contact::fields();
_civicrm_api3_store_values($contactFields, $values, $params);
- if (isset($values['contact_type'])) {
- // we're an individual/household/org property
-
- $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields();
-
- _civicrm_api3_store_values($fields[$values['contact_type']], $values, $params);
- return TRUE;
- }
-
- if (isset($values['individual_prefix'])) {
- if (!empty($params['prefix_id'])) {
- $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
- $params['prefix'] = $prefixes[$params['prefix_id']];
- }
- else {
- $params['prefix'] = $values['individual_prefix'];
- }
- return TRUE;
- }
-
- if (isset($values['individual_suffix'])) {
- if (!empty($params['suffix_id'])) {
- $suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
- $params['suffix'] = $suffixes[$params['suffix_id']];
- }
- else {
- $params['suffix'] = $values['individual_suffix'];
- }
- return TRUE;
- }
-
- // CRM-4575
- if (isset($values['email_greeting'])) {
- if (!empty($params['email_greeting_id'])) {
- $emailGreetingFilter = [
- 'contact_type' => $params['contact_type'] ?? NULL,
- 'greeting_type' => 'email_greeting',
- ];
- $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter);
- $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']];
- }
- else {
- $params['email_greeting'] = $values['email_greeting'];
- }
-
- return TRUE;
- }
-
- if (isset($values['postal_greeting'])) {
- if (!empty($params['postal_greeting_id'])) {
- $postalGreetingFilter = [
- 'contact_type' => $params['contact_type'] ?? NULL,
- 'greeting_type' => 'postal_greeting',
- ];
- $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter);
- $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']];
- }
- else {
- $params['postal_greeting'] = $values['postal_greeting'];
- }
- return TRUE;
- }
-
- if (isset($values['addressee'])) {
- $params['addressee'] = $values['addressee'];
- return TRUE;
- }
-
- if (isset($values['gender'])) {
- if (!empty($params['gender_id'])) {
- $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
- $params['gender'] = $genders[$params['gender_id']];
- }
- else {
- $params['gender'] = $values['gender'];
- }
- return TRUE;
- }
-
- if (!empty($values['preferred_communication_method'])) {
- $comm = [];
- $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method')), CASE_LOWER);
-
- $preffComm = explode(',', $values['preferred_communication_method']);
- foreach ($preffComm as $v) {
- $v = strtolower(trim($v));
- if (array_key_exists($v, $pcm)) {
- $comm[$pcm[$v]] = 1;
- }
- }
-
- $params['preferred_communication_method'] = $comm;
- return TRUE;
- }
-
- // format the website params.
- if (!empty($values['url'])) {
- static $websiteFields;
- if (!is_array($websiteFields)) {
- require_once 'CRM/Core/DAO/Website.php';
- $websiteFields = CRM_Core_DAO_Website::fields();
- }
- if (!array_key_exists('website', $params) ||
- !is_array($params['website'])
- ) {
- $params['website'] = [];
- }
-
- $websiteCount = count($params['website']);
- _civicrm_api3_store_values($websiteFields, $values,
- $params['website'][++$websiteCount]
- );
-
- return TRUE;
- }
-
// get the formatted location blocks into params - w/ 3.0 format, CRM-4605
if (!empty($values['location_type_id'])) {
static $fields = NULL;
}
return TRUE;
}
-
- if (isset($values['note'])) {
- // add a note field
- if (!isset($params['note'])) {
- $params['note'] = [];
- }
- $noteBlock = count($params['note']) + 1;
-
- $params['note'][$noteBlock] = [];
- if (!isset($fields['Note'])) {
- $fields['Note'] = CRM_Core_DAO_Note::fields();
- }
-
- // get the current logged in civicrm user
- $session = CRM_Core_Session::singleton();
- $userID = $session->get('userID');
-
- if ($userID) {
- $values['contact_id'] = $userID;
- }
-
- _civicrm_api3_store_values($fields['Note'], $values, $params['note'][$noteBlock]);
-
- return TRUE;
- }
-
- // Check for custom field values
-
- if (empty($fields['custom'])) {
- $fields['custom'] = &CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values),
- FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE
- );
- }
-
- foreach ($values as $key => $value) {
- if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
- // check if it's a valid custom field id
-
- if (!array_key_exists($customFieldID, $fields['custom'])) {
- return civicrm_api3_create_error('Invalid custom field ID');
- }
- else {
- $params[$key] = $value;
- }
- }
- }
}
/**