CRM-13149 fix BAO based reciprocal relationship get to accept type filter as an array...
authoreileen <eileen@fuzion.co.nz>
Fri, 2 Aug 2013 11:17:53 +0000 (23:17 +1200)
committereileen <eileen@fuzion.co.nz>
Fri, 2 Aug 2013 11:17:53 +0000 (23:17 +1200)
CRM/Contact/BAO/Relationship.php
CRM/Core/DAO.php
api/v3/utils.php

index 4a171303b6f4462d8ec23ae9d4f451afd8977c12..2ba8c638a74a08ba42e8c176a7612580adccfe11 100644 (file)
@@ -889,7 +889,6 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
     $where .= ' AND civicrm_contact.is_deleted = 0';
     if(!empty($params['relationship_type_id'])) {
       if(is_array($params['relationship_type_id'])) {
-        // get our special function from DAO to deal with this
         $where .=  " AND " . CRM_Core_DAO::createSQLFilter('relationship_type_id', $params['relationship_type_id'], 'Integer');
       }
       else {
index 8ade8e0e1361b6e5a6f905f7f942a192287ee81b..37e457c021fa854e61317cd825ac97cb17c28f91 100644 (file)
@@ -1818,8 +1818,10 @@ EOS;
    * $field => array('LIKE' => array('%me%))
    * etc
    *
-   * @param $field sql filter to be applied
-   * @param $fi
+   * @param $fieldname string name of fields
+   * @param $filter array filter to be applied indexed by operator
+   * @param $type String type of field (not actually used - nor in api @todo )
+   * @param $alias String alternative field name ('as') @todo- not actually used
    */
   public function createSQLFilter($fieldName, $filter, $type, $alias = NULL) {
     // http://issues.civicrm.org/jira/browse/CRM-9150 - stick with 'simple' operators for now
@@ -1830,7 +1832,6 @@ EOS;
       if (in_array($operator, $acceptedSQLOperators)) {
         switch ($operator) {
           // unary operators
-
           case 'IS NULL':
           case 'IS NOT NULL':
             return (sprintf('%s %s', $fieldName, $operator));
index a9f0762464574c4725bc39a2ed55b0e7378a0e49..6ad074a46565afc6bc293a7b7e624900dcdeddd9 100644 (file)
@@ -484,45 +484,9 @@ function _civicrm_api3_dao_set_filter(&$dao, $params, $unique = TRUE, $entity) {
     if (is_array($params[$field])) {
       //get the actual fieldname from db
       $fieldName = $allfields[$field]['name'];
-      //array is the syntax for SQL clause
-      foreach ($params[$field] as $operator => $criteria) {
-        if (in_array($operator, $acceptedSQLOperators)) {
-          switch ($operator) {
-            // unary operators
-
-            case 'IS NULL':
-            case 'IS NOT NULL':
-              $dao->whereAdd(sprintf('%s %s', $fieldName, $operator));
-              break;
-
-            // ternary operators
-
-            case 'BETWEEN':
-            case 'NOT BETWEEN':
-              if (empty($criteria[0]) || empty($criteria[1])) {
-                throw new exception("invalid criteria for $operator");
-              }
-              $dao->whereAdd(sprintf('%s ' . $operator . ' "%s" AND "%s"', $fieldName, CRM_Core_DAO::escapeString($criteria[0]), CRM_Core_DAO::escapeString($criteria[1])));
-              break;
-
-            // n-ary operators
-
-            case 'IN':
-            case 'NOT IN':
-              if (empty($criteria)) {
-                throw new exception("invalid criteria for $operator");
-              }
-              $escapedCriteria = array_map(array('CRM_Core_DAO', 'escapeString'), $criteria);
-              $dao->whereAdd(sprintf('%s %s ("%s")', $fieldName, $operator, implode('", "', $escapedCriteria)));
-              break;
-
-            // binary operators
-
-            default:
-
-              $dao->whereAdd(sprintf('%s %s "%s"', $fieldName, $operator, CRM_Core_DAO::escapeString($criteria)));
-          }
-        }
+      $where = CRM_Core_DAO::createSqlFilter($fieldName, $params[$field], 'String');
+      if(!empty($where)) {
+        $dao->whereAdd($where);
       }
     }
     else {