25 public string $comparison,
26 public mixed $y = null,
27 public ?
string $type = null,
28 public ?
bool $case_sensitive = null
41 $case_sensitive = $this->case_sensitive;
43 $compare_with =
function ($func, $boolean =
'OR') use ($x, $y,
$type, $case_sensitive, $qb) {
48 $y = is_array($y) ? $y : [$y];
50 foreach ($y as $val) {
53 $val =
"BINARY {$val}";
56 $parts[] = $qb->expr()->$func($x, $val);
59 return $qb->
merge($parts, $boolean);
63 $comparison = strtolower($this->comparison);
64 switch ($comparison) {
69 $x =
"CAST($x as BINARY)";
72 if (is_array($y) || $comparison ===
'in') {
75 $match_expr = $qb->expr()->in($x, $param);
79 $match_expr = $qb->expr()->eq($x, $param);
88 $x =
"CAST($x as BINARY)";
91 if (is_array($y) || $comparison ===
'not in') {
94 $match_expr = $qb->expr()->notIn($x, $param);
98 $match_expr = $qb->expr()->neq($x, $param);
103 return $compare_with(
'like');
106 return $compare_with(
'notLike',
'AND');
110 return $compare_with(
'gt');
114 return $compare_with(
'lt');
118 return $compare_with(
'gte');
122 return $compare_with(
'lte');
125 return $qb->expr()->isNull($x);
128 return $qb->expr()->isNotNull($x);
131 return "EXISTS ($y)";
134 return "NOT EXISTS ($y)";
137 throw new DomainException(
"'{$this->comparison}' is not a supported comparison operator");
Utility class for building composite comparison expression.
param($value, string $type=ELGG_VALUE_STRING, string $key=null)
Sets a new parameter assigning it a unique parameter key/name if none provided Returns the name of th...
Saves user notification settings.
Interface that allows resolving statements and/or extending query builder.
Exception thrown if a value does not adhere to a defined valid data domain.
Database abstraction query builder.
static isEmpty($value)
Check if a value isn't empty, but allow 0 and '0'.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
__construct(public string $x, public string $comparison, public mixed $y=null, public?string $type=null, public?bool $case_sensitive=null)
Constructor.
prepare(QueryBuilder $qb, $table_alias=null)
{}
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.