CoolCMS API

CategoryFormTrait

Add/edit form of an advert category.

Translated fields are the multilingual ones (name, URL, editor info, meta*); not translated are the parent category (tree, picker), the flags (free, active, admin-only, preferred) and the economy (credits, advert validity).

The Api maintains the nested-set indexes: save() for a new category (insertTreeNode through TreeNodeInterface), moveSubtree() when the parent changes. See CategoryFormTrait.

The main image is saved through $meta into the Api afterSave (creates the variants, sets the FK).

Table of Contents

Properties

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

Methods

createComponentEditForm()  : Form
addCategoryParameterFields()  : void
Section "parameter settings": the "use default parameters" switch plus nested multipliers that look like the resulting advert form (section, then fields): - outer `parameterGroups` = groups (row = `parameterGroupId` select), - nested `parameters` (in every group row) = the group's parameters (row = parameter Picker `parameterId` + `parameterName` + required + search + options).
addCategoryParameterRowControls()  : void
Fields of one row of the nested parameters multiplier (Picker field, flags, options).
addCategoryPriceMatrix()  : void
Price matrix of the category: for each payment region x payment gateway combination a price field plus an active checkbox (currency is the currency of the gateway's region-rel, falling back to the region currency; price is `price_for_unlogged`). The presenter supplies the axes (`$this->categoryRegions`, `categoryGates`). Applies when the category is not free.
addCategoryStructureFields()  : void
Structure, flags, economy. The parent (tree) is a hidden field filled by a Picker.
addCategoryTranslationFields()  : void
Multilingual fields: one set per language (`<field>_<langId>`), active per the language checkbox.
applyCategoryParameterDefaults()  : void
Sets the defaults of the parameters section (on GET, for a new and an edited category): - the stored rels of the edited category, or (new category / no own rels) the global default parameters (`default=1`) with their options, - the "use default parameters" flag (edited category only).
buildCategoryEntity()  : Category
buildCategoryParameterDefaultGroups()  : array<int, array{parameterGroupId: int, parameters: list}>
Returns the nested multiplier rows from the stored rels of the edited category: groups the parameters by `parameterGroupId` (in order of first occurrence) into group rows, each with its own parameters; also fills the map of default options ({@see $categoryParameterOptionDefaults}).
buildCategoryParameterRelsMeta()  : array<int, array{parameterId: int, parameterGroupId: ?int, required: bool, useInSearch: bool, order: int}>
Builds `meta['parameterRels']` from the nested multiplier values: for every group its parameters plus their options, as flat rel rows. A parameter's group is the `parameterGroupId` of the group row; options are child parameters with `parameterGroupId = null`.
buildCategoryPrices()  : ArrayCollection<int, CategoryPrice>
Builds the owned `CategoryPrice` collection from the price matrix (scalar region/gateway/currency).
buildGlobalDefaultParameterGroups()  : array<int, array{parameterGroupId: int, parameters: list}>
Returns the global default parameters for pre-filling: top-level parameters with `default=1` (null parent), grouped by group. Also fills the map of default options ({@see $categoryParameterOptionDefaults}) = child parameters with `default=1` (other options are shown unticked in `onAnchor`). `required` and `useInSearch` come from the parameter. A parameter without a group is skipped because it cannot be placed in the group multiplier.
categoryFormLangId()  : int
categoryRowField()  : mixed
Safely reads a field from a multiplier row (`ArrayHash` or array).
categoryRowInt()  : int
Returns a multiplier row field as a positive 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. The Api turns it into an `Asset` (variants) and sets the FK to the main image (`afterSave` `processMainImage`).
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 the given parameter as checkbox list items (id to name).
isCategoryHrefUnique()  : bool
Validates that the href is unique within the language (the edited category is excluded on edit).
loadCategoryParameterNames()  : array<int, string>
loadCategoryParameterParentMap()  : array<int, int|null>
parameterGroupName()  : string
Parameter group name in the given language (falls back to the first non-empty one).
refreshCategoryParameterOptions()  : void
After the anchor: sets the items of the options checkbox list in every row to the child parameters of the chosen parameter; on GET (not a submit) pre-fills the saved options from the edit (on submit the http data holds them).
saveCategoryForm()  : bool
setCategoryFormDefaults()  : void

Properties

$categoryParameterGroupOptions

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

cached select options of the parameter groups (id to name)

$categoryParameterOptionDefaults

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

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

Methods

addCategoryParameterFields()

Section "parameter settings": the "use default parameters" switch plus nested multipliers that look like the resulting advert form (section, then fields): - outer `parameterGroups` = groups (row = `parameterGroupId` select), - nested `parameters` (in every group row) = the group's parameters (row = parameter Picker `parameterId` + `parameterName` + required + search + options).

private addCategoryParameterFields(Form $form) : void

A Picker in the nested multiplier addresses two index levels ({control "picker-parameter_<g>_<p>"}), see ParameterPickerTrait::parameterPicker() (nestedContainer) and the extended PickerHostTrait/Picker. Adding or removing a row (group or parameter) runs over AJAX (.ajax buttons redraw the parameterGroups snippet).

Parameters
$form : Form

addCategoryParameterRowControls()

Fields of one row of the nested parameters multiplier (Picker field, flags, options).

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

addCategoryPriceMatrix()

Price matrix of the category: for each payment region x payment gateway combination a price field plus an active checkbox (currency is the currency of the gateway's region-rel, falling back to the region currency; price is `price_for_unlogged`). The presenter supplies the axes (`$this->categoryRegions`, `categoryGates`). Applies when the category is not free.

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

addCategoryStructureFields()

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

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

addCategoryTranslationFields()

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

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

applyCategoryParameterDefaults()

Sets the defaults of the parameters section (on GET, for a new and an edited category): - the stored rels of the edited category, or (new category / no own rels) the global default parameters (`default=1`) with their options, - the "use default parameters" flag (edited category only).

private applyCategoryParameterDefaults(Form $form) : void

The options (checkbox list) 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()

Returns the nested multiplier rows from the stored rels of the edited category: groups the parameters by `parameterGroupId` (in order of first occurrence) into group rows, each with its own parameters; also fills the map of default options ({@see $categoryParameterOptionDefaults}).

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

buildCategoryParameterRelsMeta()

Builds `meta['parameterRels']` from the nested multiplier values: for every group its parameters plus their options, as flat rel rows. A parameter's group is the `parameterGroupId` of the group row; options are child parameters with `parameterGroupId = null`.

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

With "use default parameters" it returns an empty array. The Api sync then leaves the stored rels untouched, so the category's own settings survive 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 owned `CategoryPrice` collection from the price matrix (scalar region/gateway/currency).

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

The price currency is the currency of the gateway's region-rel (credits give KRD), falling back to the region currency; it must match the front end lookup, see CategoryPriceGridTrait. Price is price_for_unlogged, the entered price. 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()

Returns the global default parameters for pre-filling: top-level parameters with `default=1` (null parent), grouped by group. Also fills the map of default options ({@see $categoryParameterOptionDefaults}) = child parameters with `default=1` (other options are shown unticked in `onAnchor`). `required` and `useInSearch` come from the parameter. A parameter without a group is skipped because it cannot be placed in the group multiplier.

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

categoryRowField()

Safely reads a field from a multiplier row (`ArrayHash` or array).

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

categoryRowInt()

Returns a multiplier row field as a positive 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. The Api turns it into an `Asset` (variants) and sets the FK to the main image (`afterSave` `processMainImage`).

private collectCategoryImageMeta(ArrayHash<string|int, mixed> $values) : array<string, mixed>
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>

IMPORTANT: the name is already translated data, not a key, hence NotTranslate; otherwise the form translator looks it up as a key (bazaar.presenters.category.<name>) and Tracy reports a missing translation.

Return values
array<int, NotTranslate>

getCategoryParameterOptionItems()

Returns the child parameters (options) of the given 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 within the language (the edited category is excluded on edit).

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

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

id mapped to name

loadCategoryParameterParentMap()

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

id mapped to parentId

parameterGroupName()

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()

After the anchor: sets the items of the options checkbox list in every row to the child parameters of the chosen parameter; on GET (not a submit) pre-fills the saved options from the edit (on submit the http data holds them).

private refreshCategoryParameterOptions(Form $form) : void
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