diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php new file mode 100644 index 000000000..ea125adb2 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php @@ -0,0 +1,81 @@ +actionRender = $actionRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_socialactions', EntityType::class, [ + 'class' => SocialAction::class, + 'choice_label' => function (SocialAction $sa) { + return $this->actionRender->renderString($sa, []); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by linked socialaction'; + } + + public function describeAction($data, $format = 'string'): array + { + $actions = []; + + foreach ($data['accepted_socialactions'] as $sa) { + $actions[] = $this->actionRender->renderString($sa, []); + } + + return ['Filtered activity by linked socialaction: only %actions%', [ + '%actions%' => implode(", ou", $actions) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('activity.socialActions', ':socialactions'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('socialactions', $data['accepted_socialactions']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php new file mode 100644 index 000000000..247b0ea32 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php @@ -0,0 +1,81 @@ +issueRender = $issueRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_socialissues', EntityType::class, [ + 'class' => SocialIssue::class, + 'choice_label' => function(SocialIssue $si) { + return $this->issueRender->renderString($si, []); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by linked socialissue'; + } + + public function describeAction($data, $format = 'string'): array + { + $issues = []; + + foreach ($data['accepted_socialissues'] as $si) { + $issues[] = $this->issueRender->renderString($si, []); + } + + return ['Filtered activity by linked socialissue: only %issues%', [ + '%issues%' => implode(", ou", $issues) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('activity.socialIssues', ':socialissues'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('socialissues', $data['accepted_socialissues']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/ByUserFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/ByUserFilter.php new file mode 100644 index 000000000..9fef06f72 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/ByUserFilter.php @@ -0,0 +1,80 @@ +userRender = $userRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_users', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + return $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by linked users'; + } + + public function describeAction($data, $format = 'string'): array + { + $users = []; + + foreach ($data['accepted_users'] as $u) { + $users[] = $this->userRender->renderString($u, []); + } + + return ['Filtered activity by linked users: only %users%', [ + '%users%' => implode(", ou", $users) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('activity.users', ':users'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('users', $data['accepted_users']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php new file mode 100644 index 000000000..d7a823891 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php @@ -0,0 +1,86 @@ + true, + 'activity is not emergency' => false, + ]; + + private CONST DEFAULT_CHOICE = false; + + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_emergency', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by emergency'; + } + + public function describeAction($data, $format = 'string'): array + { + foreach (self::CHOICES as $k => $v) { + if ($v === $data['accepted_emergency']) { + $choice = $k; + } + } + + return ['Filtered activity by emergency: only %emergency%', [ + '%emergency%' => $this->translator->trans($choice) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->eq('activity.emergency', ':emergency'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('emergency', $data['accepted_emergency']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php new file mode 100644 index 000000000..22e1f3c30 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php @@ -0,0 +1,85 @@ +translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_locationtype', EntityType::class, [ + 'class' => LocationType::class, + 'choice_label' => function(LocationType $type) { + return $this->translatableStringHelper->localize($type->getTitle()); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by locationtype'; + } + + public function describeAction($data, $format = 'string'): array + { + $types = []; + + foreach ($data['accepted_locationtype'] as $type) { + $types[] = $this->translatableStringHelper->localize( + $type->getTitle() + ); + } + + return ['Filtered activity by locationtype: only %types%', [ + '%types%' => implode(", ou", $types) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + if (!in_array('location', $qb->getAllAliases())) { + $qb->join('activity.location', 'location'); + } + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('location.locationType', ':locationtype'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('locationtype', $data['accepted_locationtype']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/SentReceivedFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/SentReceivedFilter.php new file mode 100644 index 000000000..409c974ac --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/SentReceivedFilter.php @@ -0,0 +1,82 @@ + Activity::SENTRECEIVED_SENT, + 'is received' => Activity::SENTRECEIVED_RECEIVED, + ]; + + private CONST DEFAULT_CHOICE = Activity::SENTRECEIVED_SENT; + + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_sentreceived', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + public function getTitle(): string + { + return 'Filter activity by sentreceived'; + } + + public function describeAction($data, $format = 'string'): array + { + $sentreceived = array_flip(self::CHOICES)[$data['accepted_sentreceived']]; + + return ['Filtered activity by sentreceived: only %sentreceived%', [ + '%sentreceived%' => $this->translator->trans($sentreceived) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->eq('activity.sentReceived', ':sentreceived'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('sentreceived', $data['accepted_sentreceived']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserFilter.php new file mode 100644 index 000000000..02aff8cad --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserFilter.php @@ -0,0 +1,82 @@ +userRender = $userRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_users', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + return $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true, + 'label' => 'Creators' + ]); + } + + public function getTitle(): string + { + return 'Filter activity by user'; + } + + public function describeAction($data, $format = 'string'): array + { + $users = []; + + foreach ($data['accepted_users'] as $u) { + $users[] = $this->userRender->renderString($u, []); + } + + return ['Filtered activity by user: only %users%', [ + '%users%' => implode(", ou", $users) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('activity.user', ':users'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('users', $data['accepted_users']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserScopeFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserScopeFilter.php new file mode 100644 index 000000000..abc26d418 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/UserScopeFilter.php @@ -0,0 +1,89 @@ +translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_userscope', EntityType::class, [ + 'class' => Scope::class, + 'choice_label' => function (Scope $s) { + return $this->translatableStringHelper->localize( + $s->getName() + ); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function getTitle(): string + { + return 'Filter activity by userscope'; + } + + public function describeAction($data, $format = 'string'): array + { + $scopes = []; + + foreach ($data['accepted_userscope'] as $s) { + $scopes[] = $this->translatableStringHelper->localize( + $s->getName() + ); + } + + return ['Filtered activity by userscope: only %scopes%', [ + '%scopes%' => implode(", ou", $scopes) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + if (!in_array('user', $qb->getAllAliases())) { + $qb->join('activity.user', 'user'); + } + + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('user.mainScope', ':userscope'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('userscope', $data['accepted_userscope']); + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/config/services/export.yaml b/src/Bundle/ChillActivityBundle/config/services/export.yaml index c6b0e9718..393e452e6 100644 --- a/src/Bundle/ChillActivityBundle/config/services/export.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/export.yaml @@ -67,6 +67,46 @@ services: name: chill.export_filter alias: 'activity_person_having_ac_bw_date_filter' + chill.activity.export.locationtype_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\LocationTypeFilter + tags: + - { name: chill.export_filter, alias: 'activity_locationtype_filter' } + + chill.activity.export.byuser_filter: # TMS (M2M) + class: Chill\ActivityBundle\Export\Filter\ACPFilters\ByUserFilter + tags: + - { name: chill.export_filter, alias: 'activity_byuser_filter' } + + chill.activity.export.emergency_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\EmergencyFilter + tags: + - { name: chill.export_filter, alias: 'activity_emergency_filter' } + + chill.activity.export.sentreceived_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\SentReceivedFilter + tags: + - { name: chill.export_filter, alias: 'activity_sentreceived_filter' } + + chill.activity.export.bysocialaction_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\BySocialActionFilter + tags: + - { name: chill.export_filter, alias: 'activity_bysocialaction_filter' } + + chill.activity.export.bysocialissue_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\BySocialIssueFilter + tags: + - { name: chill.export_filter, alias: 'activity_bysocialissue_filter' } + + chill.activity.export.user_filter: # Creator (M2O) + class: Chill\ActivityBundle\Export\Filter\ACPFilters\UserFilter + tags: + - { name: chill.export_filter, alias: 'activity_user_filter' } + + chill.activity.export.userscope_filter: + class: Chill\ActivityBundle\Export\Filter\ACPFilters\UserScopeFilter + tags: + - { name: chill.export_filter, alias: 'activity_userscope_filter' } + ## Aggregators chill.activity.export.reason_aggregator: class: Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index f6bfafc41..b66c606d5 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -249,6 +249,32 @@ Activity reasons for those activities: Sujets de ces activités Filter by activity type: Filtrer les activités par type +Filter activity by locationtype: Filtrer les activités par type de localisation +'Filtered activity by locationtype: only %types%': "Filtré par type de localisation: uniquement %types%" +Accepted locationtype: Types de localisation +Filter activity by linked users: Filtrer les activités par TMS +'Filtered activity by linked users: only %users%': "Filtré par TMS: uniquement %users%" +Accepted users: TMS(s) +Filter activity by emergency: Filtrer les activités par urgence +'Filtered activity by emergency: only %emergency%': "Filtré par urgence: uniquement %emergency%" +activity is emergency: l'activité est urgente +activity is not emergency: l'activité n'est pas urgente +Filter activity by sentreceived: Filtrer les activités par envoyé/reçu +'Filtered activity by sentreceived: only %sentreceived%': "Filtré par envoyé/reçu: uniquement %sentreceived%" +Accepted sentreceived: '' +is sent: envoyé +is received: reçu +Filter activity by linked socialaction: Filtrer les activités par action liée +'Filtered activity by linked socialaction: only %actions%': "Filtré par action liée: uniquement %actions%" +Filter activity by linked socialissue: Filtrer les activités par problématique liée +'Filtered activity by linked socialissue: only %issues%': "Filtré par problématique liée: uniquement %issues%" +Filter activity by user: Filtrer les activités par créateur +'Filtered activity by user: only %users%': "Filtré par créateur: uniquement %users%" +Creators: Créateurs +Filter activity by userscope: Filtrer les activités par service du créateur +'Filtered activity by userscope: only %scopes%': "Filtré par service du créateur: uniquement %scopes%" +Accepted userscope: Services + #aggregators Activity type: Type d'activité Activity user: Utilisateur lié à l'activity