From a68fef8547c3f8137b5326934e1e214fcebb6b0d Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Aug 2023 14:21:37 +0200 Subject: [PATCH 01/11] Feature: migrate changes in Location attribute in Asideactivity Entity --- .../src/Entity/AsideActivity.php | 10 +++--- .../src/migrations/Version20230816112809.php | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php diff --git a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php index 3dc205f09..2486d1fcc 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php @@ -14,6 +14,7 @@ namespace Chill\AsideActivityBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Entity\Location; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; @@ -60,9 +61,10 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface private ?int $id = null; /** - * @ORM\Column(type="string", length=100, nullable=true) + * @ORM\ManyToOne(targetEntity=Location::class) + * @ORM\JoinColumn(nullable=true) */ - private $location; + private ?Location $location; /** * @ORM\Column(type="text", nullable=true) @@ -115,7 +117,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface return $this->id; } - public function getLocation(): ?string + public function getLocation(): ?Location { return $this->location; } @@ -175,7 +177,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function setLocation(?string $location): self + public function setLocation(?Location $location): self { $this->location = $location; diff --git a/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php b/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php new file mode 100644 index 000000000..6a52f41f9 --- /dev/null +++ b/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php @@ -0,0 +1,35 @@ +addSql('DROP INDEX chill_asideactivity.IDX_A866DA0E64D218E'); + $this->addSql('ALTER TABLE chill_asideactivity.AsideActivity DROP CONSTRAINT FK_A866DA0E64D218E'); + $this->addSql('ALTER TABLE chill_asideactivity.AsideActivity DROP location_id'); + $this->addSql('ALTER TABLE chill_asideactivity.AsideActivity ADD location VARCHAR(100) DEFAULT NULL'); + } + + public function up(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_asideactivity.asideactivity ADD location_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_asideactivity.asideactivity DROP location'); + $this->addSql('ALTER TABLE chill_asideactivity.asideactivity ADD CONSTRAINT FK_A866DA0E64D218E FOREIGN KEY (location_id) REFERENCES chill_main_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_A866DA0E64D218E ON chill_asideactivity.asideactivity (location_id)'); + } +} From 0e16ab4c189fdd3f1e12cf150f97b45165f7cce8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Aug 2023 15:44:58 +0200 Subject: [PATCH 02/11] Feature: add location in asideActivity pages (user currentLocation by default) --- .../src/Controller/AsideActivityController.php | 1 + .../src/Form/AsideActivityFormType.php | 12 +++++++++++- .../Resources/views/asideActivity/index.html.twig | 3 +++ .../src/Resources/views/asideActivity/view.html.twig | 7 +++++++ .../src/translations/messages.fr.yml | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Controller/AsideActivityController.php b/src/Bundle/ChillAsideActivityBundle/src/Controller/AsideActivityController.php index 8481f24eb..25cb2a557 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Controller/AsideActivityController.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Controller/AsideActivityController.php @@ -33,6 +33,7 @@ final class AsideActivityController extends CRUDController $asideActivity = new AsideActivity(); $asideActivity->setAgent($this->getUser()); + $asideActivity->setLocation($this->getUser()->getCurrentLocation()); $duration = $request->query->get('duration', '300'); $duration = DateTime::createFromFormat('U', $duration); diff --git a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php index 727287972..300b34a6a 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php @@ -13,6 +13,7 @@ namespace Chill\AsideActivityBundle\Form; use Chill\AsideActivityBundle\Entity\AsideActivity; use Chill\AsideActivityBundle\Form\Type\PickAsideActivityCategoryType; +use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; @@ -20,6 +21,7 @@ use DateInterval; use DateTime; use DateTimeImmutable; use DateTimeZone; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; @@ -77,7 +79,15 @@ final class AsideActivityFormType extends AbstractType ->add('note', ChillTextareaType::class, [ '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, + ]) + ; foreach (['duration'] as $fieldName) { $builder->get($fieldName) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig index 5ffc73684..1e2711bfe 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig +++ b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig @@ -39,6 +39,9 @@ {% endif %} + {%- if entity.location.name is defined -%} +
{{ entity.location.name }}
+ {%- endif -%}
diff --git a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/view.html.twig b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/view.html.twig index 75da9a444..8fb487d31 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/view.html.twig +++ b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/view.html.twig @@ -22,6 +22,13 @@
{{ 'Created for'|trans }}
{{ entity.agent }}
+ +
{{ 'Asideactivity location'|trans }}
+ {%- if entity.location.name is defined -%} +
{{ entity.location.name }}
+ {%- else -%} +
{{ 'No data given'|trans }}
+ {%- endif -%}

{{ 'Activity data'|trans }}

diff --git a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml index 25d07bd22..3c06db9c9 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml +++ b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml @@ -26,6 +26,7 @@ Users: Utilisateurs Emergency: Urgent by: "Par " location: Lieu +Asideactivity location: Localisation de l'activité # Crud crud: From 67ea62f33d6f322b3be998a1bd45afac6101201b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Aug 2023 12:25:30 +0200 Subject: [PATCH 03/11] Feature: [export] add byLocation filter/aggregators in asideActivity exports --- .../Aggregator/ByLocationAggregator.php | 92 ++++++++++++++++++ .../src/Export/Export/ListAsideActivity.php | 17 ++++ .../src/Export/Filter/ByLocationFilter.php | 94 +++++++++++++++++++ .../src/config/services/export.yaml | 16 +++- .../src/translations/messages.fr.yml | 6 ++ 5 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php create mode 100644 src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php new file mode 100644 index 000000000..c87a1078d --- /dev/null +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php @@ -0,0 +1,92 @@ +locationRepository->find($value)) { + return ''; + } + + return $l->getName(); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['by_aside_activity_location_aggregator']; + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'export.aggregator.Group by aside activity location'; + } + + /** + * @inheritDoc + */ + public function addRole(): ?string + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data): void + { + $qb->addSelect('IDENTITY(aside.location) AS by_aside_activity_location_aggregator') + ->addGroupBy('by_aside_activity_location_aggregator'); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ASIDE_ACTIVITY_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php index b46e120b5..248456b9d 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Export\Helper\DateTimeHelper; use Chill\MainBundle\Export\Helper\UserHelper; use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface; +use Chill\MainBundle\Repository\LocationRepository; use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use DateTimeInterface; @@ -58,6 +59,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface CenterRepositoryInterface $centerRepository, AsideActivityCategoryRepository $asideActivityCategoryRepository, CategoryRender $categoryRender, + private LocationRepository $locationRepository, TranslatableStringHelperInterface $translatableStringHelper ) { $this->em = $em; @@ -145,6 +147,19 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface return $this->categoryRender->renderString($c, []); }; + case 'location': + return function ($value) { + if ('_header' === $value) { + return 'export.aside_activity.location'; + } + + if (null === $value || '' === $value || null === $l = $this->locationRepository->find($value)) { + return ''; + } + + return $l->getName(); + }; + case 'main_scope': return function ($value) { if ('_header' === $value) { @@ -191,6 +206,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface 'date', 'duration', 'note', + 'location', ]; } @@ -226,6 +242,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface ->addSelect('IDENTITY(aside.type) AS aside_activity_type') ->addSelect('aside.date') ->addSelect('aside.duration') + ->addSelect('IDENTITY(aside.location) AS location') ->addSelect('aside.note'); return $qb; diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php new file mode 100644 index 000000000..b164c127f --- /dev/null +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php @@ -0,0 +1,94 @@ +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(), + ]); + } + + /** + * @inheritDoc + */ + public function getFormDefaultData(): array + { + return []; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $locations = array_map( + fn (Location $l): string => $l->getName(), + $data['locations']->toArray() + ); + + return ['export.filter.Filtered by aside activity location: only %location%', [ + '%location%' => implode(', ', $locations), + ]]; + } + + /** + * @inheritDoc + */ + public function addRole(): ?string + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data): void + { + $clause = $qb->expr()->in('aside.location', ':locations'); + + $qb->andWhere($clause); + $qb->setParameter('locations', $data['locations']); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ASIDE_ACTIVITY_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml b/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml index a29413e15..5614c1725 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml +++ b/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml @@ -46,19 +46,29 @@ services: tags: - { name: chill.export_filter, alias: 'aside_activity_user_filter' } + chill.aside_activity.export.location_filter: + class: Chill\AsideActivityBundle\Export\Filter\ByLocationFilter + tags: + - { name: chill.export_filter, alias: 'aside_activity_location_filter' } + ## Aggregators chill.aside_activity.export.type_aggregator: class: Chill\AsideActivityBundle\Export\Aggregator\ByActivityTypeAggregator tags: - - { name: chill.export_aggregator, alias: activity_type_aggregator } + - { name: chill.export_aggregator, alias: 'activity_type_aggregator' } chill.aside_activity.export.user_job_aggregator: class: Chill\AsideActivityBundle\Export\Aggregator\ByUserJobAggregator tags: - - { name: chill.export_aggregator, alias: aside_activity_user_job_aggregator } + - { name: chill.export_aggregator, alias: 'aside_activity_user_job_aggregator' } chill.aside_activity.export.user_scope_aggregator: class: Chill\AsideActivityBundle\Export\Aggregator\ByUserScopeAggregator tags: - - { name: chill.export_aggregator, alias: aside_activity_user_scope_aggregator } + - { name: chill.export_aggregator, alias: 'aside_activity_user_scope_aggregator' } + + chill.aside_activity.export.location_aggregator: + class: Chill\AsideActivityBundle\Export\Aggregator\ByLocationAggregator + tags: + - { name: chill.export_aggregator, alias: 'aside_activity_location_aggregator' } diff --git a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml index 3c06db9c9..6028193db 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml +++ b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml @@ -183,6 +183,7 @@ export: duration: Durée note: Note id: Identifiant + location: Localisation Exports of aside activities: Exports des activités annexes Count aside activities: Nombre d'activités annexes @@ -203,11 +204,16 @@ export: Filter by user jobs: Filtrer les activités annexes par métier des utilisateurs 'Filtered aside activities by user scope: only %scopes%': "Filtré par service des utilisateur: uniquement %scopes%" Filter by user scope: Filtrer les activités annexes par service d'utilisateur + Filter by aside activity location: Filtrer les activités annexes par localisation + 'Filtered by aside activity location: only %location%': "Filtré par localisation: uniquement %location%" aggregator: Group by aside activity type: Grouper les activités annexes par type d'activité Aside activity type: Type d'activité annexe Aggregate by user job: Grouper les activités annexes par métier des utilisateurs Aggregate by user scope: Grouper les activités annexes par service des utilisateurs + Aside activity location: Localisation des activités annexe + Group by aside activity location: Grouper les activités annexes par localisation + Aside activity localisation: Localisation # ROLES CHILL_ASIDE_ACTIVITY_STATS: Statistiques pour les activités annexes From 46a54644294a63fd5ce7a21005000189b411edcf Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Aug 2023 13:06:21 +0200 Subject: [PATCH 04/11] Fix missing translation in acpw exports --- src/Bundle/ChillPersonBundle/translations/messages.fr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 892bb0dfd..12ec6ea29 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1225,6 +1225,7 @@ export: acpw: List of accompanying period works: Liste des actions List description: Génère une liste des actions d'accompagnement, filtrée sur différents paramètres. + Date of calculation for associated elements: Date de calcul des éléments associés help_description: L'agent traitant de l'action sera valide à cette date id: Identifiant de l'action startDate: Date de début From fe1fe31b68f1f0af813f00a8f4d1570935a0f68f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Aug 2023 13:13:33 +0200 Subject: [PATCH 05/11] add changies --- .changes/unreleased/Feature-20230817-131059.yaml | 6 ++++++ .changes/unreleased/Feature-20230817-131152.yaml | 6 ++++++ .changes/unreleased/Fixed-20230817-131239.yaml | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 .changes/unreleased/Feature-20230817-131059.yaml create mode 100644 .changes/unreleased/Feature-20230817-131152.yaml create mode 100644 .changes/unreleased/Fixed-20230817-131239.yaml diff --git a/.changes/unreleased/Feature-20230817-131059.yaml b/.changes/unreleased/Feature-20230817-131059.yaml new file mode 100644 index 000000000..29de8ec34 --- /dev/null +++ b/.changes/unreleased/Feature-20230817-131059.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Add locations in Aside Activity. By default, suggest user location, otherwise + a select with all locations. +time: 2023-08-17T13:10:59.152278661+02:00 +custom: + Issue: "133" diff --git a/.changes/unreleased/Feature-20230817-131152.yaml b/.changes/unreleased/Feature-20230817-131152.yaml new file mode 100644 index 000000000..bf9a165bf --- /dev/null +++ b/.changes/unreleased/Feature-20230817-131152.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: 'Adapt Aside Activity exports: display location, filter by location, group by + location' +time: 2023-08-17T13:11:52.911356021+02:00 +custom: + Issue: "133" diff --git a/.changes/unreleased/Fixed-20230817-131239.yaml b/.changes/unreleased/Fixed-20230817-131239.yaml new file mode 100644 index 000000000..6fc62f433 --- /dev/null +++ b/.changes/unreleased/Fixed-20230817-131239.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Missing translation in Work Actions exports +time: 2023-08-17T13:12:39.159627128+02:00 +custom: + Issue: "" From 75bca46b981111314afd62725a075bf4bbec1ab7 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Aug 2023 14:49:29 +0200 Subject: [PATCH 06/11] cs fixer --- docs/source/_static/code/exports/CountPerson.php | 2 +- .../widgets/ChillMainConfiguration.php | 2 +- rector.php | 7 +++++++ .../Controller/ActivityController.php | 5 ++--- .../Repository/ActivityACLAwareRepository.php | 2 +- .../ActivityDocumentACLAwareRepositoryTest.php | 1 - .../src/Export/Aggregator/ByLocationAggregator.php | 12 ++++++++++-- .../src/Export/Filter/ByLocationFilter.php | 11 ++++++++++- .../src/migrations/Version20230816112809.php | 7 +++++++ .../Connector/MSGraph/MSUserAbsenceReader.php | 1 - .../AccompanyingPeriodCalendarGenericDocProvider.php | 2 -- .../Connector/MSGraph/MSUserAbsenceReaderTest.php | 1 - .../GenericDocForAccompanyingPeriodController.php | 1 - .../Controller/GenericDocForPerson.php | 1 - .../ChillDocStoreBundle/GenericDoc/FetchQuery.php | 2 -- ...ericDocForAccompanyingPeriodProviderInterface.php | 1 - .../AccompanyingCourseDocumentGenericDocProvider.php | 1 - .../GenericDoc/Twig/GenericDocExtensionRuntime.php | 1 - .../GenericDoc/Twig/GenericDocRendererInterface.php | 1 - .../Repository/PersonDocumentACLAwareRepository.php | 1 - .../Tests/GenericDoc/FetchQueryToSqlBuilderTest.php | 4 ---- .../PersonDocumentACLAwareRepositoryTest.php | 2 -- src/Bundle/ChillMainBundle/Cron/CronManager.php | 1 - .../Form/Type/Listing/FilterOrderType.php | 2 -- .../Tests/Cron/CronJobDatabaseInteractionTest.php | 1 - ...teAddressWithReferenceOrPostalCodeCronJobTest.php | 1 - .../RelationshipNoDuplicateValidator.php | 6 ++---- .../Repository/SingleTaskStateRepository.php | 1 - .../ChillThirdPartyBundle/Form/ThirdPartyType.php | 2 +- 29 files changed, 42 insertions(+), 40 deletions(-) diff --git a/docs/source/_static/code/exports/CountPerson.php b/docs/source/_static/code/exports/CountPerson.php index be800e52c..5d9cb2c2f 100644 --- a/docs/source/_static/code/exports/CountPerson.php +++ b/docs/source/_static/code/exports/CountPerson.php @@ -94,7 +94,7 @@ class CountPerson implements ExportInterface public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { // we gather all center the user choose. - $centers = array_map(static fn($el) => $el['center'], $acl); + $centers = array_map(static fn ($el) => $el['center'], $acl); $qb = $this->entityManager->createQueryBuilder(); diff --git a/docs/source/development/user-interface/widgets/ChillMainConfiguration.php b/docs/source/development/user-interface/widgets/ChillMainConfiguration.php index 9eca0ae76..cdad6b42b 100644 --- a/docs/source/development/user-interface/widgets/ChillMainConfiguration.php +++ b/docs/source/development/user-interface/widgets/ChillMainConfiguration.php @@ -56,7 +56,7 @@ class ChillMainConfiguration implements ConfigurationInterface ->end() // end of widgets ->end() // end of root/children ->end() // end of root -; + ; return $treeBuilder; } diff --git a/rector.php b/rector.php index c2e752c32..b8975b970 100644 --- a/rector.php +++ b/rector.php @@ -2,6 +2,13 @@ declare(strict_types=1); +/* + * Chill is a software for social workers + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Set\ValueObject\LevelSetList; diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 1e911ff08..1c1f0ab30 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -320,7 +320,6 @@ final class ActivityController extends AbstractController private function buildFilterOrder(AccompanyingPeriod|Person $associated): FilterOrderHelper { - $filterBuilder = $this->filterOrderHelperFactory->create(self::class); $types = $this->activityACLAwareRepository->findActivityTypeByAssociated($associated); $jobs = $this->activityACLAwareRepository->findUserJobByAssociated($associated); @@ -679,8 +678,8 @@ final class ActivityController extends AbstractController throw $this->createNotFoundException('Accompanying Period not found'); } - // TODO Add permission - // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + // TODO Add permission + // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); } else { throw $this->createNotFoundException('Person or Accompanying Period not found'); } diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php index 1544dd764..7925f861b 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php @@ -322,7 +322,7 @@ final readonly class ActivityACLAwareRepository implements ActivityACLAwareRepos $counter++; } - foreach ($person->getAccompanyingPeriodParticipations() as $participation) { + foreach ($person->getAccompanyingPeriodParticipations() as $participation) { if (!$this->security->isGranted(ActivityVoter::SEE, $participation->getAccompanyingPeriod())) { continue; } diff --git a/src/Bundle/ChillActivityBundle/Tests/Repository/ActivityDocumentACLAwareRepositoryTest.php b/src/Bundle/ChillActivityBundle/Tests/Repository/ActivityDocumentACLAwareRepositoryTest.php index ce4f318e3..74f1d2bd0 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Repository/ActivityDocumentACLAwareRepositoryTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Repository/ActivityDocumentACLAwareRepositoryTest.php @@ -122,5 +122,4 @@ class ActivityDocumentACLAwareRepositoryTest extends KernelTestCase yield [$person, $scopes, true, null, new \DateTimeImmutable("1 week ago"), "content"]; yield [$person, [], true, new \DateTimeImmutable("1 month ago"), new \DateTimeImmutable("1 week ago"), "content"]; } - } diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php index c87a1078d..c6a35e3d7 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByLocationAggregator.php @@ -1,5 +1,14 @@ throw new UserAbsenceSyncException("this status is not documented by Microsoft") }; } - } diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php index 6675f7c7e..1040f9f0a 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -190,6 +190,4 @@ final readonly class AccompanyingPeriodCalendarGenericDocProvider implements Gen return $query; } - - } diff --git a/src/Bundle/ChillCalendarBundle/Tests/RemoteCalendar/Connector/MSGraph/MSUserAbsenceReaderTest.php b/src/Bundle/ChillCalendarBundle/Tests/RemoteCalendar/Connector/MSGraph/MSUserAbsenceReaderTest.php index 089477fda..2ceab8b1f 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/RemoteCalendar/Connector/MSGraph/MSUserAbsenceReaderTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/RemoteCalendar/Connector/MSGraph/MSUserAbsenceReaderTest.php @@ -172,5 +172,4 @@ class MSUserAbsenceReaderTest extends TestCase "User is absent: absence is always enabled" ]; } - } diff --git a/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForAccompanyingPeriodController.php b/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForAccompanyingPeriodController.php index 70c41db50..9a0650b2d 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForAccompanyingPeriodController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForAccompanyingPeriodController.php @@ -94,5 +94,4 @@ final readonly class GenericDocForAccompanyingPeriodController ] )); } - } diff --git a/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForPerson.php b/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForPerson.php index 3484e0904..e010c41c5 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForPerson.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/GenericDocForPerson.php @@ -91,5 +91,4 @@ final readonly class GenericDocForPerson ] )); } - } diff --git a/src/Bundle/ChillDocStoreBundle/GenericDoc/FetchQuery.php b/src/Bundle/ChillDocStoreBundle/GenericDoc/FetchQuery.php index 30e07a841..b1631bb24 100644 --- a/src/Bundle/ChillDocStoreBundle/GenericDoc/FetchQuery.php +++ b/src/Bundle/ChillDocStoreBundle/GenericDoc/FetchQuery.php @@ -82,7 +82,6 @@ class FetchQuery implements FetchQueryInterface } unset($this->wheres[$index], $this->whereParams[$index], $this->whereTypes[$index]); - } public function removeJoinClause(int $index): void @@ -92,7 +91,6 @@ class FetchQuery implements FetchQueryInterface } unset($this->joins[$index], $this->joinParams[$index], $this->joinTypes[$index]); - } public function getSelectKeyString(): string diff --git a/src/Bundle/ChillDocStoreBundle/GenericDoc/GenericDocForAccompanyingPeriodProviderInterface.php b/src/Bundle/ChillDocStoreBundle/GenericDoc/GenericDocForAccompanyingPeriodProviderInterface.php index 0d3cb1c32..bffa19b53 100644 --- a/src/Bundle/ChillDocStoreBundle/GenericDoc/GenericDocForAccompanyingPeriodProviderInterface.php +++ b/src/Bundle/ChillDocStoreBundle/GenericDoc/GenericDocForAccompanyingPeriodProviderInterface.php @@ -27,5 +27,4 @@ interface GenericDocForAccompanyingPeriodProviderInterface * Return true if the user is allowed to see some documents for this provider. */ public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool; - } diff --git a/src/Bundle/ChillDocStoreBundle/GenericDoc/Providers/AccompanyingCourseDocumentGenericDocProvider.php b/src/Bundle/ChillDocStoreBundle/GenericDoc/Providers/AccompanyingCourseDocumentGenericDocProvider.php index fd36f7976..fe03a8b00 100644 --- a/src/Bundle/ChillDocStoreBundle/GenericDoc/Providers/AccompanyingCourseDocumentGenericDocProvider.php +++ b/src/Bundle/ChillDocStoreBundle/GenericDoc/Providers/AccompanyingCourseDocumentGenericDocProvider.php @@ -143,5 +143,4 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen return $query; } - } diff --git a/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocExtensionRuntime.php b/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocExtensionRuntime.php index 2dee0ed0b..8bb97a9b9 100644 --- a/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocExtensionRuntime.php +++ b/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocExtensionRuntime.php @@ -46,5 +46,4 @@ final readonly class GenericDocExtensionRuntime implements RuntimeExtensionInter throw new \LogicException("no renderer found"); } - } diff --git a/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocRendererInterface.php b/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocRendererInterface.php index 940001f4a..cdd28ac70 100644 --- a/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocRendererInterface.php +++ b/src/Bundle/ChillDocStoreBundle/GenericDoc/Twig/GenericDocRendererInterface.php @@ -20,5 +20,4 @@ interface GenericDocRendererInterface public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string; public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array; - } diff --git a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php index 26a42b894..12506581c 100644 --- a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php +++ b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php @@ -98,7 +98,6 @@ final readonly class PersonDocumentACLAwareRepository implements PersonDocumentA continue; } $orPersonId[] = $participation->getPerson()->getId(); - } if ([] === $orPersonId) { diff --git a/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/FetchQueryToSqlBuilderTest.php b/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/FetchQueryToSqlBuilderTest.php index 02be9460f..f55b889a9 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/FetchQueryToSqlBuilderTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/FetchQueryToSqlBuilderTest.php @@ -54,9 +54,6 @@ class FetchQueryToSqlBuilderTest extends KernelTestCase ); self::assertEquals(['foo', 'bar_baz', 'baz'], $params); self::assertEquals([Types::STRING, Types::STRING, Types::STRING], $types); - - - } public function testToSqlWithoutWhere(): void @@ -85,5 +82,4 @@ class FetchQueryToSqlBuilderTest extends KernelTestCase self::assertEquals([], $params); self::assertEquals([], $types); } - } diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Repository/PersonDocumentACLAwareRepositoryTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Repository/PersonDocumentACLAwareRepositoryTest.php index fd611042c..bb372a150 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/Repository/PersonDocumentACLAwareRepositoryTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/Repository/PersonDocumentACLAwareRepositoryTest.php @@ -142,7 +142,6 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), null]; yield [$period, null, null, 'test']; yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test']; - } public function provideDataBuildFetchQueryForPerson(): iterable @@ -154,5 +153,4 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase yield [null, null, 'test']; yield [new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test']; } - } diff --git a/src/Bundle/ChillMainBundle/Cron/CronManager.php b/src/Bundle/ChillMainBundle/Cron/CronManager.php index a3e82a170..322000cb3 100644 --- a/src/Bundle/ChillMainBundle/Cron/CronManager.php +++ b/src/Bundle/ChillMainBundle/Cron/CronManager.php @@ -88,7 +88,6 @@ class CronManager implements CronManagerInterface foreach ($orderedJobs as $job) { if ($job->canRun($lasts[$job->getKey()] ?? null)) { if (array_key_exists($job->getKey(), $lasts)) { - $executionData = $lasts[$job->getKey()]->getLastExecutionData(); $this->entityManager diff --git a/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php b/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php index 51d1b3974..b0d80176b 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php @@ -122,7 +122,6 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType foreach ($helper->getUserPickers() as $name => [ 'label' => $label, 'options' => $opts ]) { - $userPickersBuilder->add( $name, PickUserDynamicType::class, @@ -136,7 +135,6 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType $builder->add($userPickersBuilder); } - } public static function buildCheckboxChoices(array $choices, array $trans = []): array diff --git a/src/Bundle/ChillMainBundle/Tests/Cron/CronJobDatabaseInteractionTest.php b/src/Bundle/ChillMainBundle/Tests/Cron/CronJobDatabaseInteractionTest.php index 0b80730fe..c8ab200fc 100644 --- a/src/Bundle/ChillMainBundle/Tests/Cron/CronJobDatabaseInteractionTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Cron/CronJobDatabaseInteractionTest.php @@ -65,7 +65,6 @@ class CronJobDatabaseInteractionTest extends KernelTestCase // run a second time $manager->run(); } - } class JobWithReturn implements CronJobInterface diff --git a/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php index 69eeca2da..9e83f2e7e 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php @@ -64,5 +64,4 @@ class CollateAddressWithReferenceOrPostalCodeCronJobTest extends TestCase yield [new \DateTimeImmutable('2023-07-10T12:00:00'), new \DateTimeImmutable('2023-07-01T12:00:00'), true]; yield [new \DateTimeImmutable('2023-07-10T12:00:00'), null, true]; } - } diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicateValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicateValidator.php index 5b1038287..f8538cd09 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicateValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicateValidator.php @@ -47,11 +47,9 @@ class RelationshipNoDuplicateValidator extends ConstraintValidator foreach ($relationships as $r) { if (spl_object_hash($r) !== spl_object_hash($value) - and - ( + and ( ($r->getFromPerson() === $fromPerson and $r->getToPerson() === $toPerson) - || - ($r->getFromPerson() === $toPerson and $r->getToPerson() === $fromPerson) + || ($r->getFromPerson() === $toPerson and $r->getToPerson() === $fromPerson) ) ) { $this->context->buildViolation($constraint->message) diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskStateRepository.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskStateRepository.php index 2d64c69a0..c0d596e09 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskStateRepository.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskStateRepository.php @@ -43,5 +43,4 @@ class SingleTaskStateRepository return $states; } - } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index 6c4984f33..b1446a543 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -117,7 +117,7 @@ class ThirdPartyType extends AbstractType 'label' => 'thirdparty.Contact data are confidential', ]); - // Institutional ThirdParty (parent) + // Institutional ThirdParty (parent) } else { $builder ->add('nameCompany', TextType::class, [ From bd4f3e38eb013b397580a61316ab48f15d78e61a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Aug 2023 14:57:51 +0200 Subject: [PATCH 07/11] run rector --- .../ChillAsideActivityBundle/src/Entity/AsideActivity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php index 2486d1fcc..412bb873e 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php @@ -64,7 +64,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface * @ORM\ManyToOne(targetEntity=Location::class) * @ORM\JoinColumn(nullable=true) */ - private ?Location $location; + private ?Location $location = null; /** * @ORM\Column(type="text", nullable=true) From 0a6131abcce8072d1cc7b18d8e7d4889ed0fd278 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 30 Aug 2023 15:54:43 +0200 Subject: [PATCH 08/11] csfixer after (rebuild php container) --- .../ChillActivityBundle/Controller/ActivityController.php | 4 ++-- src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 1c1f0ab30..17545c1af 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -678,8 +678,8 @@ final class ActivityController extends AbstractController throw $this->createNotFoundException('Accompanying Period not found'); } - // TODO Add permission - // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + // TODO Add permission + // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); } else { throw $this->createNotFoundException('Person or Accompanying Period not found'); } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index b1446a543..6c4984f33 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -117,7 +117,7 @@ class ThirdPartyType extends AbstractType 'label' => 'thirdparty.Contact data are confidential', ]); - // Institutional ThirdParty (parent) + // Institutional ThirdParty (parent) } else { $builder ->add('nameCompany', TextType::class, [ From 30fa57b99903e8b410128e780ecd4b4b0206f8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Sep 2023 12:57:41 +0200 Subject: [PATCH 09/11] remove unused comment on Version migration --- .../src/migrations/Version20230816112809.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php b/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php index b7befddc3..bde8af1e3 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php +++ b/src/Bundle/ChillAsideActivityBundle/src/migrations/Version20230816112809.php @@ -14,9 +14,6 @@ namespace Chill\Migrations\AsideActivity; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -/** - * Auto-generated Migration: Please modify to your needs! - */ final class Version20230816112809 extends AbstractMigration { public function getDescription(): string From 665f0b4ccbd70292656ccfe62fe183f5da897e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Sep 2023 12:58:40 +0200 Subject: [PATCH 10/11] Use PickUserLocationType instead of an EntityType --- .../src/Export/Export/ListAsideActivity.php | 1 + .../src/Export/Filter/ByLocationFilter.php | 38 ++++++++++--------- .../src/Form/AsideActivityFormType.php | 9 +---- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php index 248456b9d..93b0c495d 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php @@ -75,6 +75,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface public function buildForm(FormBuilderInterface $builder) { } + public function getFormDefaultData(): array { return []; diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php index 328020d51..f2808eca1 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByLocationFilter.php @@ -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), diff --git a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php index 300b34a6a..2a6068424 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php @@ -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) { From b6fe830f1e05be6784c30bb24a414dc56fcb0fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Sep 2023 13:00:24 +0200 Subject: [PATCH 11/11] use newer notation for declaring service --- .../src/config/services/export.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml b/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml index 5614c1725..40cb120da 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml +++ b/src/Bundle/ChillAsideActivityBundle/src/config/services/export.yaml @@ -46,8 +46,7 @@ services: tags: - { name: chill.export_filter, alias: 'aside_activity_user_filter' } - chill.aside_activity.export.location_filter: - class: Chill\AsideActivityBundle\Export\Filter\ByLocationFilter + Chill\AsideActivityBundle\Export\Filter\ByLocationFilter: tags: - { name: chill.export_filter, alias: 'aside_activity_location_filter' } @@ -68,7 +67,6 @@ services: tags: - { name: chill.export_aggregator, alias: 'aside_activity_user_scope_aggregator' } - chill.aside_activity.export.location_aggregator: - class: Chill\AsideActivityBundle\Export\Aggregator\ByLocationAggregator + Chill\AsideActivityBundle\Export\Aggregator\ByLocationAggregator: tags: - { name: chill.export_aggregator, alias: 'aside_activity_location_aggregator' }