CRM-16476 fix - Search Builder: Contact created_date and modified_date filters not...
authormonishdeb <monish.deb@webaccessglobal.com>
Wed, 27 May 2015 20:48:16 +0000 (02:18 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Thu, 4 Jun 2015 22:18:38 +0000 (03:48 +0530)
https://issues.civicrm.org/jira/browse/CRM-16476

CRM/Contact/BAO/Query.php

index 226a664c700bfe7855ff4d551708ad0791d51029..aa79b3bf4a466d41c74a106c51607446ec95c7fa 100644 (file)
@@ -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\"";
     }
   }