CRM-18284 -- include returnProperties when orderBy clause is enabled
[civicrm-core.git] / CRM / Contact / Selector.php
index 36d4a94f15309b55826091328d06e17d82d7e797..8375cea074384ddc3bdec4709c0121bec600225c 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
@@ -116,8 +116,22 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
 
   protected $_searchContext;
 
+  /**
+   * Query object for this selector.
+   *
+   * @var CRM_Contact_BAO_Query
+   */
   protected $_query;
 
+  /**
+   * Get the query object for this selector.
+   *
+   * @return CRM_Contact_BAO_Query
+   */
+  public function getQueryObject() {
+    return $this->_query;
+  }
+
   /**
    * Group id
    *
@@ -649,10 +663,9 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
           continue;
         }
         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) {
-          $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue(
+          $row[$property] = CRM_Core_BAO_CustomField::displayValue(
             $result->$property,
             $cfID,
-            $this->_options,
             $result->contact_id
           );
         }
@@ -1199,6 +1212,11 @@ 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
@@ -1208,14 +1226,15 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont
 
     if (!$displayRelationshipType) {
       $query = new CRM_Contact_BAO_Query($params,
-        $this->_returnProperties,
+        $returnProperties,
         NULL, FALSE, FALSE, 1,
         FALSE, TRUE, TRUE, NULL,
         $queryOperator
       );
     }
     else {
-      $query = new CRM_Contact_BAO_Query($params, $this->_returnProperties,
+      $query = new CRM_Contact_BAO_Query($params,
+        $returnProperties,
         NULL, FALSE, FALSE, 1,
         FALSE, TRUE, TRUE, $displayRelationshipType,
         $queryOperator