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
30fa57b999
commit
665f0b4ccb
@ -75,6 +75,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
|||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormDefaultData(): array
|
public function getFormDefaultData(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
|
@ -13,16 +13,20 @@ namespace Chill\AsideActivityBundle\Export\Filter;
|
|||||||
|
|
||||||
use Chill\AsideActivityBundle\Export\Declarations;
|
use Chill\AsideActivityBundle\Export\Declarations;
|
||||||
use Chill\MainBundle\Entity\Location;
|
use Chill\MainBundle\Entity\Location;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||||
use Chill\MainBundle\Repository\LocationRepository;
|
use Chill\MainBundle\Repository\LocationRepository;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
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
|
public function buildForm(FormBuilderInterface $builder): void
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('locations', EntityType::class, [
|
->add('locations', PickUserLocationType::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(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +51,17 @@ class ByLocationFilter implements FilterInterface
|
|||||||
*/
|
*/
|
||||||
public function getFormDefaultData(): array
|
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
|
public function describeAction($data, $format = 'string'): array
|
||||||
{
|
{
|
||||||
$locations = array_map(
|
$locations = $data['locations']->map(fn (Location $l): string => $l->getName());
|
||||||
fn (Location $l): string => $l->getName(),
|
|
||||||
$data['locations']->toArray()
|
|
||||||
);
|
|
||||||
|
|
||||||
return ['export.filter.Filtered by aside activity location: only %location%', [
|
return ['export.filter.Filtered by aside activity location: only %location%', [
|
||||||
'%location%' => implode(', ', $locations),
|
'%location%' => implode(', ', $locations),
|
||||||
|
@ -17,6 +17,7 @@ use Chill\MainBundle\Entity\Location;
|
|||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||||
|
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
@ -80,13 +81,7 @@ final class AsideActivityFormType extends AbstractType
|
|||||||
'label' => 'Note',
|
'label' => 'Note',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('location', EntityType::class, [
|
->add('location', PickUserLocationType::class)
|
||||||
'label' => 'Set a location',
|
|
||||||
'class' => Location::class,
|
|
||||||
'choice_label' => fn (Location $l) => $l->getName(),
|
|
||||||
'data' => $options['data']->getLocation(),
|
|
||||||
'required' => false,
|
|
||||||
])
|
|
||||||
;
|
;
|
||||||
|
|
||||||
foreach (['duration'] as $fieldName) {
|
foreach (['duration'] as $fieldName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user