From beb596e1bbf98facbcd3273c7476c82f8a5e35af Mon Sep 17 00:00:00 2001 From: kurund Date: Thu, 1 May 2014 12:53:33 -0700 Subject: [PATCH] CRM-13274, search builder fixes ---------------------------------------- * CRM-13274: Sort by pseudo-constants is broken for search builder https://issues.civicrm.org/jira/browse/CRM-13274 --- CRM/Contact/BAO/Query.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 3bc84cdb6a..aed58c8583 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4357,6 +4357,14 @@ civicrm_relationship.is_permission_a_b = 0 $this->_whereTables["civicrm_email"] = 1; $order = str_replace($field, "civicrm_email.{$field}", $order); break; + + default: + //CRM-12565 add "`" around $field if it is a pseudo constant + foreach ($this->_pseudoConstantsSelect as $key => $value) { + if (!empty($value['element']) && $value['element'] == $field) { + $order = str_replace($field, "`{$field}`", $order); + } + } } $this->_fromClause = self::fromClause($this->_tables, NULL, NULL, $this->_primaryLocation, $this->_mode); $this->_simpleFromClause = self::fromClause($this->_whereTables, NULL, NULL, $this->_primaryLocation, $this->_mode); -- 2.25.1