/** * 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; }
$settingsFile = trim(implode('', file('path.inc'))) . '/civicrm.settings.php'; define('CIVICRM_SETTINGS_PATH', $settingsFile); $error = @(include_once $settingsFile); if ($error == false) { echo "Could not load the settings file at: {$settingsFile}\n"; exit; } // Load class loader global $civicrm_root; require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; CRM_Core_ClassLoader::singleton()->register(); require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); CRM_Core_OptionGroup::getAssoc('email_greeting', $group, false, 'name'); print_r($group); $dict = new CRM_Speakcivi_Tools_Dictionary(); $dict->parseGroupEmailGreeting(); print_r($dict->emailGreetingIds); $locales = array('fr_FR:', 'fr_FR:F', 'fr_FR:M', 'de_DE:', 'de_DE:M', 'de_DE:FG'); foreach ($locales as $loc) { echo $loc . ' -> ' . print_r($dict->parseLocaleGenderShortcut($loc), true) . "\n"; } echo $dict->getEmailGreetingId('fr_FR', '') . "\n"; echo $dict->getEmailGreetingId('fr_FR', 'F') . "\n"; echo $dict->getEmailGreetingId('fr_FR', 'M') . "\n"; echo $dict->getEmailGreetingId('de_DE', '') . "\n"; echo $dict->getEmailGreetingId('de_DE', 'F') . "\n"; echo $dict->getEmailGreetingId('de_DE', 'M') . "\n"; echo $dict->getEmailGreetingId('es_ES', '') . "\n"; echo $dict->getEmailGreetingId('es_ES', 'F') . "\n"; echo $dict->getEmailGreetingId('es_ES', 'M') . "\n";