mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[FEATURE] allow adding of user filters in filter order - template still to be done
This commit is contained in:
parent
0e5f1b4ab9
commit
25d4b6acbb
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Form\Type\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@ -120,6 +121,35 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
|
||||
$builder->add($singleCheckBoxBuilder);
|
||||
}
|
||||
|
||||
if ([] !== $helper->getUserPickers()) {
|
||||
$userPickersBuilder = $builder->create('userPicker', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getUserPickers() as $name => [
|
||||
'label' => $label, 'options' => $options
|
||||
]) {
|
||||
$userPicker = $userPickersBuilder->create($name, null, [
|
||||
'compound' => true,
|
||||
'label' => $label,
|
||||
]);
|
||||
|
||||
$userPicker->add(
|
||||
$name,
|
||||
PickUserDynamicType::class,
|
||||
[
|
||||
'multiple' => true,
|
||||
'label' => $label,
|
||||
...$options,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$userPickersBuilder->add($userPicker);
|
||||
}
|
||||
|
||||
$builder->add($userPickersBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user