<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Dedupe_Merger {
// CRM-15681 don't display sub-types in UI
continue;
}
- foreach (['main' => $main, 'other' => $other] as $moniker => $contact) {
- list($label, $value) = self::getFieldValueAndLabel($field, $contact);
- $rows["move_$field"][$moniker] = $label;
- if ($moniker == 'other') {
- //CRM-14334
- if ($value === NULL || $value == '') {
- $value = 'null';
- }
- if ($value === 0 or $value === '0') {
- $value = $qfZeroBug;
- }
- if (is_array($value) && empty($value[1])) {
- $value[1] = NULL;
- }
+ $rows["move_$field"] = [
+ 'main' => self::getFieldValueAndLabel($field, $main)['label'],
+ 'other' => self::getFieldValueAndLabel($field, $other)['label'],
+ 'title' => $fields[$field]['title'],
+ ];
- // Display a checkbox to migrate, only if the values are different
- if ($value != $main[$field]) {
- $elements[] = [
- 'advcheckbox',
- "move_$field",
- NULL,
- NULL,
- NULL,
- $value,
- ];
- }
+ $value = self::getFieldValueAndLabel($field, $other)['value'];
+ //CRM-14334
+ if ($value === NULL || $value == '') {
+ $value = 'null';
+ }
+ if ($value === 0 or $value === '0') {
+ $value = $qfZeroBug;
+ }
+ if (is_array($value) && empty($value[1])) {
+ $value[1] = NULL;
+ }
- $migrationInfo["move_$field"] = $value;
- }
+ // Display a checkbox to migrate, only if the values are different
+ if ($value != $main[$field]) {
+ $elements[] = [
+ 0 => 'advcheckbox',
+ 1 => "move_$field",
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ 5 => $value,
+ 'is_checked' => (!isset($main[$field]) || $main[$field] === ''),
+ ];
}
- $rows["move_$field"]['title'] = $fields[$field]['title'];
+
+ $migrationInfo["move_$field"] = $value;
}
// Handle location blocks.
// Set up useful information about the location blocks
$locationBlocks = self::getLocationBlockInfo();
- $locations = [
- 'main' => [],
- 'other' => [],
- ];
-
- // @todo This could probably be defined and used earlier
- $mergeTargets = [
- 'main' => $mainId,
- 'other' => $otherId,
- ];
+ $locations = ['main' => [], 'other' => []];
foreach ($locationBlocks as $blockName => $blockInfo) {
// Collect existing fields from both 'main' and 'other' contacts first
// This allows us to match up location/types when building the table rows
- foreach ($mergeTargets as $moniker => $cid) {
- $searchParams = [
- 'contact_id' => $cid,
- // CRM-17556 Order by field-specific criteria
- 'options' => [
- 'sort' => $blockInfo['sortString'],
- ],
- ];
- $values = civicrm_api3($blockName, 'get', $searchParams);
- if ($values['count']) {
- $cnt = 0;
- foreach ($values['values'] as $value) {
- $locations[$moniker][$blockName][$cnt] = $value;
- // Fix address display
- if ($blockName == 'address') {
- // For performance avoid geocoding while merging https://issues.civicrm.org/jira/browse/CRM-21786
- // we can expect existing geocode values to be retained.
- $value['skip_geocode'] = TRUE;
- CRM_Core_BAO_Address::fixAddress($value);
- unset($value['skip_geocode']);
- $locations[$moniker][$blockName][$cnt]['display'] = CRM_Utils_Address::format($value);
- }
- // Fix email display
- elseif ($blockName == 'email') {
- $locations[$moniker][$blockName][$cnt]['display'] = CRM_Utils_Mail::format($value);
- }
-
- $cnt++;
- }
- }
- }
+ $locations['main'][$blockName] = self::buildLocationBlockForContact($mainId, $blockInfo, $blockName);
+ $locations['other'][$blockName] = self::buildLocationBlockForContact($otherId, $blockInfo, $blockName);
// Now, build the table rows appropriately, based off the information on
// the 'other' contact
elseif ($field == 'current_employer_id' && !empty($value)) {
$label = "$value (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
}
- return [$label, $value];
+ return ['label' => $label, 'value' => $value];
+ }
+
+ /**
+ * Build up the location block for the contact in dedupe-screen display format.
+ *
+ * @param integer $cid
+ * @param array $blockInfo
+ * @param string $blockName
+ *
+ * @return array
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ private static function buildLocationBlockForContact($cid, $blockInfo, $blockName): array {
+ $searchParams = [
+ 'contact_id' => $cid,
+ // CRM-17556 Order by field-specific criteria
+ 'options' => [
+ 'sort' => $blockInfo['sortString'],
+ ],
+ ];
+ $locationBlock = [];
+ $values = civicrm_api3($blockName, 'get', $searchParams);
+ if ($values['count']) {
+ $cnt = 0;
+ foreach ($values['values'] as $value) {
+ $locationBlock[$cnt] = $value;
+ // Fix address display
+ if ($blockName == 'address') {
+ // For performance avoid geocoding while merging https://issues.civicrm.org/jira/browse/CRM-21786
+ // we can expect existing geocode values to be retained.
+ $value['skip_geocode'] = TRUE;
+ CRM_Core_BAO_Address::fixAddress($value);
+ unset($value['skip_geocode']);
+ $locationBlock[$cnt]['display'] = CRM_Utils_Address::format($value);
+ }
+ // Fix email display
+ elseif ($blockName == 'email') {
+ $locationBlock[$cnt]['display'] = CRM_Utils_Mail::format($value);
+ }
+
+ $cnt++;
+ }
+ }
+ return $locationBlock;
}
}