mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Use PickUserLocationType instead of an EntityType
This commit is contained in:
parent
18971b3204
commit
599510c3b9
@ -75,6 +75,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
|
@ -13,16 +13,20 @@ namespace Chill\AsideActivityBundle\Export\Filter;
|
||||
|
||||
use Chill\AsideActivityBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||
use Chill\MainBundle\Repository\LocationRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class ByLocationFilter implements FilterInterface
|
||||
final readonly class ByLocationFilter implements FilterInterface
|
||||
{
|
||||
public function __construct(private LocationRepository $locationRepository)
|
||||
{
|
||||
public function __construct(
|
||||
private Security $security
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,16 +43,7 @@ class ByLocationFilter implements FilterInterface
|
||||
public function buildForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$builder
|
||||
->add('locations', EntityType::class, [
|
||||
'label' => 'pick location',
|
||||
'class' => Location::class,
|
||||
'choices' => $this->locationRepository->findAll(),
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'attr' => ['class' => 'select2'],
|
||||
'choice_label' => fn (Location $l) => $l->getName(),
|
||||
]);
|
||||
->add('locations', PickUserLocationType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +51,17 @@ class ByLocationFilter implements FilterInterface
|
||||
*/
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if ($user instanceof User) {
|
||||
return [
|
||||
'locations' => $user->getCurrentLocation(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'locations' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +69,7 @@ class ByLocationFilter implements FilterInterface
|
||||
*/
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
$locations = array_map(
|
||||
fn (Location $l): string => $l->getName(),
|
||||
$data['locations']->toArray()
|
||||
);
|
||||
$locations = $data['locations']->map(fn (Location $l): string => $l->getName());
|
||||
|
||||
return ['export.filter.Filtered by aside activity location: only %location%', [
|
||||
'%location%' => implode(', ', $locations),
|
||||
|
@ -17,6 +17,7 @@ use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
@ -80,13 +81,7 @@ final class AsideActivityFormType extends AbstractType
|
||||
'label' => 'Note',
|
||||
'required' => false,
|
||||
])
|
||||
->add('location', EntityType::class, [
|
||||
'label' => 'Set a location',
|
||||
'class' => Location::class,
|
||||
'choice_label' => fn (Location $l) => $l->getName(),
|
||||
'data' => $options['data']->getLocation(),
|
||||
'required' => false,
|
||||
])
|
||||
->add('location', PickUserLocationType::class)
|
||||
;
|
||||
|
||||
foreach (['duration'] as $fieldName) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user