From d820f4e8e058206267b642984c33ba925a22b69b Mon Sep 17 00:00:00 2001 From: monishdeb Date: Thu, 28 May 2015 02:18:16 +0530 Subject: [PATCH] CRM-16476 fix - Search Builder: Contact created_date and modified_date filters not working https://issues.civicrm.org/jira/browse/CRM-16476 --- CRM/Contact/BAO/Query.php | 46 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 226a664c70..aa79b3bf4a 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2081,36 +2081,17 @@ class CRM_Contact_BAO_Query { TRUE ); } - elseif ($name === 'birth_date') { - $date = CRM_Utils_Date::processDate($value); - $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); - - if ($date) { - $date = CRM_Utils_Date::customFormat($date); - $this->_qill[$grouping][] = "$field[title] $op \"$date\""; - } - else { - $this->_qill[$grouping][] = "$field[title] $op"; - } - self::$_openedPanes[ts('Demographics')] = TRUE; - } - elseif ($name === 'deceased_date') { - $date = CRM_Utils_Date::processDate($value); - $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); - if ($date) { - $date = CRM_Utils_Date::customFormat($date); - $this->_qill[$grouping][] = "$field[title] $op \"$date\""; - } - else { - $this->_qill[$grouping][] = "$field[title] $op"; - } - self::$_openedPanes[ts('Demographics')] = TRUE; - } elseif ($name === 'is_deceased') { $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value); $this->_qill[$grouping][] = "$field[title] $op \"$value\""; self::$_openedPanes[ts('Demographics')] = TRUE; } + elseif ($name === 'created_date' || $name === 'modified_date' || $name === 'deceased_date' || $name === 'birth_date') { + $this->dateQueryBuilder($values, 'contact_a', $name ,$name , $field['title']); + if ($name === 'deceased_date' || $name === 'birth_date') { + self::$_openedPanes[ts('Demographics')] = TRUE; + } + } elseif ($name === 'contact_id') { if (is_int($value)) { $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value); @@ -5059,17 +5040,17 @@ SELECT COUNT( conts.total_amount ) as cancel_count, } if ($name == $fieldName) { - // $op = '='; - $phrase = $op; + //In Get API, for operators other then '=' the $value is in array(op => value) format + if (is_array($value) && !empty($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $op = key($value); + $value = $value[$op]; + } $date = CRM_Utils_Date::processDate($value); - if (!$appendTimeStamp) { $date = substr($date, 0, 8); } - $format = CRM_Utils_Date::customFormat($date); - if ($date) { $this->_where[$grouping][] = "{$tableName}.{$dbFieldName} $op '$date'"; } @@ -5077,7 +5058,10 @@ SELECT COUNT( conts.total_amount ) as cancel_count, $this->_where[$grouping][] = "{$tableName}.{$dbFieldName} $op"; } $this->_tables[$tableName] = $this->_whereTables[$tableName] = 1; - $this->_qill[$grouping][] = "$fieldTitle - $phrase \"$format\""; + + $op = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); + $format = CRM_Utils_Date::customFormat($date); + $this->_qill[$grouping][] = "$fieldTitle $op \"$format\""; } } -- 2.25.1