ParameterRuleEvaluator
in package
Evaluates parameter rules (display, required, option reveal) over submitted values, without a form.
The front form applies the rules as Nette form conditions (RulesTrait) and as dependent select items
(DependentSelectTrait); the Api save has no form, so it asks this class the same questions. Two condition
semantics exist on purpose, each copied from its front counterpart:
- display and required (formConditionHolds()): the Nette validator of the condition (
Validator::validate*) over the value as the form control holds it, so:equalover a multi value requires every value to match; - option reveal (optionConditionHolds()): the dependent select check, where
:equalneeds one match and other validators accept everything.
Rules and items are plain arrays (scalar reads in the Api, entities in the front):
- rule:
{sources: list<int>, conditions: list<{parameterId: int, validator: string, expected: list<string>}>, targets: list<{parameterId: ?int, groupId: ?int, optionId: ?int}>}; - item (a parameter of the advert's categories):
{required: bool, groupId: ?int, type: ?int}; - values:
parameterId => list<string>(one entry per stored row, empty rows dropped).
Tags
Table of Contents
Constants
- LIST_TYPES : array<string|int, mixed> = [\App\Core\Base\Shared\Shared\Models\Entities\P...
- Types whose form control holds a list (`MultiSelectBox`, `CheckboxList`).
Methods
- allowedOptionIds() : array<int, int>|null
- Options of a choice parameter the form offers (`DependentSelectTrait::buildDependentData()`): those no rule controls, plus the targets of rules whose conditions all hold. `null` when no rule controls an option of it (every option allowed).
- controlValue() : mixed
- The stored rows as the form control would hold them: a list for multi choices, a bool for a checkbox, otherwise the first value (`null` when there is none, like an empty select).
- formConditionHolds() : bool
- A display/required condition the way the Nette form evaluates `addConditionOn()`: `:filled`/`:blank` by `BaseControl::isFilled()` (a checkbox is filled when checked), the rest by `Validator::validate*()` with the argument the form passes (the list for array validators, otherwise its first item).
- optionConditionHolds() : bool
- An option reveal condition (`DependentSelectTrait::isConditionMet()`): `:equal` needs one match, `:notEqual` none, `:all_in` every value among the expected ones; `:filled`/`:blank` by emptiness; other validators accept everything.
- requiredParameterIds() : array<int, int>
- Parameters that must have a value (`RulesTrait::initializeFormRules()` and `initializeRequiredRules()`): an item required in the categories is required unless a rule targets it (directly or through its group); a targeted one is required only while all conditions of one of those rules hold. A rule acts only when one of its sources is an item, and a condition over a parameter that is not an item is left out, as in the form.
- activeRules() : array<int, Rule>
- Rules that take part: one of the sources is an item (the form collects rules from its parameters).
Constants
LIST_TYPES
Types whose form control holds a list (`MultiSelectBox`, `CheckboxList`).
private
array<string|int, mixed>
LIST_TYPES
= [\App\Core\Base\Shared\Shared\Models\Entities\ParameterType::MULTISELECT, \App\Core\Base\Shared\Shared\Models\Entities\ParameterType::CHECKBOXLIST]
Methods
allowedOptionIds()
Options of a choice parameter the form offers (`DependentSelectTrait::buildDependentData()`): those no rule controls, plus the targets of rules whose conditions all hold. `null` when no rule controls an option of it (every option allowed).
public
static allowedOptionIds(array<int, Rule> $rules, array<int, int> $optionIds, array<int, array<int, string>> $values) : array<int, int>|null
Parameters
- $rules : array<int, Rule>
- $optionIds : array<int, int>
-
options of the parameter
- $values : array<int, array<int, string>>
Return values
array<int, int>|nullcontrolValue()
The stored rows as the form control would hold them: a list for multi choices, a bool for a checkbox, otherwise the first value (`null` when there is none, like an empty select).
public
static controlValue(int|null $type, array<int, string> $rows) : mixed
Parameters
- $type : int|null
- $rows : array<int, string>
formConditionHolds()
A display/required condition the way the Nette form evaluates `addConditionOn()`: `:filled`/`:blank` by `BaseControl::isFilled()` (a checkbox is filled when checked), the rest by `Validator::validate*()` with the argument the form passes (the list for array validators, otherwise its first item).
public
static formConditionHolds(string $validator, mixed $value, array<int, string> $expected) : bool
Parameters
- $validator : string
- $value : mixed
- $expected : array<int, string>
Return values
booloptionConditionHolds()
An option reveal condition (`DependentSelectTrait::isConditionMet()`): `:equal` needs one match, `:notEqual` none, `:all_in` every value among the expected ones; `:filled`/`:blank` by emptiness; other validators accept everything.
public
static optionConditionHolds(string $validator, mixed $value, array<int, string> $expected) : bool
Parameters
- $validator : string
- $value : mixed
- $expected : array<int, string>
Return values
boolrequiredParameterIds()
Parameters that must have a value (`RulesTrait::initializeFormRules()` and `initializeRequiredRules()`): an item required in the categories is required unless a rule targets it (directly or through its group); a targeted one is required only while all conditions of one of those rules hold. A rule acts only when one of its sources is an item, and a condition over a parameter that is not an item is left out, as in the form.
public
static requiredParameterIds(array<int, Rule> $rules, array<int, Item> $items, array<int, array<int, string>> $values) : array<int, int>
Parameters
- $rules : array<int, Rule>
- $items : array<int, Item>
- $values : array<int, array<int, string>>
Return values
array<int, int>activeRules()
Rules that take part: one of the sources is an item (the form collects rules from its parameters).
private
static activeRules(array<int, Rule> $rules, array<int, Item> $items) : array<int, Rule>
Parameters
- $rules : array<int, Rule>
- $items : array<int, Item>