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

dev/core#824 Rationalise summary part of the merge screen. #13897

Merged
merged 1 commit into from
Mar 27, 2019
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
41 changes: 37 additions & 4 deletions CRM/Contact/Form/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ public function preProcess() {

$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']));

Expand Down Expand Up @@ -175,6 +177,7 @@ public function preProcess() {
$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'));

Expand Down Expand Up @@ -365,4 +368,34 @@ public function bounceIfInvalid($cid, $oid) {
}
}

/**
* 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') . ')' : ''),
],
]);
}

}
19 changes: 9 additions & 10 deletions templates/CRM/Contact/Form/Merge.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,16 @@
<th width="300">Add/overwrite?</th>
</tr>

{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}

<tr>
<td>Last modified</td>
<td>{$other_result.values.0.modified_date|crmDate} {if $other_result.values.0.modified_date gt $main_result.values.0.modified_date} (Most recent) {/if}</td>
<td></td>
<td>{$main_result.values.0.modified_date|crmDate} {if $main_result.values.0.modified_date gt $other_result.values.0.modified_date} (Most recent) {/if}</td>
<td></td>
</tr>
{foreach from=$summary_rows item=summaryRow}
<tr>
<td>{$summaryRow.label}</td>
<td>{$summaryRow.other_contact_value}</td>
<td></td>
<td>{$summaryRow.main_contact_value}</td>
<td></td>
</tr>
{/foreach}

{foreach from=$rows item=row key=field}

Expand Down