mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
do not show filter on job or activity type if less than 2 possibilities
This commit is contained in:
parent
0e5f1b4ab9
commit
c04fd66163
@ -259,8 +259,8 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$filterArgs = [
|
$filterArgs = [
|
||||||
'my_activities' => $filter->getSingleCheckboxData('my_activities'),
|
'my_activities' => $filter->getSingleCheckboxData('my_activities'),
|
||||||
'types' => $filter->getEntityChoiceData('activity_types'),
|
'types' => $filter->hasEntityChoice('activity_type') ? $filter->getEntityChoiceData('activity_types') : [],
|
||||||
'jobs' => $filter->getEntityChoiceData('jobs'),
|
'jobs' => $filter->hasEntityChoice('jobs') ? $filter->getEntityChoiceData('jobs') : [],
|
||||||
'before' => $filter->getDateRangeData('activity_date')['to'],
|
'before' => $filter->getDateRangeData('activity_date')['to'],
|
||||||
'after' => $filter->getDateRangeData('activity_date')['from'],
|
'after' => $filter->getDateRangeData('activity_date')['from'],
|
||||||
];
|
];
|
||||||
@ -327,7 +327,10 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$filterBuilder
|
$filterBuilder
|
||||||
->addDateRange('activity_date', 'activity.date')
|
->addDateRange('activity_date', 'activity.date')
|
||||||
->addSingleCheckbox('my_activities', 'activity_filter.My activities')
|
->addSingleCheckbox('my_activities', 'activity_filter.My activities');
|
||||||
|
|
||||||
|
if (1 < count($types)) {
|
||||||
|
$filterBuilder
|
||||||
->addEntityChoice('activity_types', 'activity_filter.Types', \Chill\ActivityBundle\Entity\ActivityType::class, $types, [
|
->addEntityChoice('activity_types', 'activity_filter.Types', \Chill\ActivityBundle\Entity\ActivityType::class, $types, [
|
||||||
'choice_label' => function (\Chill\ActivityBundle\Entity\ActivityType $activityType) {
|
'choice_label' => function (\Chill\ActivityBundle\Entity\ActivityType $activityType) {
|
||||||
$text = match ($activityType->hasCategory()) {
|
$text = match ($activityType->hasCategory()) {
|
||||||
@ -337,11 +340,15 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
return $text . $this->translatableStringHelper->localize($activityType->getName());
|
return $text . $this->translatableStringHelper->localize($activityType->getName());
|
||||||
}
|
}
|
||||||
])
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (1 < count($jobs)) {
|
||||||
|
$filterBuilder
|
||||||
->addEntityChoice('jobs', 'activity_filter.Jobs', UserJob::class, $jobs, [
|
->addEntityChoice('jobs', 'activity_filter.Jobs', UserJob::class, $jobs, [
|
||||||
'choice_label' => fn (UserJob $u) => $this->translatableStringHelper->localize($u->getLabel())
|
'choice_label' => fn (UserJob $u) => $this->translatableStringHelper->localize($u->getLabel())
|
||||||
])
|
]);
|
||||||
;
|
}
|
||||||
|
|
||||||
return $filterBuilder->build();
|
return $filterBuilder->build();
|
||||||
}
|
}
|
||||||
|
@ -116,16 +116,31 @@ class FilterOrderHelper
|
|||||||
->handleRequest($this->requestStack->getCurrentRequest());
|
->handleRequest($this->requestStack->getCurrentRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasCheckboxData(string $name): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->checkboxes);
|
||||||
|
}
|
||||||
|
|
||||||
public function getCheckboxData(string $name): array
|
public function getCheckboxData(string $name): array
|
||||||
{
|
{
|
||||||
return $this->getFormData()['checkboxes'][$name];
|
return $this->getFormData()['checkboxes'][$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasSingleCheckboxData(string $name): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->singleCheckbox);
|
||||||
|
}
|
||||||
|
|
||||||
public function getSingleCheckboxData(string $name): ?bool
|
public function getSingleCheckboxData(string $name): ?bool
|
||||||
{
|
{
|
||||||
return $this->getFormData()['single_checkboxes'][$name];
|
return $this->getFormData()['single_checkboxes'][$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasEntityChoice(string $name): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->entityChoices);
|
||||||
|
}
|
||||||
|
|
||||||
public function getEntityChoiceData($name): mixed
|
public function getEntityChoiceData($name): mixed
|
||||||
{
|
{
|
||||||
return $this->getFormData()['entity_choices'][$name];
|
return $this->getFormData()['entity_choices'][$name];
|
||||||
@ -144,6 +159,11 @@ class FilterOrderHelper
|
|||||||
return $this->singleCheckbox;
|
return $this->singleCheckbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasDateRangeData(string $name): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->dateRanges);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{to: ?DateTimeImmutable, from: ?DateTimeImmutable}
|
* @return array{to: ?DateTimeImmutable, from: ?DateTimeImmutable}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user