From: jitendrapurohit Date: Thu, 6 Oct 2016 10:04:12 +0000 (+0530) Subject: improve performance for action links and add button X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e1d48b724668b2b2b6bf687b4be613fb0159e449;p=civicrm-core.git improve performance for action links and add button --- diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index bbb3c4e090..6b6c38fb62 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -233,7 +233,14 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $this->_entityId, - $this->_groupID + $this->_groupID, + array(), + NULL, + TRUE, + NULL, + FALSE, + TRUE, + $this->_copyValueId ); $valueIdDefaults = array(); $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this); diff --git a/CRM/Contact/Page/View/CustomData.php b/CRM/Contact/Page/View/CustomData.php index 9a1a45a696..16cad61179 100644 --- a/CRM/Contact/Page/View/CustomData.php +++ b/CRM/Contact/Page/View/CustomData.php @@ -136,18 +136,23 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { //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); CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle))); + $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, + $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount + ); $recId = $this->_recId; $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); $this->assign('skipTitle', 1); } + else { + $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, + $this->_groupId, $entitySubType + ); + } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId); } } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 0e3574b66e..b2f402218d 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -330,6 +330,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { * api - through which it is properly tested - so can be refactored with some comfort.) * * @param bool $checkPermission + * @param varchar $singleRecord + * holds 'new' or id if view/edit/copy form for a single record is being loaded. * * @return array * Custom field 'tree'. @@ -353,7 +355,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { $fromCache = TRUE, $onlySubType = NULL, $returnAll = FALSE, - $checkPermission = TRUE + $checkPermission = TRUE, + $singleRecord = NULL ) { if ($entityID) { $entityID = CRM_Utils_Type::escape($entityID, 'Integer'); @@ -596,7 +599,7 @@ ORDER BY civicrm_custom_group.weight, // add info to groupTree if (isset($groupTree['info']) && !empty($groupTree['info']) && - !empty($groupTree['info']['tables']) + !empty($groupTree['info']['tables']) && $singleRecord != 'new' ) { $select = $from = $where = array(); $groupTree['info']['where'] = NULL; @@ -630,7 +633,7 @@ ORDER BY civicrm_custom_group.weight, } $multipleFieldTablesWithEntityData = array_keys($entityMultipleSelectClauses); if (!empty($multipleFieldTablesWithEntityData)) { - self::buildEntityTreeMultipleFields($groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData); + self::buildEntityTreeMultipleFields($groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData, $singleRecord); } } @@ -751,8 +754,10 @@ ORDER BY civicrm_custom_group.weight, * Array of select clauses relevant to the entity. * @param array $multipleFieldTablesWithEntityData * Array of tables in which this entity has data. + * @param varchar $singleRecord + * holds 'new' or id if view/edit/copy form for a single record is being loaded. */ - static public function buildEntityTreeMultipleFields(&$groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData) { + static public function buildEntityTreeMultipleFields(&$groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData, $singleRecord = NULL) { foreach ($entityMultipleSelectClauses as $table => $selectClauses) { $select = implode(',', $selectClauses); $query = " @@ -760,7 +765,11 @@ ORDER BY civicrm_custom_group.weight, FROM $table WHERE entity_id = $entityID "; - self::buildTreeEntityDataFromQuery($groupTree, $query, array($table)); + if ($singleRecord) { + $offset = $singleRecord - 1; + $query .= " LIMIT {$offset}, 1"; + } + self::buildTreeEntityDataFromQuery($groupTree, $query, array($table), $singleRecord); } } @@ -776,8 +785,10 @@ ORDER BY civicrm_custom_group.weight, * @param array $includedTables * Tables to include - required because the function (for historical reasons). * iterates through the group tree + * @param varchar $singleRecord + * holds 'new' OR id if view/edit/copy form for a single record is being loaded. */ - static public function buildTreeEntityDataFromQuery(&$groupTree, $query, $includedTables) { + static public function buildTreeEntityDataFromQuery(&$groupTree, $query, $includedTables, $singleRecord = NULL) { $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { foreach ($groupTree as $groupID => $group) { @@ -792,7 +803,7 @@ ORDER BY civicrm_custom_group.weight, continue; } foreach ($group['fields'] as $fieldID => $dontCare) { - self::buildCustomFieldData($dao, $groupTree, $table, $groupID, $fieldID); + self::buildCustomFieldData($dao, $groupTree, $table, $groupID, $fieldID, $singleRecord); } } } @@ -811,8 +822,10 @@ ORDER BY civicrm_custom_group.weight, * Custom group ID. * @param int $fieldID * Custom field ID. + * @param varchar $singleRecord + * holds 'new' or id if loading view/edit/copy for a single record. */ - static public function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID) { + static public function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID, $singleRecord = NULL) { $column = $groupTree[$groupID]['fields'][$fieldID]['column_name']; $idName = "{$table}_id"; $fieldName = "{$table}_{$column}"; @@ -896,7 +909,10 @@ ORDER BY civicrm_custom_group.weight, if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(); } - if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) { + if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue']) && !empty($singleRecord)) { + $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array($singleRecord => $customValue); + } + elseif (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue); } else { diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index be7338081a..51547d825e 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -151,6 +151,14 @@ class CRM_Custom_Form_CustomData { * @return array */ public static function setGroupTree(&$form, $subType, $gid, $onlySubType = NULL, $getCachedTree = FALSE) { + $singleRecord = NULL; + if (!empty($form->_groupCount) && $form->_multiRecordDisplay == 'single') { + $singleRecord = $form->_groupCount; + } + $mode = CRM_Utils_Request::retrieve('mode', 'String', $form); + if ($form->_groupCount == 0 && $mode == 'add' && $form->_multiRecordDisplay == 'single') { + $singleRecord = 'new'; + } $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, @@ -159,7 +167,10 @@ class CRM_Custom_Form_CustomData { $subType, $form->_subName, $getCachedTree, - $onlySubType + $onlySubType, + FALSE, + TRUE, + $singleRecord ); if (property_exists($form, '_customValueCount') && !empty($groupTree)) { diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index 1598f4f8df..63f1e30d42 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -109,7 +109,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { elseif ($this->_pageViewType == 'customDataView') { // custom data specific view links $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd'; - $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single&mode=view'; + $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&cgcount=%%cgcount%%&multiRecordDisplay=single&mode=view'; // custom data specific update links $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit';