Skip to content

Commit

Permalink
Merge pull request #15519 from eileenmcnaughton/dedupe
Browse files Browse the repository at this point in the history
[REF] minor extraction with code to build dedupe arrays
  • Loading branch information
seamuslee001 authored Oct 16, 2019
2 parents 86d75e4 + 6704a92 commit 58e7f00
Showing 1 changed file with 52 additions and 37 deletions.
89 changes: 52 additions & 37 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,43 +1092,7 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio
continue;
}
foreach (['main' => $main, 'other' => $other] as $moniker => $contact) {
$value = $label = CRM_Utils_Array::value($field, $contact);
$fieldSpec = $fields[$field];
if (!empty($fieldSpec['serialize']) && is_array($value)) {
// In practice this only applies to preferred_communication_method as the sub types are skipped above
// and no others are serialized.
$labels = [];
foreach ($value as $individualValue) {
$labels[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $individualValue);
}
$label = implode(', ', $labels);
// We serialize this due to historic handling but it's likely that if we just left it as an
// array all would be well & we would have less code.
$value = CRM_Core_DAO::serializeField($value, $fieldSpec['serialize']);
}
elseif (!empty($fieldSpec['type']) && $fieldSpec['type'] == CRM_Utils_Type::T_DATE) {
if ($value) {
$value = str_replace('-', '', $value);
$label = CRM_Utils_Date::customFormat($label);
}
else {
$value = "null";
}
}
elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
if ($label === '0') {
$label = ts('[ ]');
}
if ($label === '1') {
$label = ts('[x]');
}
}
elseif (!empty($fieldSpec['pseudoconstant'])) {
$label = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $value);
}
elseif ($field == 'current_employer_id' && !empty($value)) {
$label = "$value (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
}
list($label, $value) = self::getFieldValueAndLabel($field, $contact);
$rows["move_$field"][$moniker] = $label;
if ($moniker == 'other') {
//CRM-14334
Expand Down Expand Up @@ -2550,4 +2514,55 @@ protected static function ignoredFields(): array {
return $keysToIgnore;
}

/**
* Get the field value & label for the given field.
*
* @param $field
* @param $contact
*
* @return array
* @throws \Exception
*/
private static function getFieldValueAndLabel($field, $contact): array {
$fields = self::getMergeFieldsMetadata();
$value = $label = CRM_Utils_Array::value($field, $contact);
$fieldSpec = $fields[$field];
if (!empty($fieldSpec['serialize']) && is_array($value)) {
// In practice this only applies to preferred_communication_method as the sub types are skipped above
// and no others are serialized.
$labels = [];
foreach ($value as $individualValue) {
$labels[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $individualValue);
}
$label = implode(', ', $labels);
// We serialize this due to historic handling but it's likely that if we just left it as an
// array all would be well & we would have less code.
$value = CRM_Core_DAO::serializeField($value, $fieldSpec['serialize']);
}
elseif (!empty($fieldSpec['type']) && $fieldSpec['type'] == CRM_Utils_Type::T_DATE) {
if ($value) {
$value = str_replace('-', '', $value);
$label = CRM_Utils_Date::customFormat($label);
}
else {
$value = "null";
}
}
elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
if ($label === '0') {
$label = ts('[ ]');
}
if ($label === '1') {
$label = ts('[x]');
}
}
elseif (!empty($fieldSpec['pseudoconstant'])) {
$label = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $value);
}
elseif ($field == 'current_employer_id' && !empty($value)) {
$label = "$value (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
}
return [$label, $value];
}

}

0 comments on commit 58e7f00

Please sign in to comment.