diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 56599265fd5a..5f1abdadc774 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2640,15 +2640,8 @@ public static function getCountComponent($component, $contactId, $tableName = NU * * @param object $contact * Contact object after save. - * @param bool $useDefaults - * Use default greeting values. */ - public static function processGreetings(&$contact, $useDefaults = FALSE) { - if ($useDefaults) { - //retrieve default greetings - $defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults(); - $contactDefaults = $defaultGreetings[$contact->contact_type]; - } + public static function processGreetings(&$contact) { // The contact object has not always required the // fields that are required to calculate greetings @@ -2681,14 +2674,7 @@ public static function processGreetings(&$contact, $useDefaults = FALSE) { $updateQueryString[] = " email_greeting_custom = NULL "; } else { - if ($useDefaults) { - reset($contactDefaults['email_greeting']); - $emailGreetingID = key($contactDefaults['email_greeting']); - $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID]; - $updateQueryString[] = " email_greeting_id = $emailGreetingID "; - $updateQueryString[] = " email_greeting_custom = NULL "; - } - elseif ($contact->email_greeting_custom) { + if ($contact->email_greeting_custom) { $updateQueryString[] = " email_greeting_display = NULL "; } } @@ -2717,14 +2703,7 @@ public static function processGreetings(&$contact, $useDefaults = FALSE) { $updateQueryString[] = " postal_greeting_custom = NULL "; } else { - if ($useDefaults) { - reset($contactDefaults['postal_greeting']); - $postalGreetingID = key($contactDefaults['postal_greeting']); - $postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID]; - $updateQueryString[] = " postal_greeting_id = $postalGreetingID "; - $updateQueryString[] = " postal_greeting_custom = NULL "; - } - elseif ($contact->postal_greeting_custom) { + if ($contact->postal_greeting_custom) { $updateQueryString[] = " postal_greeting_display = NULL "; } } @@ -2754,14 +2733,7 @@ public static function processGreetings(&$contact, $useDefaults = FALSE) { $updateQueryString[] = " addressee_custom = NULL "; } else { - if ($useDefaults) { - reset($contactDefaults['addressee']); - $addresseeID = key($contactDefaults['addressee']); - $addresseeString = $contactDefaults['addressee'][$addresseeID]; - $updateQueryString[] = " addressee_id = $addresseeID "; - $updateQueryString[] = " addressee_custom = NULL "; - } - elseif ($contact->addressee_custom) { + if ($contact->addressee_custom) { $updateQueryString[] = " addressee_display = NULL "; } } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 419664441890..dd1369821168 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -155,12 +155,6 @@ class CRM_Core_PseudoConstant { */ private static $greeting; - /** - * Default Greetings - * @var array - */ - private static $greetingDefaults; - /** * Extensions of type module * @var array @@ -1650,6 +1644,10 @@ public static function countryIDForStateID($stateID) { * array reference of all greetings. */ public static function greeting($filter, $columnName = 'label') { + if (!isset(Civi::$statics[__CLASS__]['greeting'])) { + Civi::$statics[__CLASS__]['greeting'] = array(); + } + $index = $filter['greeting_type'] . '_' . $columnName; // also add contactType to the array @@ -1658,11 +1656,7 @@ public static function greeting($filter, $columnName = 'label') { $index .= '_' . $contactType; } - if (NULL === self::$greeting) { - self::$greeting = array(); - } - - if (!CRM_Utils_Array::value($index, self::$greeting)) { + if (!CRM_Utils_Array::value($index, Civi::$statics[__CLASS__]['greeting'])) { $filterCondition = NULL; if ($contactType) { $filterVal = 'v.filter ='; @@ -1682,40 +1676,10 @@ public static function greeting($filter, $columnName = 'label') { $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) "; } - self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName); - } - - return self::$greeting[$index]; - } - - /** - * Construct array of default greeting values for contact type. - * - * - * @return array - * array reference of default greetings. - */ - public static function &greetingDefaults() { - if (!self::$greetingDefaults) { - $defaultGreetings = array(); - $contactTypes = self::get('CRM_Contact_DAO_Contact', 'contact_type', array( - 'keyColumn' => 'id', - 'labelColumn' => 'name', - )); - - foreach ($contactTypes as $filter => $contactType) { - $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 "; - - foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { - $tokenVal = CRM_Core_OptionGroup::values($greeting, NULL, NULL, NULL, $filterCondition, 'label'); - $defaultGreetings[$contactType][$greeting] = $tokenVal; - } - } - - self::$greetingDefaults = $defaultGreetings; + Civi::$statics[__CLASS__]['greeting'][$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName); } - return self::$greetingDefaults; + return Civi::$statics[__CLASS__]['greeting'][$index]; } /**