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