mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add new columns to export list event
This commit is contained in:
parent
36a484c708
commit
7689fa254e
@ -16,7 +16,7 @@ use Doctrine\DBAL\Types\Types;
|
|||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[ORM\Entity]
|
#[ORM\Entity(repositoryClass: EventThemeRepository::class)]
|
||||||
#[ORM\Table(name: 'chill_event_budget_element')]
|
#[ORM\Table(name: 'chill_event_budget_element')]
|
||||||
class EventBudgetElement
|
class EventBudgetElement
|
||||||
{
|
{
|
||||||
|
@ -12,14 +12,17 @@ declare(strict_types=1);
|
|||||||
namespace Chill\EventBundle\Export\Export;
|
namespace Chill\EventBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\EventBundle\Entity\Event;
|
use Chill\EventBundle\Entity\Event;
|
||||||
|
use Chill\EventBundle\Entity\EventBudgetElement;
|
||||||
use Chill\EventBundle\Export\Declarations;
|
use Chill\EventBundle\Export\Declarations;
|
||||||
|
use Chill\EventBundle\Repository\EventBudgetElementRepository;
|
||||||
|
use Chill\EventBundle\Repository\EventThemeRepository;
|
||||||
use Chill\EventBundle\Security\EventVoter;
|
use Chill\EventBundle\Security\EventVoter;
|
||||||
|
use Chill\EventBundle\Templating\Entity\EventThemeRender;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\ListInterface;
|
use Chill\MainBundle\Export\ListInterface;
|
||||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
|
||||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
@ -42,6 +45,9 @@ class ListEvents implements ListInterface, GroupedExportInterface
|
|||||||
'event_moderator',
|
'event_moderator',
|
||||||
'event_participants_count',
|
'event_participants_count',
|
||||||
'event_location',
|
'event_location',
|
||||||
|
'event_budget_elements',
|
||||||
|
'event_animators',
|
||||||
|
'event_themes',
|
||||||
];
|
];
|
||||||
|
|
||||||
private readonly bool $filterStatsByCenters;
|
private readonly bool $filterStatsByCenters;
|
||||||
@ -50,6 +56,10 @@ class ListEvents implements ListInterface, GroupedExportInterface
|
|||||||
protected readonly EntityManagerInterface $entityManager,
|
protected readonly EntityManagerInterface $entityManager,
|
||||||
ParameterBagInterface $parameterBag,
|
ParameterBagInterface $parameterBag,
|
||||||
protected readonly TranslatableStringHelperInterface $translatableStringHelper,
|
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'];
|
$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];
|
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.';
|
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';
|
return 'Exports of events';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data): \Closure
|
||||||
{
|
{
|
||||||
switch ($key) {
|
return match ($key) {
|
||||||
case 'event_id':
|
'event_id' => fn ($value) => '_header' === $value ? 'ID' : $value,
|
||||||
return 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':
|
if ($value instanceof \DateTime) {
|
||||||
return fn ($value) => '_header' === $value ? 'Name' : $value;
|
return $value->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
case 'event_date':
|
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
||||||
return function ($value) {
|
|
||||||
if ('_header' === $value) {
|
|
||||||
return 'Date';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($value instanceof \DateTime) {
|
return $date ? $date->format('Y-m-d') : $value;
|
||||||
return $value->format('Y-m-d');
|
},
|
||||||
}
|
'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':
|
$ids = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
|
||||||
return function ($value) {
|
|
||||||
if ('_header' === $value) {
|
|
||||||
return 'event type';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize(json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR));
|
if (!is_array($ids)) {
|
||||||
};
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
case 'event_center':
|
$elements = $this->eventBudgetElementRepository->findBy(['id' => $ids]);
|
||||||
return fn ($value) => '_header' === $value ? 'Center' : $value;
|
|
||||||
|
|
||||||
case 'event_moderator':
|
return implode(
|
||||||
return fn ($value) => '_header' === $value ? 'Moderator' : $value;
|
' | ',
|
||||||
|
array_map(function ($element) {
|
||||||
|
$kindName = $this->translatableStringHelper->localize($element->getKind()->getName());
|
||||||
|
$amount = number_format($element->getAmount(), 2, '.', '');
|
||||||
|
|
||||||
case 'event_participants_count':
|
return sprintf('%s: %s€', $kindName, $amount);
|
||||||
return fn ($value) => '_header' === $value ? 'Participants Count' : $value;
|
}, $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':
|
if (null === $value) {
|
||||||
return fn ($value) => '_header' === $value ? 'Location' : $value;
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
return implode(
|
||||||
return fn ($value) => '_header' === $value ? $key : $value;
|
'|',
|
||||||
}
|
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)
|
public function getQueryKeys($data)
|
||||||
@ -232,6 +271,24 @@ class ListEvents implements ListInterface, GroupedExportInterface
|
|||||||
}
|
}
|
||||||
$qb->addSelect('location.name AS event_location');
|
$qb->addSelect('location.name AS event_location');
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\EventBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\EventBundle\Entity\EventBudgetElement;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<EventBudgetElement>
|
||||||
|
*/
|
||||||
|
class EventBudgetElementRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, EventBudgetElement::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user