-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathCheckboxesFormOption.class.php
More file actions
88 lines (76 loc) · 2.42 KB
/
CheckboxesFormOption.class.php
File metadata and controls
88 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace wcf\system\form\option;
use wcf\data\DatabaseObjectList;
use wcf\system\form\builder\field\AbstractFormField;
use wcf\system\form\builder\field\MultipleSelectionFormField;
use wcf\system\form\option\formatter\IFormOptionFormatter;
use wcf\system\form\option\formatter\MultipleSelectionFormatter;
use wcf\system\WCF;
/**
* Implementation of a form field for selecting multiple values.
*
* @author Marcel Werk
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
class CheckboxesFormOption extends AbstractFormOption
{
use TSelectOptionsFormOption;
#[\Override]
public function getId(): string
{
return 'checkboxes';
}
#[\Override]
public function getFormField(string $id, array $configuration = []): AbstractFormField
{
$formField = MultipleSelectionFormField::create($id)
->ignoreInvalidValues();
$this->setSelectOptions($formField, $configuration);
return $formField;
}
#[\Override]
public function getConfigurationFormFields(): array
{
return ['selectOptions', 'required'];
}
#[\Override]
public function getFormatter(): IFormOptionFormatter
{
return new MultipleSelectionFormatter();
}
#[\Override]
public function getPlainTextFormatter(): IFormOptionFormatter
{
return $this->getFormatter();
}
#[\Override]
public function serializeValue(mixed $value): string
{
return \implode(',', $value);
}
/**
* @return array<string|int>
*/
#[\Override]
public function unserializeValue(string $value): array
{
return \explode(',', $value);
}
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $columnName, mixed $value): void
{
foreach ($this->unserializeValue($value) as $selectedValue) {
$list->getConditionBuilder()->add(
"({$columnName} = ? OR {$columnName} LIKE ? OR {$columnName} LIKE ? OR {$columnName} LIKE ?) ",
[
$selectedValue,
WCF::getDB()->escapeLikeValue($selectedValue) . ',%',
'%,' . WCF::getDB()->escapeLikeValue($selectedValue),
'%,' . WCF::getDB()->escapeLikeValue($selectedValue) . ',%',
]
);
}
}
}