CoolCMS API

ParameterRuleGraphTrait uses trait:short

Shared raw-DBAL synchronization of the display rule graph (`ParameterRule`) from `meta['rules']`.

Parameterized by the target column in cms_mod_<module>_parameter_rule_targets (group, parameter or option) and the rule action. The thin wrappers ParameterGroupRuleSyncTrait, ParameterRuleSyncTrait and OptionRuleSyncTrait supply their target; used by the Bazaar and Eshop parameter managers (tables named by ParameterTablesTrait).

Raw DBAL instead of ORM persist: the rule entities have composite/derived primary keys whose scalar column is shared with the parent association, which breaks ORM writes. A rule is also not owned by its target (the link is only the target row), so object-graph save with orphanRemoval would delete shared rules. Runs on the same connection and transaction as service->save() (uses $this->em, the default entity manager).

meta['rules'] contract (no longer sent by the admin): list<{parameterRuleId:?int, conditions: list<{parameterId:int, validator:string, optionIds:list<int>, values:list<string>}>}>. When the rules key arrives the whole graph is synchronized; otherwise nothing happens. Each condition has one source (the parameter), function = null (the front end combines conditions with AND) and a 1-based key.

Table of Contents

Properties

$em  : EntityManagerInterface

Methods

parameterTablePrefix()  : string
Module part of the parameter table names: `'bazaar'`, `'comcat'` or `'eshop'`.
deleteRulesForTarget()  : void
Deletes the rules targeted at `$targetColumn == $targetId` with all their child rows (5 tables).
detachTargetAndGc()  : void
Detaches the target from the rule (deletes only this target row).
insertOptionRevealRuleGraph()  : void
Inserts a `SHOW_SELECT_OPTIONS` rule (action 1): conditions plus one target row per revealed option.
insertRuleWithConditions()  : int
Inserts a rule (`$action`) with its conditions (per condition: source, condition and condition values).
normalizeRuleConditions()  : array<int, array{parameterId: int, validator: string, optionIds: list, values: list}>
Normalizes rule conditions (shared by `HIDE` and `SHOW_SELECT_OPTIONS`): source parameter, validator and values (`optionIds` for option parameters, text `values` otherwise).
normalizeRulesMeta()  : array<int, array{parameterRuleId: ?int, conditions: list, values: list}>}>
parameterSqlName()  : string
`cms_mod_<module>_<name>`: a parameter table, or a FK column named after one.
ruleExistsForAction()  : bool
Tells whether rule `$ruleId` of the given action exists (guards against a foreign or unknown id from the form).
safeRuleTargetColumn()  : string
Whitelists the target column, which is interpolated into SQL (guards against mix-ups and injection).
syncRulesForTarget()  : void
Upserts the rules targeted at `$targetColumn == $targetId` from `meta['rules']` (rule reuse).
targetRuleIds()  : array<int, int>
Returns the ids of the rules (of the given action) that the target currently controls.
updateRuleConditions()  : void
Rewrites the conditions of the existing rule `$ruleId` in place.
upsertTargetRow()  : void
Attaches the target to the rule (one target row) idempotently.
writeRuleConditions()  : void
Writes the conditions of rule `$ruleId` (per condition: source, condition and condition values).

Properties

Methods

parameterTablePrefix()

Module part of the parameter table names: `'bazaar'`, `'comcat'` or `'eshop'`.

protected abstract parameterTablePrefix() : string
Return values
string

deleteRulesForTarget()

Deletes the rules targeted at `$targetColumn == $targetId` with all their child rows (5 tables).

private deleteRulesForTarget(Connection $connection, string $targetColumn, int $targetId[, int|null $action = null ]) : void

With $action set, only rules of that action are deleted (tells HIDE from SHOW_SELECT_OPTIONS on the shared parameter_id).

Parameters
$connection : Connection
$targetColumn : string
$targetId : int
$action : int|null = null

detachTargetAndGc()

Detaches the target from the rule (deletes only this target row).

private detachTargetAndGc(Connection $connection, string $targetColumn, int $targetId, int $ruleId) : void

A rule left without any target is orphaned, so it is deleted with its conditions, values and sources. A rule shared with another target survives.

Parameters
$connection : Connection
$targetColumn : string
$targetId : int
$ruleId : int

insertOptionRevealRuleGraph()

Inserts a `SHOW_SELECT_OPTIONS` rule (action 1): conditions plus one target row per revealed option.

private insertOptionRevealRuleGraph(Connection $connection, int $parentSelectId, array<int, int> $revealOptionIds, array{conditions: list, values: list}>} $rule) : void

Each target row carries both parameter_id (the parent select) and option_id. The front end reads only option_id; parameter_id serves the load/delete filter.

Parameters
$connection : Connection
$parentSelectId : int
$revealOptionIds : array<int, int>
$rule : array{conditions: list, values: list}>}

insertRuleWithConditions()

Inserts a rule (`$action`) with its conditions (per condition: source, condition and condition values).

private insertRuleWithConditions(Connection $connection, int $action, array{conditions: list, values: list}>} $rule) : int

The caller adds the targets (HIDE has a single target, SHOW_SELECT_OPTIONS has one per option).

Parameters
$connection : Connection
$action : int
$rule : array{conditions: list, values: list}>}
Return values
int —

id of the inserted rule

normalizeRuleConditions()

Normalizes rule conditions (shared by `HIDE` and `SHOW_SELECT_OPTIONS`): source parameter, validator and values (`optionIds` for option parameters, text `values` otherwise).

private normalizeRuleConditions(mixed $conditionsRaw) : array<int, array{parameterId: int, validator: string, optionIds: list, values: list}>
Parameters
$conditionsRaw : mixed
Return values
array<int, array{parameterId: int, validator: string, optionIds: list, values: list}>

normalizeRulesMeta()

private normalizeRulesMeta(mixed $raw) : array<int, array{parameterRuleId: ?int, conditions: list, values: list}>}>
Parameters
$raw : mixed
Return values
array<int, array{parameterRuleId: ?int, conditions: list, values: list}>}>

parameterSqlName()

`cms_mod_<module>_<name>`: a parameter table, or a FK column named after one.

private parameterSqlName(string $name) : string
Parameters
$name : string
Return values
string

ruleExistsForAction()

Tells whether rule `$ruleId` of the given action exists (guards against a foreign or unknown id from the form).

private ruleExistsForAction(Connection $connection, int $ruleId, int $action) : bool
Parameters
$connection : Connection
$ruleId : int
$action : int
Return values
bool

safeRuleTargetColumn()

Whitelists the target column, which is interpolated into SQL (guards against mix-ups and injection).

private safeRuleTargetColumn(string $column) : string
Parameters
$column : string
Return values
string

syncRulesForTarget()

Upserts the rules targeted at `$targetColumn == $targetId` from `meta['rules']` (rule reuse).

private syncRulesForTarget(string $targetColumn, int $targetId, int $action, array<string, mixed> $meta) : void
  • parameterRuleId > 0 (existing, same action): rewrites only its conditions in place (the change shows on all targets sharing the rule) and attaches this target idempotently;
  • otherwise: creates a new rule and attaches the target;
  • rules this target controlled before but that are no longer in the form: detaches only this target (a shared rule survives on other targets); the rule is deleted when no target remains.

Delete-all plus reinsert is not an option: it would mint new ids and delete shared rules. Does nothing unless the rules key is present.

Parameters
$targetColumn : string
$targetId : int
$action : int
$meta : array<string, mixed>

targetRuleIds()

Returns the ids of the rules (of the given action) that the target currently controls.

private targetRuleIds(Connection $connection, string $targetColumn, int $targetId, int $action) : array<int, int>
Parameters
$connection : Connection
$targetColumn : string
$targetId : int
$action : int
Return values
array<int, int>

updateRuleConditions()

Rewrites the conditions of the existing rule `$ruleId` in place.

private updateRuleConditions(Connection $connection, int $ruleId, array<int, array{parameterId: int, validator: string, optionIds: list, values: list}> $conditions) : void

Deletes the old conditions, values and sources and writes the new ones. The rule row and its targets stay, so the change shows on all targets sharing the rule.

Parameters
$connection : Connection
$ruleId : int
$conditions : array<int, array{parameterId: int, validator: string, optionIds: list, values: list}>

upsertTargetRow()

Attaches the target to the rule (one target row) idempotently.

private upsertTargetRow(Connection $connection, string $targetColumn, int $targetId, int $ruleId) : void

The existence check is done in PHP because the unique key does not cover rows with option_id null (nulls are distinct).

Parameters
$connection : Connection
$targetColumn : string
$targetId : int
$ruleId : int

writeRuleConditions()

Writes the conditions of rule `$ruleId` (per condition: source, condition and condition values).

private writeRuleConditions(Connection $connection, int $ruleId, array<int, array{parameterId: int, validator: string, optionIds: list, values: list}> $conditions) : void

key is a 1-based ordinal and function is null (the front end combines with AND).

Parameters
$connection : Connection
$ruleId : int
$conditions : array<int, array{parameterId: int, validator: string, optionIds: list, values: list}>
On this page

Search results