From a038992cda183128d36258c0f4e1ede338cd3eae Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 2 Aug 2013 23:17:53 +1200 Subject: [PATCH] CRM-13149 fix BAO based reciprocal relationship get to accept type filter as an array per API, includes extracting function to be available from the BAO --- CRM/Contact/BAO/Relationship.php | 1 - CRM/Core/DAO.php | 7 +++--- api/v3/utils.php | 42 +++----------------------------- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 4a171303b6..2ba8c638a7 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -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 { diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 8ade8e0e13..37e457c021 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -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)); diff --git a/api/v3/utils.php b/api/v3/utils.php index a9f0762464..6ad074a465 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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 { -- 2.25.1