mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 19:43:49 +00:00
[FEATURE] allow adding of user filters in filter order - template still to be done
This commit is contained in:
@@ -52,6 +52,11 @@ class FilterOrderHelper
|
||||
*/
|
||||
private array $entityChoices = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array{label: string, options: array}>
|
||||
*/
|
||||
private array $userPickers = [];
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
RequestStack $requestStack
|
||||
@@ -82,6 +87,14 @@ class FilterOrderHelper
|
||||
return $this->entityChoices;
|
||||
}
|
||||
|
||||
public function addUserPickers(string $name, ?string $label = null, array $options = []): self
|
||||
{
|
||||
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function addCheckbox(string $name, array $choices, ?array $default = [], ?array $trans = [], array $options = []): self
|
||||
{
|
||||
$missing = count($choices) - count($trans) - 1;
|
||||
@@ -116,6 +129,16 @@ class FilterOrderHelper
|
||||
->handleRequest($this->requestStack->getCurrentRequest());
|
||||
}
|
||||
|
||||
public function getUserPickers(): array
|
||||
{
|
||||
return $this->userPickers;
|
||||
}
|
||||
|
||||
public function getUserPickerData(string $name): array
|
||||
{
|
||||
return $this->getFormData()['userPickers'][$name];
|
||||
}
|
||||
|
||||
public function getCheckboxData(string $name): array
|
||||
{
|
||||
return $this->getFormData()['checkboxes'][$name];
|
||||
@@ -180,7 +203,8 @@ class FilterOrderHelper
|
||||
'checkboxes' => [],
|
||||
'dateRanges' => [],
|
||||
'single_checkboxes' => [],
|
||||
'entity_choices' => []
|
||||
'entity_choices' => [],
|
||||
'user_pickers' => []
|
||||
];
|
||||
|
||||
if ($this->hasSearchBox()) {
|
||||
@@ -204,7 +228,12 @@ class FilterOrderHelper
|
||||
$r['entity_choices'][$name] = ($c['options']['multiple'] ?? true) ? [] : null;
|
||||
}
|
||||
|
||||
foreach ($this->userPickers as $name => $u) {
|
||||
$r['user_pickers'][$name] = ($u['options']['multiple'] ?? true) ? [] : null;
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
private function getFormData(): array
|
||||
|
@@ -37,6 +37,11 @@ class FilterOrderHelperBuilder
|
||||
*/
|
||||
private array $entityChoices = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array{label: string, options: array}>
|
||||
*/
|
||||
private array $userPickers = [];
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
RequestStack $requestStack
|
||||
@@ -83,6 +88,13 @@ class FilterOrderHelperBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addUserPickers(string $name, ?string $label = null, ?array $options = []): self
|
||||
{
|
||||
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build(): FilterOrderHelper
|
||||
{
|
||||
$helper = new FilterOrderHelper(
|
||||
@@ -124,6 +136,17 @@ class FilterOrderHelperBuilder
|
||||
$helper->addDateRange($name, $label, $from, $to);
|
||||
}
|
||||
|
||||
|
||||
foreach (
|
||||
$this->userPickers as $name => [
|
||||
'label' => $label,
|
||||
'options' => $options
|
||||
]
|
||||
) {
|
||||
$helper->addUserPickers($name, $label, $options);
|
||||
}
|
||||
|
||||
|
||||
return $helper;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user