Skip to content
Snippets Groups Projects
Commit a038992c authored by eileen's avatar eileen
Browse files

CRM-13149 fix BAO based reciprocal relationship get to accept type filter as...

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
parent faf8c53b
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
......@@ -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));
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment