From: Johan Vervloet Date: Tue, 15 Dec 2015 12:48:25 +0000 (+0100) Subject: CRM-14920 - This will work with my workaround of CRM-16587. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f57a51788eafb07a2f389b73d529566f04ef88ab;p=civicrm-core.git CRM-14920 - This will work with my workaround of CRM-16587. ---------------------------------------- * 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 --- diff --git a/CRM/Contact/Form/Search/Custom/PostalMailing.php b/CRM/Contact/Form/Search/Custom/PostalMailing.php index 02c9486a40..352c1d7705 100644 --- a/CRM/Contact/Form/Search/Custom/PostalMailing.php +++ b/CRM/Contact/Form/Search/Custom/PostalMailing.php @@ -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 = " diff --git a/CRM/Contact/Selector/Custom.php b/CRM/Contact/Selector/Custom.php index f529f76e97..3ac10fa31a 100644 --- a/CRM/Contact/Selector/Custom.php +++ b/CRM/Contact/Selector/Custom.php @@ -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); } /**