*
* @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
$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 ";
}
}
$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 ";
}
}
$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 ";
}
}
*/
private static $greeting;
- /**
- * Default Greetings
- * @var array
- */
- private static $greetingDefaults;
-
/**
* Extensions of type module
* @var array
* 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
$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 =';
$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];
}
/**