diff --git a/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php b/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php index 40109d568..826a302a8 100644 --- a/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php +++ b/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php @@ -16,7 +16,7 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; -#[ORM\Entity] +#[ORM\Entity(repositoryClass: EventThemeRepository::class)] #[ORM\Table(name: 'chill_event_budget_element')] class EventBudgetElement { diff --git a/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php b/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php index 685912191..66e407a09 100644 --- a/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php +++ b/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php @@ -12,14 +12,17 @@ declare(strict_types=1); namespace Chill\EventBundle\Export\Export; use Chill\EventBundle\Entity\Event; +use Chill\EventBundle\Entity\EventBudgetElement; use Chill\EventBundle\Export\Declarations; +use Chill\EventBundle\Repository\EventBudgetElementRepository; +use Chill\EventBundle\Repository\EventThemeRepository; use Chill\EventBundle\Security\EventVoter; +use Chill\EventBundle\Templating\Entity\EventThemeRender; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\ListInterface; -use Chill\MainBundle\Form\Type\PickRollingDateType; -use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; @@ -42,6 +45,9 @@ class ListEvents implements ListInterface, GroupedExportInterface 'event_moderator', 'event_participants_count', 'event_location', + 'event_budget_elements', + 'event_animators', + 'event_themes', ]; private readonly bool $filterStatsByCenters; @@ -50,6 +56,10 @@ class ListEvents implements ListInterface, GroupedExportInterface protected readonly EntityManagerInterface $entityManager, ParameterBagInterface $parameterBag, protected readonly TranslatableStringHelperInterface $translatableStringHelper, + protected readonly EventThemeRender $eventThemeRender, + protected readonly EventThemeRepository $eventThemeRepository, + protected readonly LabelThirdPartyHelper $labelThirdPartyHelper, + protected readonly EventBudgetElementRepository $eventBudgetElementRepository, ) { $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } @@ -82,12 +92,12 @@ class ListEvents implements ListInterface, GroupedExportInterface ]; } - public function getAllowedFormattersTypes() + public function getAllowedFormattersTypes(): array { return [FormatterInterface::TYPE_LIST]; } - public function getDescription() + public function getDescription(): string { return 'event.export.list.description.Create a list of events according to various filters.'; } @@ -97,54 +107,83 @@ class ListEvents implements ListInterface, GroupedExportInterface return 'Exports of events'; } - public function getLabels($key, array $values, $data) + public function getLabels($key, array $values, $data): \Closure { - switch ($key) { - case 'event_id': - return fn ($value) => '_header' === $value ? 'ID' : $value; + return match ($key) { + 'event_id' => fn ($value) => '_header' === $value ? 'ID' : $value, + 'event_name' => fn ($value) => '_header' === $value ? 'Name' : $value, + 'event_date' => function ($value) { + if ('_header' === $value) { + return 'Date'; + } - case 'event_name': - return fn ($value) => '_header' === $value ? 'Name' : $value; + if ($value instanceof \DateTime) { + return $value->format('Y-m-d'); + } - case 'event_date': - return function ($value) { - if ('_header' === $value) { - return 'Date'; - } + $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); - if ($value instanceof \DateTime) { - return $value->format('Y-m-d'); - } + return $date ? $date->format('Y-m-d') : $value; + }, + 'event_type' => function ($value) { + if ('_header' === $value) { + return 'event type'; + } - $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); + return $this->translatableStringHelper->localize(json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR)); + }, + 'event_center' => fn ($value) => '_header' === $value ? 'Center' : $value, + 'event_moderator' => fn ($value) => '_header' === $value ? 'Moderator' : $value, + 'event_participants_count' => fn ($value) => '_header' === $value ? 'Participants Count' : $value, + 'event_location' => fn ($value) => '_header' === $value ? 'Location' : $value, + 'event_budget_elements' => function ($value) use ($key) { + if ('_header' === $value) { + return 'export.event.list.'.$key; + } - return $date ? $date->format('Y-m-d') : $value; - }; + if (null === $value || '' === $value) { + return ''; + } - case 'event_type': - return function ($value) { - if ('_header' === $value) { - return 'event type'; - } + $ids = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR); - return $this->translatableStringHelper->localize(json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR)); - }; + if (!is_array($ids)) { + return ''; + } - case 'event_center': - return fn ($value) => '_header' === $value ? 'Center' : $value; + $elements = $this->eventBudgetElementRepository->findBy(['id' => $ids]); - case 'event_moderator': - return fn ($value) => '_header' === $value ? 'Moderator' : $value; + return implode( + ' | ', + array_map(function ($element) { + $kindName = $this->translatableStringHelper->localize($element->getKind()->getName()); + $amount = number_format($element->getAmount(), 2, '.', ''); - case 'event_participants_count': - return fn ($value) => '_header' === $value ? 'Participants Count' : $value; + return sprintf('%s: %s€', $kindName, $amount); + }, $elements) + ); + }, + 'event_animators' => $this->labelThirdPartyHelper->getLabelMulti($key, $values, 'export.list.acp.'.$key), + 'event_themes' => function ($value) use ($key) { + if ('_header' === $value) { + return 'export.event.list.'.$key; + } - case 'event_location': - return fn ($value) => '_header' === $value ? 'Location' : $value; + if (null === $value) { + return ''; + } - default: - return fn ($value) => '_header' === $value ? $key : $value; - } + return implode( + '|', + array_map( + fn ($t) => $this->eventThemeRender->renderString($this->eventThemeRepository->find($t), []), + json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR) + ) + ); + }, + + default => fn ($value) => '_header' === $value ? $key : $value, + }; } public function getQueryKeys($data) @@ -232,6 +271,24 @@ class ListEvents implements ListInterface, GroupedExportInterface } $qb->addSelect('location.name AS event_location'); break; + + case 'event_animators': + $qb->addSelect( + '(SELECT AGGREGATE(tp.id) FROM Chill\ThirdPartyBundle\Entity\ThirdParty tp WHERE tp MEMBER OF event.animators) AS event_animators' + ); + break; + + case 'event_themes': + $qb->addSelect( + '(SELECT AGGREGATE(t.id) FROM Chill\EventBundle\Entity\EventTheme t WHERE t MEMBER OF event.themes) AS event_themes' + ); + break; + + case 'event_budget_elements': + $qb->addSelect( + '(SELECT AGGREGATE(e.id) FROM Chill\EventBundle\Entity\EventBudgetElement e WHERE e.event = event.id) AS event_budget_elements' + ); + break; } } } diff --git a/src/Bundle/ChillEventBundle/Repository/EventBudgetElementRepository.php b/src/Bundle/ChillEventBundle/Repository/EventBudgetElementRepository.php new file mode 100644 index 000000000..3d700abba --- /dev/null +++ b/src/Bundle/ChillEventBundle/Repository/EventBudgetElementRepository.php @@ -0,0 +1,28 @@ + + */ +class EventBudgetElementRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, EventBudgetElement::class); + } + +}