From: Alexander Ebert Date: Fri, 13 Oct 2023 13:39:49 +0000 (+0200) Subject: Use `\http_build_query()` and the proper name to build the query string X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3689b707ecd132368019b5f4075a51502ba88158;p=GitHub%2FWoltLab%2FWCF.git Use `\http_build_query()` and the proper name to build the query string --- diff --git a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php index 2df533ef87..8851232d10 100644 --- a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php @@ -23,9 +23,9 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate private readonly array $labelPickers; /** - * @var list + * Field name of the selected values. */ - private readonly array $positionToGroupID; + private string $name = 'labelIDs'; /** * @param LabelPicker[] $labelPickers @@ -43,7 +43,6 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate } $this->labelPickers = $pickers; - $this->positionToGroupID = \array_keys($pickers); } /** @@ -98,19 +97,15 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate */ 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], '', '&'); } /** @@ -192,6 +187,8 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate */ public function setName(string $name): void { + $this->name = $name; + foreach ($this->labelPickers as $labelPicker) { $labelPicker->name = $name; }