/** * Preparing params for API Contact.create based on retrieved result. * @param array $param * @param array $contact * @param array $result * @param int $basedOnContactId * * @return mixed */ function prepareParamsContact($param, $contact, $result, $basedOnContactId = 0) { $h = $param->cons_hash; $optInMapGroupStatus = array(0 => 'Added', 1 => 'Pending'); unset($contact['return']); unset($contact[$this->apiAddressGet]); unset($contact[$this->apiGroupContactGet]); $existingContact = array(); if ($basedOnContactId > 0) { foreach ($result['values'] as $id => $res) { if ($res['id'] == $basedOnContactId) { $existingContact = $res; break; } } } if (is_array($existingContact) && count($existingContact) > 0) { $contact['id'] = $existingContact['id']; if ($existingContact['first_name'] == '') { $contact['first_name'] = $h->firstname; } if ($existingContact['last_name'] == '') { $contact['last_name'] = $h->lastname; } $contact = $this->prepareParamsAddress($contact, $existingContact); if ($existingContact[$this->apiGroupContactGet]['count'] == 0) { $contact[$this->apiGroupContactCreate] = array('group_id' => $this->groupId, 'contact_id' => '$value.id', 'status' => $optInMapGroupStatus[$this->optIn]); } } else { $genderId = $this->getGenderId($h->lastname); $genderShortcut = $this->getGenderShortcut($h->lastname); $lastname = $this->cleanLastname($h->lastname); $contact['first_name'] = $h->firstname; $contact['last_name'] = $lastname; $contact['gender_id'] = $genderId; $contact['prefix_id'] = CRM_Speakcivi_Tools_Dictionary::getPrefix($genderShortcut); $dict = new CRM_Speakcivi_Tools_Dictionary(); $dict->parseGroupEmailGreeting(); $emailGreetingId = $dict->getEmailGreetingId($this->locale, $genderShortcut); if ($emailGreetingId) { $contact['email_greeting_id'] = $emailGreetingId; } $contact['preferred_language'] = $this->locale; $contact['source'] = 'speakout ' . $param->action_type . ' ' . $param->external_id; $contact = $this->prepareParamsAddressDefault($contact); $contact[$this->apiGroupContactCreate] = array('group_id' => $this->groupId, 'contact_id' => '$value.id', 'status' => $optInMapGroupStatus[$this->optIn]); } return $contact; }