From bf7ec51a28be3a176fc4754168ca373eba7866db Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 29 Mar 2016 18:13:12 +0530 Subject: [PATCH] add from clause w.r.t orderBy --- CRM/Contact/BAO/Query.php | 9 ++++++--- CRM/Contact/Selector.php | 9 ++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index affbeaaa6f..8b414c3b73 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4610,18 +4610,21 @@ civicrm_relationship.is_permission_a_b = 0 switch ($field) { case 'city': case 'postal_code': - $this->_whereTables["civicrm_address"] = 1; + $this->_tables["civicrm_address"] = $this->_whereTables["civicrm_address"] = 1; $order = str_replace($field, "civicrm_address.{$field}", $order); break; case 'country': case 'state_province': - $this->_whereTables["civicrm_{$field}"] = 1; + $this->_tables["civicrm_{$field}"] = $this->_whereTables["civicrm_{$field}"] = 1; + if (is_array($this->_returnProperties) && empty($this->_returnProperties)) { + $additionalFromClause .= " LEFT JOIN civicrm_{$field} ON civicrm_{$field}.id = civicrm_address.{$field}_id"; + } $order = str_replace($field, "civicrm_{$field}.name", $order); break; case 'email': - $this->_whereTables["civicrm_email"] = 1; + $this->_tables["civicrm_email"] = $this->_whereTables["civicrm_email"] = 1; $order = str_replace($field, "civicrm_email.{$field}", $order); break; diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 8375cea074..295c569fc8 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1212,11 +1212,6 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont public function contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') { $sortOrder = &$this->getSortOrder($this->_action); $sort = new CRM_Utils_Sort($sortOrder, $sortID); - $includeOrderByClause = Civi::settings()->get('includeOrderByClause'); - $returnProperties = CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES; - if ($includeOrderByClause) { - $returnProperties = $this->_returnProperties; - } // rectify params to what proximity search expects if there is a value for prox_distance // CRM-7021 CRM-7905 @@ -1226,7 +1221,7 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont if (!$displayRelationshipType) { $query = new CRM_Contact_BAO_Query($params, - $returnProperties, + CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES, NULL, FALSE, FALSE, 1, FALSE, TRUE, TRUE, NULL, $queryOperator @@ -1234,7 +1229,7 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont } else { $query = new CRM_Contact_BAO_Query($params, - $returnProperties, + CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES, NULL, FALSE, FALSE, 1, FALSE, TRUE, TRUE, $displayRelationshipType, $queryOperator -- 2.25.1