From 9082df1a06d1c952add514b0570aca7772b8fb89 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 5 Oct 2016 16:10:09 +0530 Subject: [PATCH] Fix performance on table display --- CRM/Contact/Page/View/CustomData.php | 20 ++--- .../Page/MultipleRecordFieldsListing.php | 24 +++-- .../CRM/Contact/Page/View/CustomData.tpl | 87 +++++++++---------- 3 files changed, 70 insertions(+), 61 deletions(-) diff --git a/CRM/Contact/Page/View/CustomData.php b/CRM/Contact/Page/View/CustomData.php index 1c6b9db637..9a1a45a696 100644 --- a/CRM/Contact/Page/View/CustomData.php +++ b/CRM/Contact/Page/View/CustomData.php @@ -101,12 +101,6 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { $this->assign('editOwnCustomData', $editOwnCustomData); if ($this->_action == CRM_Core_Action::BROWSE) { - //Custom Groups Inline - $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); - $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); - $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, - $this->_groupId, $entitySubType - ); $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, @@ -115,7 +109,8 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { if ($this->_multiRecordDisplay != 'single') { $id = "custom_{$this->_groupId}"; - $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']); + $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name'); + $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $tableName); } if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') { @@ -135,14 +130,15 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { $page->set('pageViewType', 'customDataView'); $page->set('contactType', $ctype); $page->_headersOnly = TRUE; - $page->assign('viewCustomData', array( - $this->_groupId => array( - $this->_groupId => $groupTree[$this->_groupId], - ), - )); $page->run(); } else { + //Custom Groups Inline + $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); + $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); + $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, + $this->_groupId, $entitySubType + ); $recId = NULL; if ($this->_multiRecordDisplay == 'single') { $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId); diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index e2c2876528..1598f4f8df 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -219,7 +219,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { // from the above customGroupInfo we can get $this->_customGroupTitle $this->_customGroupTitle = $groupDetail[$customGroupId]['title']; } - if ($fieldIDs && !empty($fieldIDs) && $this->_contactId && empty($this->_headersOnly)) { + if (!empty($fieldIDs) && $this->_contactId) { $options = array(); $returnProperities = array( 'html_type', @@ -259,7 +259,10 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues); $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues); } + $linkAction = array_sum(array_keys($this->links())); + } + if (!empty($fieldIDs) && $this->_contactId && empty($this->_headersOnly)) { $DTparams = !empty($this->_DTparams) ? $this->_DTparams : NULL; // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView) $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE, $DTparams); @@ -298,7 +301,6 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { } } } - $linkAction = array_sum(array_keys($this->links())); if ($reached) { unset($links[CRM_Core_Action::COPY]); @@ -384,8 +386,6 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $op = 'profile.multiValue.row'; } else { - $headerAttr[$fieldId]['dataType'] = CRM_Utils_Array::value('data-type', $fieldAttributes); - $headerAttr[$fieldId]['dataEmptyOption'] = CRM_Utils_Array::value('data-empty-option', $fieldAttributes); // different set of url params $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId; $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId; @@ -428,11 +428,25 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $headers = array(); if (!empty($fieldIDs)) { + $fields = array('Radio', 'Select', 'Select Country', 'Select State/Province'); foreach ($fieldIDs as $fieldID) { if ($this->_pageViewType == 'profileDataView') { $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel']; } - else { + elseif (!empty($this->_headersOnly)) { + if (!$options[$fieldID]['attributes']['is_view'] && $linkAction & CRM_Core_Action::UPDATE) { + $spec = $options[$fieldID]['attributes']; + + if (in_array($spec['html_type'], $fields)) { + $headerAttr[$fieldID]['dataType'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select'; + if (!$spec['is_required']) { + $headerAttr[$fieldID]['dataEmptyOption'] = ts('- none -'); + } + } + elseif ($spec['html_type'] == 'TextArea') { + $headerAttr[$fieldID]['dataType'] = 'textarea'; + } + } $headers[$fieldID] = $fieldLabels[$fieldID]['label']; $headerAttr[$fieldID]['columnName'] = $fieldLabels[$fieldID]['column_name']; } diff --git a/templates/CRM/Contact/Page/View/CustomData.tpl b/templates/CRM/Contact/Page/View/CustomData.tpl index f7e99123a1..0d8b7d655a 100644 --- a/templates/CRM/Contact/Page/View/CustomData.tpl +++ b/templates/CRM/Contact/Page/View/CustomData.tpl @@ -32,6 +32,37 @@ {/if} {/strip} +{if $displayStyle eq 'tableOriented'} + {include file='CRM/Profile/Page/MultipleRecordFieldsListing.tpl' showListing=1 dontShowTitle=1 pageViewType='customDataView'} + {literal} + + {/literal} +{/if} {foreach from=$viewCustomData item=customGroupWrapper} {foreach from=$customGroupWrapper item=customGroup key=customGroupId} {assign var="customRegion" value='contact-custom-data-'|cat:$customGroup.name} @@ -42,53 +73,21 @@ {if $action eq 0 or $action eq 1 or $action eq 2 or $recordActivity} {include file="CRM/Contact/Form/CustomData.tpl" mainEdit=$mainEditForm} {/if} - {if $displayStyle eq 'tableOriented'} - {include file='CRM/Profile/Page/MultipleRecordFieldsListing.tpl' showListing=1 dontShowTitle=1 pageViewType='customDataView'} - {literal} - - {/literal} + on_load_init_blocks(showBlocks1, hideBlocks1); + {else} - {if $mainEditForm} - - {else} - - {/if} + {* hide and display the appropriate blocks as directed by the php code *} + on_load_init_blocks(showBlocks, hideBlocks); + {/if} {if $customGroup.help_post}
{$customGroup.help_post}
-- 2.25.1