LimitRangeSliderHandler
extends AbstractParameterHandler
in package
uses
RangePairFieldsTrait
Handler of `LIMITRANGE_SLIDER`: a search range with a lower and an upper bound (from/to).
URL convention: p[{id}_from] and p[{id}_to]. The pair of form fields is built like the
edit range (RangePairFieldsTrait).
Full-overlap filter: an advert stores its own range (value is from, value2 is to) and the
search matches the whole edit range lying inside the search range:
searchFrom <= value AND value2 <= searchTo, i.e. GreaterOrEqualFilter on parameterRels.value
plus LessOrEqualFilter on value2. Bounds are bound as numbers; otherwise the comparison
over the text column would be lexicographic.
Table of Contents
Methods
- applyDefault() : void
- applyEntityValue() : void
- Prefills the form field with the entity value; a scalar or array goes to `$key`.
- buildField() : BaseControl
- extractRows() : array<int, array{value: mixed, value2?: ?string}>
- Splits the submitted values into rows to persist (one `AdvertParameterRel` per row).
- extractValue() : mixed
- Extracts the value from the form for persistence.
- formatValue() : string|object|null
- Formats the stored value of a parameter relation for display.
- fromUrlParams() : array<string, mixed>
- Converts URL fragments back to defaults for `$form->setDefaults()`.
- getActiveValueLabels() : array<int|string, string>
- Returns human-readable labels of the active parameter value, used for the filter badges above the list (`.pactive__chip`).
- getParameterLabel() : string
- Returns the label of a parameter or option in the context language.
- getTypes() : array<string|int, int>
- hasTranslatedLabel() : bool
- Returns whether the item has a usable label in the current language.
- isPersistable() : bool
- resolveDefaultValue() : string|null
- Resolves the default of a new field (no entity value).
- setupOptions() : void
- toFilters() : array<string|int, Filter>
- Builds database filters from URL fragments.
- toUrlParams() : array<string|int, mixed>
- Converts submitted form values to URL fragments for the redirect.
- applyDisplayText() : string
- Applies the display text (`display_text`) of the translation to an already rendered value.
- buildRangePair() : BaseControl
- getOptionItems() : array<int, string>
- Returns plain option labels without counts.
-
getOptionItemsForField()
: Html> : array
) - Returns option labels for a form field, with item counts when the module supplied them.
- getParameterPlaceholder() : string|null
- getParameterText() : string|null
- resolveDisplayText() : string|null
- resolveOptionLabel() : string|null
- Finds the option (child parameter) by the stored id and returns its translated name.
- resolveTranslation() : ParameterTextInterface|null
- applyRangeBounds() : void
- Applies the slider bounds (`min`/`max`), only when the module supplied them in the context.
- applyRangePlaceholder() : void
- numericBound() : float|string
- Binds as a number (not a string) for a numeric comparison over the text column.
- rangeColumnLabel() : string|null
- rangeName() : string
Methods
applyDefault()
public
applyDefault(BaseControl $element, ParameterInterface $parameter, mixed $value, ParameterFormContext $context) : void
Parameters
- $element : BaseControl
- $parameter : ParameterInterface
- $value : mixed
- $context : ParameterFormContext
applyEntityValue()
Prefills the form field with the entity value; a scalar or array goes to `$key`.
public
applyEntityValue(Form $form, string $key, mixed $value[, bool $force = false ]) : void
Range overrides it to split into {key}_from and {key}_to.
With $force it calls setValue() instead of setDefaultValue(), which is a no-op on a
submitted and anchored form (Nette BaseControl::setDefaultValue); without force, new fields
revealed by an AJAX category refresh would stay empty. IMPORTANT: use $force only for fields
that are not in the submitted POST (see
ParameterFieldBuilder::applyEntityDefaultsForNewFields()),
otherwise it overwrites the value the user is typing.
Parameters
- $form : Form
- $key : string
- $value : mixed
- $force : bool = false
buildField()
public
buildField(Form $form, ParameterInterface $parameter, string $key, ParameterFormContext $context) : BaseControl
Parameters
- $form : Form
- $parameter : ParameterInterface
- $key : string
- $context : ParameterFormContext
Return values
BaseControlextractRows()
Splits the submitted values into rows to persist (one `AdvertParameterRel` per row).
public
extractRows(ArrayHash $values, string $key, ParameterInterface $parameter) : array<int, array{value: mixed, value2?: ?string}>
A scalar becomes one row, an array (multiselect/checkboxlist) one row per item.
Range overrides it to value (from) and value2 (to).
Parameters
- $values : ArrayHash
- $key : string
- $parameter : ParameterInterface
Return values
array<int, array{value: mixed, value2?: ?string}>extractValue()
Extracts the value from the form for persistence.
public
extractValue(BaseControl $element, ParameterInterface $parameter) : mixed
Most types return a scalar; multiselect and checkboxlist return an array.
Parameters
- $element : BaseControl
- $parameter : ParameterInterface
formatValue()
Formats the stored value of a parameter relation for display.
public
formatValue(string|null $value, string|null $value2, ParameterInterface $parameter, ParameterRenderContext $context) : string|object|null
Receives the raw value/value2 of AdvertParameterRel (not the entity, so the handler does
not depend on the module variant of the relation), the parameter itself (for translation and
type) and the render context (language, locale). Returns:
- string: the formatted cell value,
- object: a typed value object for a special template (e.g.
OpeningHours), - null: the row is skipped.
The default implementation covers simple single-value types.
Parameters
- $value : string|null
- $value2 : string|null
- $parameter : ParameterInterface
- $context : ParameterRenderContext
Return values
string|object|nullfromUrlParams()
Converts URL fragments back to defaults for `$form->setDefaults()`.
public
fromUrlParams(string $key, int $parameterId, array<string|int, mixed> $urlParams) : array<string, mixed>
Parameters
- $key : string
- $parameterId : int
- $urlParams : array<string|int, mixed>
-
content of
$_GET['p'](key12is anintin PHP)
Return values
array<string, mixed> —map of [formKey => value]
getActiveValueLabels()
Returns human-readable labels of the active parameter value, used for the filter badges above the list (`.pactive__chip`).
public
getActiveValueLabels(ParameterInterface $parameter, mixed $value, ParameterFormContext $context) : array<int|string, string>
Returns one label per removable value. The default covers all types: a parameter with options maps the option id to its name, others return the value as text. A type handler may override it (range "from-to", date, etc.).
IMPORTANT: it reads from the already loaded parameter entity (optionsCollection is in the
filter includes) and must not issue an extra query.
Parameters
- $parameter : ParameterInterface
- $value : mixed
- $context : ParameterFormContext
Return values
array<int|string, string> —value => label (the key is what gets removed from the URL)
getParameterLabel()
Returns the label of a parameter or option in the context language.
public
getParameterLabel(ParameterInterface $parameter, ParameterFormContext $context) : string
IMPORTANT: the fallback chain must skip an empty string, not only null (?? does not).
A translation with an empty name would otherwise win over the default language and the
option would render with no name at all on a foreign-language site. A missing row behaves
correctly (falls back to the first translation), so "no row" and "empty row" must be told apart.
Empty rows are no longer written; this guards data from imports or manual SQL.
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
Return values
stringgetTypes()
public
getTypes() : array<string|int, int>
Return values
array<string|int, int> —ParameterType constants served by this handler
hasTranslatedLabel()
Returns whether the item has a usable label in the current language.
public
hasTranslatedLabel(ParameterInterface $parameter, ParameterFormContext $context) : bool
Basis of the rule "hide untranslated items, do not show the default language". The parameter
key deliberately does not count as a label: usb is a technical identifier, not a
translation, and looks as wrong in a foreign-language filter as the default language.
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
Return values
boolisPersistable()
public
isPersistable() : bool
Return values
boolresolveDefaultValue()
Resolves the default of a new field (no entity value).
public
resolveDefaultValue(ParameterInterface $parameter, string|null $defaultValue, ParameterFormContext $context) : string|null
Receives the parameter default_value (or search_default_value) and may override it;
the default implementation returns it unchanged.
Parameters
- $parameter : ParameterInterface
- $defaultValue : string|null
- $context : ParameterFormContext
Return values
string|nullsetupOptions()
public
setupOptions(BaseControl $element, ParameterInterface $parameter, string $key, ParameterFormContext $context) : void
Parameters
- $element : BaseControl
- $parameter : ParameterInterface
- $key : string
- $context : ParameterFormContext
toFilters()
Builds database filters from URL fragments.
public
toFilters(int $parameterId, array<string|int, mixed> $urlParams[, bool $matchAll = false ]) : array<string|int, Filter>
Parameters
- $parameterId : int
- $urlParams : array<string|int, mixed>
-
content of
$_GET['p'](numeric parameter key is anintin PHP) - $matchAll : bool = false
-
AND within a facet: a multi-value facet creates N separate
ParameterRelFilters (each with its own join, so an implicit AND at top level) instead of onevalue IN (...)(an OR). Driven byParameter::getFilterMatchAll().
Return values
array<string|int, Filter>toUrlParams()
Converts submitted form values to URL fragments for the redirect.
public
toUrlParams(string $key, int $parameterId, ArrayHash $values) : array<string|int, mixed>
Returns an associative array merged into $params['p'][]. The key is the parameter id
(with a _from/_to suffix for ranges); PHP stores a numeric key as int.
Parameters
- $key : string
- $parameterId : int
- $values : ArrayHash
Return values
array<string|int, mixed>applyDisplayText()
Applies the display text (`display_text`) of the translation to an already rendered value.
protected
applyDisplayText(string $display, array<string, string> $values, int|null $count, ParameterInterface $parameter, ParameterRenderContext $context) : string
- a text with
%value%/%value2%is a standalone sentence that embeds the values ("employs %value% people"); only the text is returned, - a text without a placeholder is a suffix after the value ("10 - 30 days").
The plural variant ({1}|[2,4]|...) is chosen by $count (internally %count%);
$values carry the named replacements (%value%, %value2%). Without a text (or
translation) $display is returned unchanged.
Parameters
- $display : string
- $values : array<string, string>
- $count : int|null
- $parameter : ParameterInterface
- $context : ParameterRenderContext
Return values
stringbuildRangePair()
protected
buildRangePair(Form $form, ParameterInterface $parameter, string $key, ParameterFormContext $context) : BaseControl
Parameters
- $form : Form
- $parameter : ParameterInterface
- $key : string
- $context : ParameterFormContext
Return values
BaseControlgetOptionItems()
Returns plain option labels without counts.
protected
getOptionItems(ParameterInterface $parameter, ParameterFormContext $context) : array<int, string>
IMPORTANT: the active filter badges (getActiveValueLabels()) take their label from here, which is why counts are added only in getOptionItemsForField(). Otherwise a badge would read "Sony (3)", although it says what is checked, not how many items there are.
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
Return values
array<int, string>getOptionItemsForField()
Returns option labels for a form field, with item counts when the module supplied them.
protected
getOptionItemsForField(ParameterInterface $parameter, ParameterFormContext $context[, bool $html = true ]) : Html> : array)
Without counts in the context it returns exactly what getOptionItems() does, so adverts and the company catalog are unaffected until they supply counts themselves.
IMPORTANT: pass $html = false for <select>: <option> cannot hold nested markup and the
label would be printed with its tags. Checkboxes and radios render the Html label.
An option with count 0 gets the is-empty class; it is greyed out, and hiding it is then a
single CSS rule instead of a PHP change.
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
- $html : bool = true
Return values
Html> : arraygetParameterPlaceholder()
protected
getParameterPlaceholder(ParameterInterface $parameter, ParameterFormContext $context) : string|null
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
Return values
string|nullgetParameterText()
protected
getParameterText(ParameterInterface $parameter, string $getter, ParameterFormContext $context) : string|null
Parameters
- $parameter : ParameterInterface
- $getter : string
- $context : ParameterFormContext
Return values
string|nullresolveDisplayText()
protected
resolveDisplayText(ParameterInterface $parameter, ParameterRenderContext $context) : string|null
Parameters
- $parameter : ParameterInterface
- $context : ParameterRenderContext
Return values
string|nullresolveOptionLabel()
Finds the option (child parameter) by the stored id and returns its translated name.
protected
resolveOptionLabel(string $value, ParameterInterface $parameter, ParameterRenderContext $context) : string|null
Returns null when the option or translation is missing; the caller then shows the raw value.
Parameters
- $value : string
- $parameter : ParameterInterface
- $context : ParameterRenderContext
Return values
string|nullresolveTranslation()
protected
resolveTranslation(ParameterInterface $parameter, ParameterFormContext $context) : ParameterTextInterface|null
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
Return values
ParameterTextInterface|nullapplyRangeBounds()
Applies the slider bounds (`min`/`max`), only when the module supplied them in the context.
private
applyRangeBounds(BaseControl $fromField, BaseControl $toField, ParameterInterface $parameter, ParameterFormContext $context) : void
Without bounds the slider has nowhere to drag, so it is not rendered and two number fields
remain. The bounds also go into the HTML min/max attributes, so the browser respects them
for typed input and the spinner keeps the user within the range.
Parameters
- $fromField : BaseControl
- $toField : BaseControl
- $parameter : ParameterInterface
- $context : ParameterFormContext
applyRangePlaceholder()
private
applyRangePlaceholder(BaseControl $field, ParameterInterface $parameter, ParameterFormContext $context, bool $first) : void
Parameters
- $field : BaseControl
- $parameter : ParameterInterface
- $context : ParameterFormContext
- $first : bool
numericBound()
Binds as a number (not a string) for a numeric comparison over the text column.
private
static numericBound(mixed $value) : float|string
Parameters
- $value : mixed
Return values
float|stringrangeColumnLabel()
private
rangeColumnLabel(ParameterInterface $parameter, ParameterFormContext $context, bool $first) : string|null
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext
- $first : bool
Return values
string|nullrangeName()
private
rangeName(ParameterInterface $parameter, ParameterFormContext $context) : string
Parameters
- $parameter : ParameterInterface
- $context : ParameterFormContext