diff --git a/.changes/unreleased/Feature-20240207-164038.yaml b/.changes/unreleased/Feature-20240207-164038.yaml new file mode 100644 index 000000000..ff5096036 --- /dev/null +++ b/.changes/unreleased/Feature-20240207-164038.yaml @@ -0,0 +1,5 @@ +kind: Feature +body: Allow to group activities linked with accompanying period by reason +time: 2024-02-07T16:40:38.408575109+01:00 +custom: + Issue: "229" diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php similarity index 86% rename from src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php rename to src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php index 569c4ca9a..9945fd80a 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php @@ -9,7 +9,7 @@ declare(strict_types=1); * the LICENSE file that was distributed with this source code. */ -namespace Chill\ActivityBundle\Export\Aggregator\PersonAggregators; +namespace Chill\ActivityBundle\Export\Aggregator; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Repository\ActivityReasonCategoryRepository; @@ -25,8 +25,11 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; class ActivityReasonAggregator implements AggregatorInterface, ExportElementValidatedInterface { - public function __construct(protected ActivityReasonCategoryRepository $activityReasonCategoryRepository, protected ActivityReasonRepository $activityReasonRepository, protected TranslatableStringHelper $translatableStringHelper) - { + public function __construct( + protected ActivityReasonCategoryRepository $activityReasonCategoryRepository, + protected ActivityReasonRepository $activityReasonRepository, + protected TranslatableStringHelper $translatableStringHelper + ) { } public function addRole(): ?string @@ -51,7 +54,7 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali // make a jointure only if needed if (!\in_array('actreasons', $qb->getAllAliases(), true)) { - $qb->innerJoin('activity.reasons', 'actreasons'); + $qb->leftJoin('activity.reasons', 'actreasons'); } // join category if necessary @@ -62,19 +65,12 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali } } - // add the "group by" part - $groupBy = $qb->getDQLPart('groupBy'); - - if (\count($groupBy) > 0) { - $qb->addGroupBy($alias); - } else { - $qb->groupBy($alias); - } + $qb->addGroupBy($alias); } public function applyOn(): string { - return Declarations::ACTIVITY_PERSON; + return Declarations::ACTIVITY; } public function buildForm(FormBuilderInterface $builder) @@ -96,7 +92,9 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali public function getFormDefaultData(): array { - return []; + return [ + 'level' => 'reasons', + ]; } public function getLabels($key, array $values, $data) diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/ActivityReasonAggregatorTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/ActivityReasonAggregatorTest.php similarity index 69% rename from src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/ActivityReasonAggregatorTest.php rename to src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/ActivityReasonAggregatorTest.php index 004de0b99..3e1d473f0 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/ActivityReasonAggregatorTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/ActivityReasonAggregatorTest.php @@ -9,10 +9,10 @@ declare(strict_types=1); * the LICENSE file that was distributed with this source code. */ -namespace Chill\ActivityBundle\Tests\Export\Aggregator\PersonAggregators; +namespace Chill\ActivityBundle\Tests\Export\Aggregator; use Chill\ActivityBundle\Entity\Activity; -use Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityReasonAggregator; +use Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Doctrine\ORM\EntityManagerInterface; use Prophecy\PhpUnit\ProphecyTrait; @@ -33,14 +33,14 @@ final class ActivityReasonAggregatorTest extends AbstractAggregatorTest self::bootKernel(); $this->aggregator = self::$container->get(ActivityReasonAggregator::class); + /* + $request = $this->prophesize() + ->willExtend(\Symfony\Component\HttpFoundation\Request::class); - $request = $this->prophesize() - ->willExtend(\Symfony\Component\HttpFoundation\Request::class); + $request->getLocale()->willReturn('fr'); - $request->getLocale()->willReturn('fr'); - - self::$container->get('request_stack') - ->push($request->reveal()); + self::$container->get('request_stack') + ->push($request->reveal());*/ } public function getAggregator() @@ -65,7 +65,12 @@ final class ActivityReasonAggregatorTest extends AbstractAggregatorTest return [ $em->createQueryBuilder() ->select('count(activity.id)') - ->from(Activity::class, 'activity'), + ->from(Activity::class, 'activity') + ->join('activity.person', 'person'), + $em->createQueryBuilder() + ->select('count(activity.id)') + ->from(Activity::class, 'activity') + ->join('activity.accompanyingPeriod', 'accompanyingPeriod'), $em->createQueryBuilder() ->select('count(activity.id)') ->from(Activity::class, 'activity') diff --git a/src/Bundle/ChillActivityBundle/config/services/export.yaml b/src/Bundle/ChillActivityBundle/config/services/export.yaml index ef691ba0d..b52911295 100644 --- a/src/Bundle/ChillActivityBundle/config/services/export.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/export.yaml @@ -153,7 +153,7 @@ services: ## Aggregators - Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityReasonAggregator: + Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator: tags: - { name: chill.export_aggregator, alias: activity_reason_aggregator }