$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 {
* $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
if (in_array($operator, $acceptedSQLOperators)) {
switch ($operator) {
// unary operators
-
case 'IS NULL':
case 'IS NOT NULL':
return (sprintf('%s %s', $fieldName, $operator));
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 {