CoolCMS API

ParameterRelRangeFilter extends BaseFilter
in package
implements Filter

Filters by a range (from-to) of one specific parameter.

Like ParameterRelFilter it uses its own left join with a unique alias, so it can be combined with other filters by AND.

IMPORTANT: the parameterId condition is intentional. Without it the range would compare the value of any product relation, and since value of enum parameters holds the option's parameter_id as text, "from 1" would match almost everything.

The semantics is an intersection of intervals, not containment: searched [from, to] against stored [value, value2 ?? value]. The stored interval uses COALESCE(NULLIF(value2, ''), value) because products and adverts keep a single number in value with value2 empty; a value2 <= to condition would match nothing.

Bounds are bound as numbers, not strings: value is a text column and MySQL casts it to a number when compared with a number, whereas a string would compare lexicographically ('9' > '80').

Table of Contents

Interfaces

Filter

Properties

$applyToCollections  : bool
$fields  : array<string|int, string>
$fromTableAlias  : string|null
$operator  : string
$phaseOneOnly  : bool
$textTableAlias  : string|null
$value  : mixed
$from  : float|null
$parameterId  : int
$parameterIdColumn  : string
$relation  : string
$to  : float|null
$value2Column  : string
$valueColumn  : string

Methods

__construct()  : mixed
appliesToCollections()  : bool
Tells whether the filter also applies to ToMany branch queries (phase 2 of hydration).
apply()  : void
Applies the filter to the Doctrine QueryBuilder.
applyWithCondition()  : string|null
Default implementation for simple operators (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`, `NOT LIKE`).
getBindings()  : ArrayCollection<int, mixed>
Returns no bindings; {@see self::apply()} builds the whole query directly in the QueryBuilder.
getFields()  : array<string|int, string>
Returns the field or fields the filter applies to.
getOperator()  : string
getType()  : string
Returns the filter type/operator (e.g. '=', 'LIKE', 'IN').
getValue()  : mixed
Returns the filter value.
isPhaseOneOnly()  : bool
When true, the filter applies only to phase 1 (root ID selection) and does not leak into the ToMany branch queries of the second hydration phase.
setApplyToCollections()  : static
setFields()  : static
Sets the field or fields the filter applies to.
setFromTableAlias()  : static
Sets the alias of the main table for join operations.
setPhaseOneOnly()  : static
setTextTableAlias()  : static
Sets the alias of the text (translations) table for join operations.
toSql()  : string
Builds the SQL condition for the filter.

Properties

$applyToCollections

protected bool $applyToCollections = false

$fields

protected array<string|int, string> $fields

field names; always an array, even when a single name was passed (the constructor and setFields() normalize it)

$fromTableAlias

protected string|null $fromTableAlias = null

$phaseOneOnly

protected bool $phaseOneOnly = false

$textTableAlias

protected string|null $textTableAlias = null

Methods

__construct()

public __construct(int $parameterId, float|null $from, float|null $to[, string $relation = 'parameterRels' ][, string $parameterIdColumn = 'parameterId' ][, string $valueColumn = 'value' ][, string $value2Column = 'value2' ]) : mixed
Parameters
$parameterId : int
$from : float|null
$to : float|null
$relation : string = 'parameterRels'
$parameterIdColumn : string = 'parameterId'
$valueColumn : string = 'value'
$value2Column : string = 'value2'

appliesToCollections()

Tells whether the filter also applies to ToMany branch queries (phase 2 of hydration).

public appliesToCollections() : bool

The filter decides which parents are returned (phase 1); includes decide what is loaded for them, and always in full. A dotted filter is therefore not propagated to the branch query (OrmRepository::filtersForBranch()): otherwise the collection would be silently trimmed to the matching subset and an object-graph save would INSERT the unmatched children again (UNIQUE violation, the save works only the first time).

setApplyToCollections(true) is an explicit opt-in for the rare caller that really wants the trimmed collection (e.g. orders loaded only with items X); such a caller must not save anything through it afterwards.

Return values
bool

apply()

Applies the filter to the Doctrine QueryBuilder.

public apply(QueryBuilder $qb, int|string $index) : void
Parameters
$qb : QueryBuilder
$index : int|string

applyWithCondition()

Default implementation for simple operators (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`, `NOT LIKE`).

public applyWithCondition(QueryBuilder $qb, string $joinAlias, string $column, int &$paramIndex) : string|null

Special filters (IS NULL, IN, BETWEEN, RANGE) override this method.

Parameters
$qb : QueryBuilder
$joinAlias : string
$column : string
$paramIndex : int

parameter counter passed by reference (incremented inside)

Return values
string|null

getBindings()

Returns no bindings; {@see self::apply()} builds the whole query directly in the QueryBuilder.

public getBindings([string|int|null $index = null ]) : ArrayCollection<int, mixed>
Parameters
$index : string|int|null = null
Return values
ArrayCollection<int, mixed>

getFields()

Returns the field or fields the filter applies to.

public getFields() : array<string|int, string>
Return values
array<string|int, string>

getOperator()

public getOperator() : string
Return values
string

getType()

Returns the filter type/operator (e.g. '=', 'LIKE', 'IN').

public getType() : string
Return values
string

getValue()

Returns the filter value.

public getValue() : mixed

isPhaseOneOnly()

When true, the filter applies only to phase 1 (root ID selection) and does not leak into the ToMany branch queries of the second hydration phase.

public isPhaseOneOnly() : bool

Use case: searching adverts by a single parameter — find adverts that have that parameter, but in the detail load all of their parameters, not just the filtered one.

Return values
bool

setApplyToCollections()

public setApplyToCollections([bool $applyToCollections = true ]) : static
Parameters
$applyToCollections : bool = true
Return values
static

setFields()

Sets the field or fields the filter applies to.

public setFields(array<string|int, string>|string $fields) : static
Parameters
$fields : array<string|int, string>|string
Return values
static

setFromTableAlias()

Sets the alias of the main table for join operations.

public final setFromTableAlias(string|null $alias) : static
Parameters
$alias : string|null
Return values
static

setPhaseOneOnly()

public setPhaseOneOnly([bool $phaseOneOnly = true ]) : static
Parameters
$phaseOneOnly : bool = true
Return values
static

setTextTableAlias()

Sets the alias of the text (translations) table for join operations.

public final setTextTableAlias(string|null $alias) : static
Parameters
$alias : string|null
Return values
static

toSql()

Builds the SQL condition for the filter.

public toSql(QueryBuilder $qb[, int|null $index = null ]) : string
Parameters
$qb : QueryBuilder
$index : int|null = null
Return values
string
On this page

Search results