CoolCMS API

CategoryFormTrait

Add and edit form of a company catalog category.

Translated fields (name, URL, info in the editor, meta*) are per language; untranslated are the parent category (tree, picker), flags (free, active, admin only, preferred) and economy (credits, company profile validity). The Api computes nested-set indexes: save() for a new category, moveSubtree() when the parent changes. The main image is saved through $meta and the Api afterSave hook, which creates the variants and sets the FK.

Table of Contents

Properties

$categoryParameterGroupOptions  : array<int, NotTranslate>|null
$categoryParameterOptionDefaults  : array<int, array<int, int>>

Methods

createComponentEditForm()  : Form
addCategoryParameterFields()  : void
Adds the "parameter settings" section: a "use default parameters" switch and nested multipliers.
addCategoryParameterRowControls()  : void
Fields of one row of the nested parameter multiplier (picker fields, flags and options).
addCategoryPriceMatrix()  : void
Adds the category price matrix: a price field and an active checkbox for every payment region x gate combination.
addCategoryStructureFields()  : void
Structure, flags and economy. The parent (tree) is a hidden field filled by the picker.
addCategoryTranslationFields()  : void
Translated fields: one set per language (`<field>_<langId>`), active by the checkbox.
applyCategoryParameterDefaults()  : void
Sets the defaults of the parameter section on GET, for a new and an edited category.
buildCategoryEntity()  : Category
buildCategoryParameterDefaultGroups()  : array<int, array{parameterGroupId: int, parameters: list}>
Builds the nested multiplier rows from the saved rels of the edited category.
buildCategoryParameterRelsMeta()  : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
Builds `meta['parameterRels']` from the nested multiplier values.
buildCategoryPrices()  : ArrayCollection<int, CategoryPrice>
Builds the price matrix as the owned `CategoryPrice` collection (scalar region, gate, currency).
buildGlobalDefaultParameterGroups()  : array<int, array{parameterGroupId: int, parameters: list}>
Builds the global default parameters for prefilling: top-level parameters with `default=1` (no parent), grouped by parameter group.
categoryFormLangId()  : int
categoryRowField()  : mixed
Reads a field of a multiplier row safely (`ArrayHash` or array).
categoryRowInt()  : int
Returns a multiplier row field as an int (0 when missing or non-numeric).
collectCategoryImageMeta()  : array<string, mixed>
Builds `$meta` for the save: a new image (base64) and/or the delete flag.
getCategoryParameterGroupOptions()  : array<int, NotTranslate>
Returns the parameter groups as a select option list (id to name in the current language).
getCategoryParameterOptionItems()  : array<int, string>
Returns the child parameters (options) of a parameter as checkbox list items (id to name).
isCategoryHrefUnique()  : bool
Validates that the href is unique in the given language.
loadCategoryParameterNames()  : array<int, string>
loadCategoryParameterParentMap()  : array<int, int|null>
parameterGroupName()  : string
Returns the parameter group name in the given language (falls back to the first non-empty one).
refreshCategoryParameterOptions()  : void
Sets the option checkbox list items of every row after the anchor.
saveCategoryForm()  : bool
setCategoryFormDefaults()  : void

Properties

$categoryParameterGroupOptions

private array<int, NotTranslate>|null $categoryParameterGroupOptions = null

cache of the parameter group select options (id to name)

$categoryParameterOptionDefaults

private array<int, array<int, int>> $categoryParameterOptionDefaults = []

parameter id mapped to the ids of default checked options (on edit)

Methods

addCategoryParameterFields()

Adds the "parameter settings" section: a "use default parameters" switch and nested multipliers.

private addCategoryParameterFields(Form $form) : void

The multipliers look like the resulting company profile form (section, then field):

  • outer parameterGroups: groups (a row is a parameterGroupId select),
  • nested parameters (in every group row): the group parameters (a row is a parameter picker parameterId + parameterName + required + search + options).

The picker in the nested multiplier addresses two index levels ({control "picker-parameter_<g>_<p>"}), see ParameterPickerTrait::parameterPicker(). Adding and removing a row (group or parameter) runs over AJAX and redraws the parameterGroups snippet.

Parameters
$form : Form

addCategoryParameterRowControls()

Fields of one row of the nested parameter multiplier (picker fields, flags and options).

private addCategoryParameterRowControls(Container $container) : void
Parameters
$container : Container

addCategoryPriceMatrix()

Adds the category price matrix: a price field and an active checkbox for every payment region x gate combination.

private addCategoryPriceMatrix(Form $form) : void

The currency is the currency of the gate's region rel, falling back to the region currency; the price is price_for_unlogged. The presenter supplies the axes ($this->categoryRegions, categoryGates). Applies only when the category is not free.

Parameters
$form : Form

addCategoryStructureFields()

Structure, flags and economy. The parent (tree) is a hidden field filled by the picker.

private addCategoryStructureFields(Form $form) : void
Parameters
$form : Form

addCategoryTranslationFields()

Translated fields: one set per language (`<field>_<langId>`), active by the checkbox.

private addCategoryTranslationFields(Form $form) : void
Parameters
$form : Form

applyCategoryParameterDefaults()

Sets the defaults of the parameter section on GET, for a new and an edited category.

private applyCategoryParameterDefaults(Form $form) : void

The rows come from the saved rels of the edited category, or (new category / no own rels) from the global default parameters (default=1) with their options. The "use default parameters" flag is set only for an edited category. The option checkbox lists are filled in onAnchor from $categoryParameterOptionDefaults.

Parameters
$form : Form

buildCategoryEntity()

private buildCategoryEntity(ArrayHash<string|int, mixed> $values) : Category
Parameters
$values : ArrayHash<string|int, mixed>
Return values
Category

buildCategoryParameterDefaultGroups()

Builds the nested multiplier rows from the saved rels of the edited category.

private buildCategoryParameterDefaultGroups(Category $category) : array<int, array{parameterGroupId: int, parameters: list}>

Groups parameters by parameterGroupId (in order of first occurrence) into group rows, each with its own parameters, and fills the default option map ($categoryParameterOptionDefaults).

Parameters
$category : Category
Return values
array<int, array{parameterGroupId: int, parameters: list}>

buildCategoryParameterRelsMeta()

Builds `meta['parameterRels']` from the nested multiplier values.

private buildCategoryParameterRelsMeta(ArrayHash<string|int, mixed> $values) : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>

For every group it emits its parameters plus their options as flat rel rows. The parameter group is the parameterGroupId of the group row; options are child parameters with parameterGroupId = null. With "use default parameters" it returns an empty array and the Api sync then leaves the saved rels untouched, so the category's own setup survives for a later return (see CategoryParameterRelSyncTrait).

Parameters
$values : ArrayHash<string|int, mixed>
Return values
array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>

buildCategoryPrices()

Builds the price matrix as the owned `CategoryPrice` collection (scalar region, gate, currency).

private buildCategoryPrices(ArrayHash<string|int, mixed> $values) : ArrayCollection<int, CategoryPrice>

The price currency is the currency of the gate's region rel (credits map to KRD), falling back to the region currency. It must match the front-end lookup, see CategoryPriceGridTrait; the entered price is price_for_unlogged. An empty cell means no row, the same as the discussion category and the tariff price list (the front end offers only stored rows); building every combination made a save without changes add rows with price 0.

Parameters
$values : ArrayHash<string|int, mixed>
Return values
ArrayCollection<int, CategoryPrice>

buildGlobalDefaultParameterGroups()

Builds the global default parameters for prefilling: top-level parameters with `default=1` (no parent), grouped by parameter group.

private buildGlobalDefaultParameterGroups() : array<int, array{parameterGroupId: int, parameters: list}>

Also fills the default option map ($categoryParameterOptionDefaults) with child parameters that have default=1; other options render unchecked in onAnchor. required and useInSearch come from the parameter. A parameter without a group is skipped because it cannot be placed into the group multiplier.

Return values
array<int, array{parameterGroupId: int, parameters: list}>

categoryRowField()

Reads a field of a multiplier row safely (`ArrayHash` or array).

private categoryRowField(mixed $row, string $key) : mixed
Parameters
$row : mixed
$key : string

categoryRowInt()

Returns a multiplier row field as an int (0 when missing or non-numeric).

private categoryRowInt(mixed $row, string $key) : int
Parameters
$row : mixed
$key : string
Return values
int

collectCategoryImageMeta()

Builds `$meta` for the save: a new image (base64) and/or the delete flag.

private collectCategoryImageMeta(ArrayHash<string|int, mixed> $values) : array<string, mixed>

The Api creates the Asset (variants) from it and sets the FK to the main image (afterSave processMainImage).

Parameters
$values : ArrayHash<string|int, mixed>
Return values
array<string, mixed>

getCategoryParameterGroupOptions()

Returns the parameter groups as a select option list (id to name in the current language).

private getCategoryParameterGroupOptions() : array<int, NotTranslate>

The name is already translated data, not a key, hence NotTranslate; otherwise the form translator looks it up as a key and Tracy reports a missing translation.

Return values
array<int, NotTranslate>

getCategoryParameterOptionItems()

Returns the child parameters (options) of a parameter as checkbox list items (id to name).

private getCategoryParameterOptionItems(int $parameterId) : array<int, string>
Parameters
$parameterId : int
Return values
array<int, string>

isCategoryHrefUnique()

Validates that the href is unique in the given language.

private isCategoryHrefUnique(TextInput $input, int $langId) : bool

The edited category is excluded on edit; an empty href is not checked.

Parameters
$input : TextInput
$langId : int
Return values
bool

loadCategoryParameterNames()

private loadCategoryParameterNames(array<int, int> $parameterIds) : array<int, string>
Parameters
$parameterIds : array<int, int>
Return values
array<int, string> —

parameter id mapped to its name

loadCategoryParameterParentMap()

private loadCategoryParameterParentMap(array<int, int> $parameterIds) : array<int, int|null>
Parameters
$parameterIds : array<int, int>
Return values
array<int, int|null> —

parameter id mapped to its parent id

parameterGroupName()

Returns the parameter group name in the given language (falls back to the first non-empty one).

private parameterGroupName(ParameterGroup $group, int $langId) : string
Parameters
$group : ParameterGroup
$langId : int
Return values
string

refreshCategoryParameterOptions()

Sets the option checkbox list items of every row after the anchor.

private refreshCategoryParameterOptions(Form $form) : void

The items are the child parameters of the selected parameter. On GET (not a submit) the saved options from the edit are prefilled; on submit httpData holds them.

Parameters
$form : Form

saveCategoryForm()

private saveCategoryForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool
On this page

Search results