CRM-14920 - This will work with my workaround of CRM-16587.
authorJohan Vervloet <johanv@johanv.org>
Tue, 15 Dec 2015 12:48:25 +0000 (13:48 +0100)
committerJohan Vervloet <johanv@johanv.org>
Tue, 15 Dec 2015 14:27:34 +0000 (15:27 +0100)
----------------------------------------
* CRM-14920: Custom Searches do not honor user sort order
  https://issues.civicrm.org/jira/browse/CRM-14920
* CRM-16587: Action menu is not available on selected records on a Custom search
  https://issues.civicrm.org/jira/browse/CRM-16587

CRM/Contact/Form/Search/Custom/PostalMailing.php
CRM/Contact/Selector/Custom.php

index 02c9486a40dea692d5a5abf03b5e4ed0198f7731..352c1d770561f012ea59702cb0583f0c2e0d7324 100644 (file)
@@ -106,7 +106,7 @@ class CRM_Contact_Form_Search_Custom_PostalMailing extends CRM_Contact_Form_Sear
   ) {
     if ($justIDs) {
       $selectClause = "contact_a.id as contact_id";
-      $sort = 'contact_a.id';
+      //$sort = 'contact_a.id';
     }
     else {
       $selectClause = "
index f529f76e97e28ffe460e7daaea366c4affdcb66b..3ac10fa31a4bb3954054a7c394cd7d97e86e15e5 100644 (file)
@@ -425,10 +425,24 @@ class CRM_Contact_Selector_Custom extends CRM_Contact_Selector {
    * @return Object
    */
   public function contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') {
-    $params = array();
-    $sql = $this->_search->contactIDs($params);
+    // $action, $displayRelationshipType and $queryOperator are unused. I have
+    // no idea why they are there.
+
+    // I wonder whether there is some helper function for this:
+    $matches = array();
+    if (preg_match('/([0-9]*)(_(u|d))?/', $sortID, $matches)) {
+      $columns = array_values($this->_search->columns());
+      $sort = $columns[$matches[1] - 1];
+      if (array_key_exists(3, $matches) && $matches[3] == 'd') {
+        $sort .= " DESC";
+      }
+    }
+    else {
+      $sort = NULL;
+    }
 
-    return CRM_Core_DAO::executeQuery($sql, $params);
+    $sql = $this->_search->contactIDs(0, 0, $sort);
+    return CRM_Core_DAO::executeQuery($sql);
   }
 
   /**