CoolCMS API

ParameterGroupRuleSyncTrait uses trait:short

Synchronizes display rules (`ParameterRule`) targeted at a parameter group.

A thin wrapper over the shared ParameterRuleGraphTrait: the target is a group (column cms_mod_<module>_parameter_groups_parameter_group_id), the action is HIDE (toggles the group in the item form). Called from ParameterGroupManager::afterSave (Bazaar, Eshop) with meta['rules'].

NOTE: the meta['rules'] key is deprecated and has no real producer (the admin writes through the immediate-save RuleEditor, not this save path). Do not promote it to graphDataKeys (the public data contract): the delete-all semantics of syncRulesForTarget is a footgun without a real client.

Table of Contents

Properties

$em  : EntityManagerInterface

Methods

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}>}>
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).
syncGroupRules()  : void
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

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}>}>

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