CategoryParameterRelSyncTrait
Synchronizes the parameter targeting of a category (`categoryParameterRels`) in `afterSave` and propagates it to the whole subtree.
The rels are not saved through the object graph (Api Category maps them without
cascade/orphanRemoval, so they are in defaultSkipFields). The admin form sends
meta['parameterRels'], a flat list of rows {parameterId, parameterGroupId, required, useInSearch, order} (parameters and their options; options have parameterGroupId = null).
They are converted to entities and saved via updateColumn(..., 'categoryParameterRels', ...),
which does delete-all + insert through the mapper.
Default vs. custom targeting: the front end gates on useDefaultParameters. With true it
takes the global default parameters (default=1) and ignores the category rels; with false
it uses the category rels (see
LoadingTrait::loadParameters()).
So the rels of this category are overwritten only for custom targeting; with the default they
are left alone and can be restored by unchecking the flag.
Subtree propagation (on request): the useDefaultParameters flag is always propagated; the
rels only for custom targeting. With the default only the flag spreads, so each descendant
keeps its own rels and does not lose its specific settings.
IMPORTANT: the meta['parameterRels'] key is told from its absence with array_key_exists(),
not ?? or empty(). A missing key (external Api save, import, any save that knows nothing
about parameters) leaves the stored rels untouched; only an explicitly sent list, the empty
one included, replaces them (an empty list = delete all). Propagation requested without the
key pushes the rels already stored on the category.
Tags
Table of Contents
Methods
- newCategoryParameterRel() : CategoryParameterRelInterface
- A new, empty targeting row of the module (Api layer), filled for the category or a descendant.
- buildParameterRelEntities() : array<int, CategoryParameterRelInterface>
- normalizeParameterRelsMeta() : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
- Normalizes and deduplicates rel data from `meta['parameterRels']`. A parameter may appear in a category only once (composite PK = category + parameterId), so a duplicate `parameterId` is dropped (the first wins).
- propagateParameterRelsToDescendants() : void
- `$relsData = null` (the key was not sent) propagates the rels stored on the category.
- storedParameterRelsData() : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
- Converts the rels stored on the category to the shape of {@see normalizeParameterRelsMeta()}.
- syncCategoryParameterRels() : void
Methods
newCategoryParameterRel()
A new, empty targeting row of the module (Api layer), filled for the category or a descendant.
protected
abstract newCategoryParameterRel() : CategoryParameterRelInterface
Return values
CategoryParameterRelInterfacebuildParameterRelEntities()
private
buildParameterRelEntities(int $categoryId, array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}> $relsData) : array<int, CategoryParameterRelInterface>
Parameters
- $categoryId : int
- $relsData : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
Return values
array<int, CategoryParameterRelInterface>normalizeParameterRelsMeta()
Normalizes and deduplicates rel data from `meta['parameterRels']`. A parameter may appear in a category only once (composite PK = category + parameterId), so a duplicate `parameterId` is dropped (the first wins).
private
normalizeParameterRelsMeta(array<string, mixed> $meta) : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
Parameters
- $meta : array<string, mixed>
Return values
array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>propagateParameterRelsToDescendants()
`$relsData = null` (the key was not sent) propagates the rels stored on the category.
private
propagateParameterRelsToDescendants(int $categoryId, bool $useDefaultParameters, array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>|null $relsData) : void
Parameters
- $categoryId : int
- $useDefaultParameters : bool
- $relsData : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>|null
storedParameterRelsData()
Converts the rels stored on the category to the shape of {@see normalizeParameterRelsMeta()}.
private
storedParameterRelsData(AdvertCategoryInterface $category) : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
Parameters
- $category : AdvertCategoryInterface
Return values
array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>syncCategoryParameterRels()
private
syncCategoryParameterRels(AdvertCategoryInterface $category, array<string, mixed> $meta) : void
Parameters
- $category : AdvertCategoryInterface
- $meta : array<string, mixed>