add from clause w.r.t orderBy
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 29 Mar 2016 12:43:12 +0000 (18:13 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 29 Mar 2016 12:43:12 +0000 (18:13 +0530)
CRM/Contact/BAO/Query.php
CRM/Contact/Selector.php

index affbeaaa6f711e139af490255fa42f84aa96e57e..8b414c3b7331abba365c512efb671bfe468d7673 100644 (file)
@@ -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;
 
index 8375cea074384ddc3bdec4709c0121bec600225c..295c569fc82f860b54b66f2d01e434188e4b402f 100644 (file)
@@ -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