Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21471 remove unused core function CRM_Core_Pseudoconstant::greeti… #11313

Merged
merged 1 commit into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ";
}
}
Expand Down Expand Up @@ -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 ";
}
}
Expand Down Expand Up @@ -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 ";
}
}
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 @@ -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
Expand All @@ -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 =';
Expand All @@ -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];
}

/**
Expand Down