Skip to content

Commit

Permalink
Merge pull request civicrm#11313 from eileenmcnaughton/greet2
Browse files Browse the repository at this point in the history
CRM-21471 remove unused core function CRM_Core_Pseudoconstant::greeti…
  • Loading branch information
colemanw authored and sluc23 committed Jan 10, 2018
2 parents f73a2d8 + 9299a98 commit b22e914
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 75 deletions.
36 changes: 4 additions & 32 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2694,15 +2694,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
Expand Down Expand Up @@ -2735,14 +2728,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 ";
}
}
Expand Down Expand Up @@ -2771,14 +2757,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 ";
}
}
Expand Down Expand Up @@ -2808,14 +2787,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 ";
}
}
Expand Down
50 changes: 7 additions & 43 deletions CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ class CRM_Core_PseudoConstant {
*/
private static $greeting;

/**
* Default Greetings
* @var array
*/
private static $greetingDefaults;

/**
* Extensions of type module
* @var array
Expand Down Expand Up @@ -1676,6 +1670,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
Expand All @@ -1684,11 +1682,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 =';
Expand All @@ -1708,40 +1702,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];
}

/**
Expand Down

0 comments on commit b22e914

Please sign in to comment.