AdvertLoadingTrait
Loads the dynamic advert parameters for the selected categories, the select items (currency, region) and the pre-filled values of an edited advert.
Hands values to and from ParameterFieldBuilder instead of keeping engine state. The admin always
uses the form mode, so the type is parameter.getType().
Resolved ParameterFormItem[]:
- no category selected: no parameters at all,
- default parameters (the first selected category has
useDefaultParameters): order islft; required andgroupIdcome from theParameterentity, - category-rel parameters: required is true if any category requires it, order is the minimum,
groupIdis the first non-null one.
Table of Contents
Methods
- aggregateCategoryParameterRels() : array<int, array{order: int, required: bool, groupId: ?int}>
- Aggregates the `CategoryParameterRel` rows across categories into one entry per parameter id: minimum order, required if any category requires it, first non-null group id.
- buildCurrencyItems() : array<int, string>
- buildParameterContext() : ParameterFormContext
- Fills {@see ParameterFormContext} (`languageId` and the items for the currency/region selects).
- buildRegionItems() : array<int, string>
- Builds the items of a `SELECT_REGION` parameter: a plain `<select>`, not a Picker.
- getEntityValues() : array<int, mixed>
- Returns the pre-filled values of the dynamic parameters from the edited advert (`parameterRels`).
- getRegionLabel() : string
- itemsHaveType() : bool
- loadParameterGroups() : array<string|int, ParameterGroupInterface>
- loadParameters() : array<string|int, ParameterFormItem>
Methods
aggregateCategoryParameterRels()
Aggregates the `CategoryParameterRel` rows across categories into one entry per parameter id: minimum order, required if any category requires it, first non-null group id.
private
aggregateCategoryParameterRels(array<string|int, Category> $categories) : array<int, array{order: int, required: bool, groupId: ?int}>
Parameters
- $categories : array<string|int, Category>
Return values
array<int, array{order: int, required: bool, groupId: ?int}>buildCurrencyItems()
private
buildCurrencyItems() : array<int, string>
Return values
array<int, string>buildParameterContext()
Fills {@see ParameterFormContext} (`languageId` and the items for the currency/region selects).
private
buildParameterContext(array<string|int, ParameterFormItem> $items) : ParameterFormContext
Parameters
- $items : array<string|int, ParameterFormItem>
Return values
ParameterFormContextbuildRegionItems()
Builds the items of a `SELECT_REGION` parameter: a plain `<select>`, not a Picker.
private
buildRegionItems(int|null $langId) : array<int, string>
IMPORTANT: only country and region (level <= 2). After the municipalities are imported into
cms_system_regions (thousands of nodes), an unfiltered findAll() would flood the select.
Municipality and district are chosen in the suggester, not here.
Parameters
- $langId : int|null
Return values
array<int, string>getEntityValues()
Returns the pre-filled values of the dynamic parameters from the edited advert (`parameterRels`).
private
getEntityValues() : array<int, mixed>
Return values
array<int, mixed>getRegionLabel()
private
getRegionLabel(Region $region, int|null $langId) : string
Parameters
- $region : Region
- $langId : int|null
Return values
stringitemsHaveType()
private
itemsHaveType(array<string|int, ParameterFormItem> $items, int $type) : bool
Parameters
- $items : array<string|int, ParameterFormItem>
- $type : int
Return values
boolloadParameterGroups()
private
loadParameterGroups(array<string|int, ParameterFormItem> $items) : array<string|int, ParameterGroupInterface>
Parameters
- $items : array<string|int, ParameterFormItem>
Return values
array<string|int, ParameterGroupInterface>loadParameters()
private
loadParameters(array<string|int, Category> $categories) : array<string|int, ParameterFormItem>
Parameters
- $categories : array<string|int, Category>