private readonly array $labelPickers;
/**
- * @var list<int>
+ * Field name of the selected values.
*/
- private readonly array $positionToGroupID;
+ private string $name = 'labelIDs';
/**
* @param LabelPicker[] $labelPickers
}
$this->labelPickers = $pickers;
- $this->positionToGroupID = \array_keys($pickers);
}
/**
*/
public function toUrlQueryString(): string
{
- return \implode(
- '&',
- \array_map(static function (LabelPicker $labelPicker) {
- return \sprintf(
- 'labelIDs[%d]=%d',
- $labelPicker->labelGroup->groupID,
- $labelPicker->getSelectedValue(),
- );
- }, \array_filter(
+ $mapping = \array_map(
+ static fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(),
+ \array_filter(
$this->labelPickers,
static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection()
- ))
+ )
);
+
+ return \http_build_query([$this->name => $mapping], '', '&');
}
/**
*/
public function setName(string $name): void
{
+ $this->name = $name;
+
foreach ($this->labelPickers as $labelPicker) {
$labelPicker->name = $name;
}