From dcf0d3485f0107144eb0964b6edccd4fedc4a701 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Wed, 23 Apr 2014 11:52:23 +0530 Subject: [PATCH] CRM-14265 --- CRM/Core/BAO/CustomGroup.php | 2 +- CRM/Core/BAO/CustomQuery.php | 63 ++++++++++++------------------------ CRM/Event/BAO/Query.php | 2 +- 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 94d277c6c6..df28a53afc 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1743,7 +1743,7 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1, // add field information foreach ($value['fields'] as $k => $properties) { $properties['element_name'] = "custom_{$k}_-{$groupCount}"; - if (isset($properties['customValue']) && !CRM_Utils_system::isNull($properties['customValue'])) { + if (isset($properties['customValue']) && !CRM_Utils_System::isNull($properties['customValue'])) { if (isset($properties['customValue'][$groupCount])) { $properties['element_name'] = "custom_{$k}_{$properties['customValue'][$groupCount]['id']}"; $formattedGroupTree[$key]['table_id'] = $properties['customValue'][$groupCount]['id']; diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index cab4a5057c..0f15babbc5 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -107,6 +107,7 @@ class CRM_Core_BAO_CustomQuery { /** * This stores custom data group types and tables that it extends * + * @todo add comments explaining why survey & campaign are missing from this * @var array * @static */ @@ -272,56 +273,34 @@ SELECT label, value $this->_select[$fieldName] = "{$field['table_name']}.{$field['column_name']} as $fieldName"; $this->_element[$fieldName] = 1; $joinTable = NULL; - if ($field['extends'] == 'civicrm_contact') { + // CRM-14265 + if ($field['extends'] == 'civicrm_group') { + return; + } + elseif ($field['extends'] == 'civicrm_contact') { $joinTable = 'contact_a'; } elseif ($field['extends'] == 'civicrm_contribution') { - $joinTable = 'civicrm_contribution'; - } - elseif ($field['extends'] == 'civicrm_participant') { - $joinTable = 'civicrm_participant'; - } - elseif ($field['extends'] == 'civicrm_membership') { - $joinTable = 'civicrm_membership'; - } - elseif ($field['extends'] == 'civicrm_pledge') { - $joinTable = 'civicrm_pledge'; + $joinTable = $field['extends']; } - elseif ($field['extends'] == 'civicrm_activity') { - $joinTable = 'civicrm_activity'; + elseif (in_array($field['extends'], self::$extendsMap)) { + $joinTable = $field['extends']; } - elseif ($field['extends'] == 'civicrm_relationship') { - $joinTable = 'civicrm_relationship'; - } - elseif ($field['extends'] == 'civicrm_grant') { - $joinTable = 'civicrm_grant'; - } - elseif ($field['extends'] == 'civicrm_address') { - $joinTable = 'civicrm_address'; + else { + return; } - elseif ($field['extends'] == 'civicrm_case') { - $joinTable = 'civicrm_case'; + + $this->_tables[$name] = "\nLEFT JOIN $name ON $name.entity_id = $joinTable.id"; + + if ($this->_ids[$id]) { + $this->_whereTables[$name] = $this->_tables[$name]; } - if ($joinTable) { - $joinClause = 1; - $joinTableAlias = $joinTable; - // Set location-specific query - if (isset($this->_locationSpecifiCustomFields[$id])) { - list($locationType, $locationTypeId) = $this->_locationSpecifiCustomFields[$id]; - $joinTableAlias = "$locationType-address"; - $joinClause = "\nLEFT JOIN $joinTable `$locationType-address` ON (`$locationType-address`.contact_id = contact_a.id AND `$locationType-address`.location_type_id = $locationTypeId)"; - } - $this->_tables[$name] = "\nLEFT JOIN $name ON $name.entity_id = `$joinTableAlias`.id"; - if ($this->_ids[$id]) { - $this->_whereTables[$name] = $this->_tables[$name]; - } - if ($joinTable != 'contact_a') { - $this->_whereTables[$joinTableAlias] = $this->_tables[$joinTableAlias] = $joinClause; - } - elseif ($this->_contactSearch) { - CRM_Contact_BAO_Query::$_openedPanes[ts('Custom Fields')] = TRUE; - } + if ($joinTable != 'contact_a') { + $this->_whereTables[$joinTable] = $this->_tables[$joinTable] = 1; + } + elseif ($this->_contactSearch) { + CRM_Contact_BAO_Query::$_openedPanes[ts('Custom Fields')] = TRUE; } } } diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 201ba64ecc..2fc24f18b7 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -587,7 +587,7 @@ class CRM_Event_BAO_Query { $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields - $extends = array('Participant'); + $extends = array('Participant', 'Event'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); -- 2.25.1