From: eileen Date: Wed, 27 Mar 2019 03:56:02 +0000 (+1300) Subject: Rationalise summary part of the merge screen. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c8e6c43725b4a7fb08cbded21371b5ae3020457d;p=civicrm-core.git Rationalise summary part of the merge screen. This does 3 things 1) reduces contact get queries from 3 to 1 since the 2 in the tpl layer are removed 2) adds created date to the merge summary information 3) makes it easier for extensions to replace/ extend this data (although core makes no commitment to the tpl remaining unchanged so extension writers need to carry that risk) --- diff --git a/CRM/Contact/Form/Merge.php b/CRM/Contact/Form/Merge.php index 08d826ede6..43a4fa560d 100644 --- a/CRM/Contact/Form/Merge.php +++ b/CRM/Contact/Form/Merge.php @@ -85,10 +85,12 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { $this->bounceIfInvalid($this->_cid, $this->_oid); - $this->_contactType = civicrm_api3('Contact', 'getvalue', array( - 'id' => $this->_cid, - 'return' => 'contact_type', - )); + $contacts = civicrm_api3('Contact', 'get', [ + 'id' => ['IN' => [$this->_cid, $this->_oid]], + 'return' => ['contact_type', 'modified_date', 'created_date'], + ])['values']; + + $this->_contactType = $contacts[$this->_cid]['contact_type']; $browseUrl = CRM_Utils_System::url('civicrm/contact/dedupefind', array_merge($urlParams, ['action' => 'browse'])); @@ -175,6 +177,7 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { $this->assign('main_cid', $main['contact_id']); $this->assign('other_cid', $other['contact_id']); $this->assign('rgid', $this->_rgid); + $this->assignSummaryRowsToTemplate($contacts); $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows')); @@ -365,4 +368,34 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { } } + /** + * Assign the summary_rows variable to the tpl. + * + * This adds rows to the beginning of the block that will help in making merge choices. + * + * It can be modified by a hook by altering what is assigned. Although not technically supported this + * is an easy tweak with no earth-shattering impacts if later changes stop if from working. + * + * https://lab.civicrm.org/dev/core/issues/824 + * + * @param array $contacts + */ + protected function assignSummaryRowsToTemplate($contacts) { + $mostRecent = ($contacts[$this->_cid]['modified_date'] < $contacts[$this->_oid]['modified_date']) ? $this->_oid : $this->_cid; + $this->assign('summary_rows', [ + [ + 'name' => 'created_date', + 'label' => ts('Created'), + 'main_contact_value' => CRM_Utils_Date::customFormat($contacts[$this->_cid]['created_date']), + 'other_contact_value' => CRM_Utils_Date::customFormat($contacts[$this->_oid]['created_date']), + ], + [ + 'name' => 'modified_date', + 'label' => ts('Last Modified'), + 'main_contact_value' => CRM_Utils_Date::customFormat($contacts[$this->_cid]['modified_date']) . ($mostRecent == $this->_cid ? ' (' . ts('Most Recent') . ')' : ''), + 'other_contact_value' => CRM_Utils_Date::customFormat($contacts[$this->_oid]['modified_date']) . ($mostRecent == $this->_oid ? ' (' . ts('Most Recent') . ')' : ''), + ], + ]); + } + } diff --git a/templates/CRM/Contact/Form/Merge.tpl b/templates/CRM/Contact/Form/Merge.tpl index ec276ca7c7..59d3d823a5 100644 --- a/templates/CRM/Contact/Form/Merge.tpl +++ b/templates/CRM/Contact/Form/Merge.tpl @@ -78,17 +78,16 @@ Add/overwrite? - {crmAPI var='other_result' entity='Contact' action='get' return="modified_date" id=$other_cid} - {crmAPI var='main_result' entity='Contact' action='get' return="modified_date" id=$main_cid} - - - Last modified - {$other_result.values.0.modified_date|crmDate} {if $other_result.values.0.modified_date gt $main_result.values.0.modified_date} (Most recent) {/if} - - {$main_result.values.0.modified_date|crmDate} {if $main_result.values.0.modified_date gt $other_result.values.0.modified_date} (Most recent) {/if} - - + {foreach from=$summary_rows item=summaryRow} + + {$summaryRow.label} + {$summaryRow.other_contact_value} + + {$summaryRow.main_contact_value} + + + {/foreach} {foreach from=$rows item=row key=field}