aqlFieldConditional.php
Table of Contents
Functions
- aqlFieldConditional() : string
- Generate an AQL key/value expression for a conditional scalar field (`Field::WHEN`).
Functions
aqlFieldConditional()
Generate an AQL key/value expression for a conditional scalar field (`Field::WHEN`).
aqlFieldConditional(string $key, string $then, mixed $when[, mixed $else = null ][, string $doc = AQL::DOC ]) : string
Guards the projected value behind a condition — the SQL CASE WHEN … THEN … ELSE …
shape, rendered as an AQL ternary:
price: doc.visibility == 'public' ? doc.price : null
The key is always present; only the value switches to the else branch (default
null) when the condition is false — it never omits the key (that would require a
MERGE, intentionally out of scope). The condition is compiled by
buildWhenCondition() (inline, no bind variables) and the else branch by
resolveWhenElse().
The $then expression is the already-built scalar projection — the bare field
reference (doc.price) or, when the field also declares Field::ALTERS, the
transformed value (LOWER(TRIM(doc.price))). The caller (aqlFields()) builds it.
Parameters
- $key : string
-
The output key/label (possibly already double-quoted).
- $then : string
-
The value projected when the condition holds (e.g.
doc.price). - $when : mixed
-
The
Field::WHENcondition descriptor. - $else : mixed = null
-
The
Field::ELSEdescriptor (literal or[ Field::PROPERTY => '<attr>' ]; defaultnull). - $doc : string = AQL::DOC
-
The document reference for the condition/else operands (default:
AQL::DOC).
Tags
Return values
string —The AQL key/value snippet, e.g. price:doc.visibility == 'public' ? doc.price : null.