From a60e32080a37d1c1b11e27244e7b488148eec04f Mon Sep 17 00:00:00 2001 From: Alok Patel Date: Thu, 13 Dec 2018 16:14:22 +0530 Subject: [PATCH] GREENS-199: Added paginations on Dedupe Exceptions page --- CRM/Contact/Page/DedupeException.php | 97 ++++++++----- .../CRM/Contact/Page/DedupeException.tpl | 130 ++++++++++++++---- 2 files changed, 159 insertions(+), 68 deletions(-) diff --git a/CRM/Contact/Page/DedupeException.php b/CRM/Contact/Page/DedupeException.php index 8ce168fa9f..4dbaf3cbf1 100644 --- a/CRM/Contact/Page/DedupeException.php +++ b/CRM/Contact/Page/DedupeException.php @@ -35,53 +35,74 @@ * Main page for viewing contact. */ class CRM_Contact_Page_DedupeException extends CRM_Core_Page { - /** - * Heart of the viewing process. + * the main function that is called when the page loads, + * it decides the which action has to be taken for the page. * - * The runner gets all the meta data for the contact and calls the appropriate type of page to view. + * @return null */ - public function preProcess() { - //fetch the dedupe exception contacts. - $dedupeExceptions = array(); + public function run() { + $this->initializePager(); + $this->assign('exceptions', $this->getExceptions()); + return parent::run(); + } - $exception = new CRM_Dedupe_DAO_Exception(); - $exception->find(); - $contactIds = array(); - while ($exception->fetch()) { - $key = "{$exception->contact_id1}_{$exception->contact_id2}"; - $contactIds[$exception->contact_id1] = $exception->contact_id1; - $contactIds[$exception->contact_id2] = $exception->contact_id2; - $dedupeExceptions[$key] = array( - 'main' => array('id' => $exception->contact_id1), - 'other' => array('id' => $exception->contact_id2), - ); - } - //get the dupe contacts display names. - if (!empty($dedupeExceptions)) { - $sql = 'select id, display_name from civicrm_contact where id IN ( ' . implode(', ', $contactIds) . ' )'; - $contact = CRM_Core_DAO::executeQuery($sql); - $displayNames = array(); - while ($contact->fetch()) { - $displayNames[$contact->id] = $contact->display_name; - } - foreach ($dedupeExceptions as $key => & $values) { - $values['main']['name'] = CRM_Utils_Array::value($values['main']['id'], $displayNames); - $values['other']['name'] = CRM_Utils_Array::value($values['other']['id'], $displayNames); - } - } - $this->assign('dedupeExceptions', $dedupeExceptions); + /** + * Method to initialize pager + * + * @access protected + */ + protected function initializePager() { + $totalitems = civicrm_api3('Exception', "getcount", array()); + $params = array( + 'total' => $totalitems, + 'rowCount' => CRM_Utils_Pager::ROWCOUNT, + 'status' => ts('Dedupe Exceptions %%StatusMessage%%'), + 'buttonBottom' => 'PagerBottomButton', + 'buttonTop' => 'PagerTopButton', + 'pageID' => $this->get(CRM_Utils_Pager::PAGE_ID), + ); + $this->_pager = new CRM_Utils_Pager($params); + $this->assign_by_ref('pager', $this->_pager); } /** - * the main function that is called when the page loads, - * it decides the which action has to be taken for the page. + * Function to get the exceptions * - * @return null + * @return array $exceptions + * @access protected */ - public function run() { - $this->preProcess(); - return parent::run(); + protected function getExceptions() { + list($offset, $limit) = $this->_pager->getOffsetAndRowCount(); + $contactOneQ = CRM_Utils_Request::retrieve('crmContact1Q', 'String'); + $contactTwoQ = CRM_Utils_Request::retrieve('crmContact2Q', 'String'); + + if (!$contactOneQ) { + $contactOneQ = ''; + } + if (!$contactTwoQ) { + $contactTwoQ = ''; + } + + $this->assign('searchcontact1', $contactOneQ); + $this->assign('searchcontact2', $contactTwoQ); + + $params = array( + "options" => array('limit' => $limit, 'offset' => $offset), + 'return' => ["contact_id1.display_name", "contact_id2.display_name", "contact_id1", "contact_id2"], + ); + + if ($contactOneQ != '') { + $params['contact_id1.display_name'] = array('LIKE' => '%' . $contactOneQ . '%'); + } + + if ($contactTwoQ != '') { + $params['contact_id2.display_name'] = array('LIKE' => '%' . $contactTwoQ . '%'); + } + + $exceptions = civicrm_api3("Exception", "get", $params); + $exceptions = $exceptions["values"]; + return $exceptions; } } diff --git a/templates/CRM/Contact/Page/DedupeException.tpl b/templates/CRM/Contact/Page/DedupeException.tpl index 0cff17ca8d..ec358547ad 100644 --- a/templates/CRM/Contact/Page/DedupeException.tpl +++ b/templates/CRM/Contact/Page/DedupeException.tpl @@ -30,52 +30,122 @@
-
- +
+
-
- +
+
- - - - - - - - - - {foreach from=$dedupeExceptions item=exception key=id} - - - - + + +
+ {include file="CRM/common/pager.tpl" location="top"} + {include file='CRM/common/jsortable.tpl'} + +
+
{ts}Contact 1{/ts}{ts}Contact 2 (Duplicate){/ts}
{$exception.main.name}{$exception.other.name}» {ts}Remove Exception{/ts}
+ + + + - {/foreach} - -
{ts}Contact 1{/ts}{ts}Contact 2 (Duplicate){/ts}
+ + + {assign var="rowClass" value="odd-row"} + {assign var="rowCount" value=0} + + {foreach from=$exceptions key=errorId item=exception} + {assign var="rowCount" value=$rowCount+1} + + + + + {assign var="contact1name" value="contact_id1.display_name"} + { $exception.$contact1name } + + + {assign var="contact2name" value="contact_id2.display_name"} + { $exception.$contact2name } + + + + + {if $rowClass eq "odd-row"} + {assign var="rowClass" value="even-row"} + {else} + {assign var="rowClass" value="odd-row"} + {/if} + + {/foreach} + + + + {include file="CRM/common/pager.tpl" location="bottom"} + + + +

{* process the dupe contacts *} -{include file="CRM/common/dedupe.tpl"} {literal} {/literal} -- 2.25.1