Add is empty filter to search / api
[civicrm-core.git] / Civi / Api4 / Generic / Traits / ArrayQueryActionTrait.php
index 4ae6096c503965784deff942f29420d785cf50a0..88c24a78c49de6dd1b33c1be23ec5c5246455e9d 100644 (file)
@@ -130,6 +130,10 @@ trait ArrayQueryActionTrait {
       case 'IS NOT NULL':
         return is_null($value) == ($operator == 'IS NULL');
 
+      case 'IS EMPTY':
+      case 'IS NOT EMPTY':
+        return empty($value) == ($operator == 'IS EMPTY');
+
       case '>':
         return $value > $expected;
 
@@ -158,6 +162,15 @@ trait ArrayQueryActionTrait {
       case 'NOT IN':
         return !in_array($value, $expected);
 
+      case 'CONTAINS':
+        if (is_array($value)) {
+          return in_array($expected, $value);
+        }
+        elseif (is_string($value) || is_numeric($value)) {
+          return strpos((string) $value, (string) $expected) !== FALSE;
+        }
+        return $value == $expected;
+
       default:
         throw new NotImplementedException("Unsupported operator: '$operator' cannot be used with array data");
     }