From 5a2c7bb9e6ef6e3a512271e70088beb37a2942b3 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Fri, 15 Jan 2016 18:45:25 +0530 Subject: [PATCH] Add pager to custom data tab --- CRM/Core/xml/Menu/Custom.xml | 5 ++ CRM/Custom/Page/AJAX.php | 50 ++++++++++++++++ .../Page/MultipleRecordFieldsListing.php | 21 +++++-- .../Page/MultipleRecordFieldsListing.tpl | 59 +++++++++++++++---- 4 files changed, 117 insertions(+), 18 deletions(-) diff --git a/CRM/Core/xml/Menu/Custom.xml b/CRM/Core/xml/Menu/Custom.xml index 04a38ae614..f1b40aa51e 100644 --- a/CRM/Core/xml/Menu/Custom.xml +++ b/CRM/Core/xml/Menu/Custom.xml @@ -15,4 +15,9 @@ CRM_Custom_Page_AJAX::fixOrdering access CiviCRM + + civicrm/ajax/multirecordfieldlist + CRM_Custom_Page_AJAX::getMultiRecordFieldList + access CiviCRM + diff --git a/CRM/Custom/Page/AJAX.php b/CRM/Custom/Page/AJAX.php index 4885b1f17d..1bc0991def 100644 --- a/CRM/Custom/Page/AJAX.php +++ b/CRM/Custom/Page/AJAX.php @@ -105,4 +105,54 @@ class CRM_Custom_Page_AJAX { CRM_Utils_JSON::output(TRUE); } + /** + * Get list of Multi Record Fields. + * + */ + public static function getMultiRecordFieldList() { + $params = $_REQUEST; + + $sEcho = CRM_Utils_Type::escape($_GET['sEcho'], 'Integer'); + $offset = isset($params['iDisplayStart']) ? CRM_Utils_Type::escape($params['iDisplayStart'], 'Integer') : 0; + $rowCount = isset($params['iDisplayLength']) ? CRM_Utils_Type::escape($params['iDisplayLength'], 'Integer') : 25; + + $params['page'] = ($offset / $rowCount) + 1; + $params['rp'] = $rowCount; + $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']); + + $obj = new CRM_Profile_Page_MultipleRecordFieldsListing(); + $obj->_pageViewType = 'customDataView'; + $obj->_contactId = $params['cid']; + $obj->_customGroupId = $params['cgid']; + $obj->_contactType = $contactType; + $obj->_offset = ($params['page'] - 1) * $params['rp']; + $obj->_rowCount = $params['rp']; + + list($headers, $multiRecordFields) = $obj->browse(); + + // sort the fields by the columns + $sortMapper = array_values($headers); + $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + if ($sort && $sortOrder) { + $sortOrder = constant('SORT_' . strtoupper($sortOrder)); + $sortCol = array(); + $dataType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $sort, 'data_type'); + foreach ($multiRecordFields as $key=> $row) { + $sortCol[$key] = $row[$sort]; + if ($dataType == 'Date') { + $sortCol[$key] = CRM_Utils_Date::unixTime($row[$sort]); + } + } + array_multisort($sortCol, $sortOrder, $multiRecordFields); + } + + $iFilteredTotal = $iTotal = $obj->_total; + $selectorElements = array_merge($headers, array('action', 'class')); + + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); + echo CRM_Utils_JSON::encodeDataTableSelector($multiRecordFields, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); + CRM_Utils_System::civiExit(); + } + } diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index 20615f10b4..9ee81ca02c 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -45,13 +45,13 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { protected $_profileId = NULL; - protected $_contactId = NULL; + public $_contactId = NULL; - protected $_customGroupTitle = NULL; + public $_customGroupTitle = NULL; - protected $_pageViewType = NULL; + public $_pageViewType = NULL; - protected $_contactType = NULL; + public $_contactType = NULL; /** * Get BAO Name. @@ -299,6 +299,11 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { unset($links[CRM_Core_Action::COPY]); } $newCgCount = (!$reached) ? count($result) + 1 : NULL; + if (isset($this->_offset) && isset($this->_rowCount)) { + $this->_total = count($result); + $result = array_slice($result, $this->_offset, $this->_rowCount, TRUE); + $cgcount = $this->_offset + 1; + } foreach ($result as $recId => &$value) { foreach ($value as $fieldId => &$val) { if (is_numeric($fieldId)) { @@ -418,16 +423,20 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $headers = array(); if (!empty($fieldIDs)) { foreach ($fieldIDs as $fieldID) { - $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label']; + $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : !isset($this->_offset) ? $fieldLabels[$fieldID]['label'] : $fieldID; } } $this->assign('dateFields', $dateFields); $this->assign('dateFieldsVals', $dateFieldsVals); $this->assign('cgcount', $cgcount); + $this->assign('contactId', $this->_contactId); + $this->assign('contactType', $this->_contactType); $this->assign('customGroupTitle', $this->_customGroupTitle); $this->assign('headers', $headers); $this->assign('records', $result); - $this->assign('attributes', $attributes); + $this->assign('attributes', json_encode($attributes)); + + return array($headers, $result); } /** diff --git a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl index 72bcff5596..e7fa21028a 100644 --- a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl +++ b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl @@ -35,7 +35,7 @@
{strip} - +
{foreach from=$headers key=recId item=head} @@ -47,17 +47,52 @@ {/foreach} - {foreach from=$records key=recId item=rows} - - {foreach from=$headers key=hrecId item=head} - - {/foreach} - - {foreach from=$dateFieldsVals key=fid item=rec} - - {/foreach} - - {/foreach} + {if $pageViewType eq 'customDataView'} + {literal} + + {/literal} + {else} + {foreach from=$records key=recId item=rows} + + {foreach from=$headers key=hrecId item=head} + + {/foreach} + + {foreach from=$dateFieldsVals key=fid item=rec} + + {/foreach} + + {/foreach} + {/if}
{$rows.$hrecId}{$rows.action}{$rec.$recId}
{$rows.$hrecId}{$rows.action}{$rec.$recId}
{/strip}
-- 2.25.1