From e78a6a58b0f6e711dbd02dddc67aea80f069e0b8 Mon Sep 17 00:00:00 2001 From: vgreb Date: Mon, 23 Nov 2026 20:03:03 +0100 Subject: [PATCH] =?UTF-8?q?=C3=89v=C3=A9nements:=20bascule=20des=20types?= =?UTF-8?q?=20de=20tarifs=20sur=20Doctrine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le modèle Ting TicketType servait encore aux tarifs d'évènement (TicketEventType::$ticketType), aux écrans admin des prix et aux requêtes d'inscriptions de TicketRepository. Le champ non mappé de TicketEventType porte maintenant l'entité Doctrine, renseignée par TicketTypeRepository::attachTo(), et les agrégats d'inscriptions sont complétés via Doctrine par enrichTicketAggregates(), comme les salles des sessions. Le modèle et le repository Ting des types de tarifs sont supprimés. La modification d'un prix dont le type de tarif n'existe pas renvoie maintenant une 404 au lieu d'une erreur 500. --- phpstan-baseline.php | 80 +----- .../Association/Form/TicketEventType.php | 2 +- .../Admin/Event/PricesAddAction.php | 6 +- .../Admin/Event/PricesEditAction.php | 11 +- .../Admin/Event/Ticket/IndexAction.php | 8 +- .../Controller/Event/Ticket/TicketAction.php | 2 +- .../Repository/TicketEventTypeRepository.php | 18 +- .../Repository/TicketTypeRepository.php | 68 +++++ .../Event/Entity/TicketEventType.php | 8 +- sources/AppBundle/Event/Form/TicketType.php | 18 +- sources/AppBundle/Event/JsonLd.php | 4 +- .../Model/Repository/TicketRepository.php | 21 +- .../Model/Repository/TicketTypeRepository.php | 88 ------ .../AppBundle/Event/Model/TicketAggregate.php | 5 +- sources/AppBundle/Event/Model/TicketType.php | 264 ------------------ .../Ticket/RegistrationsExportGenerator.php | 22 +- .../AppBundle/Event/Ticket/TicketOffers.php | 2 +- .../Event/Ticket/TicketTypeAvailability.php | 8 +- .../Constraints/CorporateMemberValidator.php | 2 +- .../Constraints/EarlyBirdTicketValidator.php | 2 +- .../Constraints/LoggedInMemberValidator.php | 2 +- .../Constraints/PublicTicketValidator.php | 2 +- .../TicketsCfpSubmitterValidator.php | 4 +- .../TicketEventTypeRepositoryTest.php | 4 +- .../Repository/TicketTypeRepositoryTest.php | 39 +++ 25 files changed, 192 insertions(+), 498 deletions(-) delete mode 100644 sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php delete mode 100644 sources/AppBundle/Event/Model/TicketType.php diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ef695058c1..3fd49b9ae2 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2192,17 +2192,11 @@ 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Event/PreviousRegistrationsAction.php', ]; $ignoreErrors[] = [ - 'message' => '#^Cannot call method getId\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', + 'message' => '#^Cannot access property \\$id on AppBundle\\\\Event\\\\Entity\\\\TicketType\\|null\\.$#', + 'identifier' => 'property.nonObject', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Event/PricesAddAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getId\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Event/PricesEditAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Method AppBundle\\\\Controller\\\\Admin\\\\Event\\\\RedirectEventFromSessionListener\\:\\:__construct\\(\\) has parameter \\$controllersWithEventSelector with no value type specified in iterable type array\\.$#', 'identifier' => 'missingType.iterableValue', @@ -4406,8 +4400,8 @@ 'path' => __DIR__ . '/sources/AppBundle/Event/Form/TicketInvoiceType.php', ]; $ignoreErrors[] = [ - 'message' => '#^Cannot call method getIsRestrictedToCfpSubmitter\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', + 'message' => '#^Cannot access property \\$isRestrictedToCfpSubmitter on AppBundle\\\\Event\\\\Entity\\\\TicketType\\|null\\.$#', + 'identifier' => 'property.nonObject', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Form/TicketType.php', ]; @@ -5395,18 +5389,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'aft\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'afto\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', -]; $ignoreErrors[] = [ 'message' => '#^Cannot access offset \'sold_tickets\' on mixed\\.$#', 'identifier' => 'offsetAccess.nonOffsetAccessible', @@ -5551,36 +5533,12 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$ticketType of class AppBundle\\\\Event\\\\Model\\\\TicketAggregate constructor expects AppBundle\\\\Event\\\\Model\\\\TicketType, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#3 \\$invoice of class AppBundle\\\\Event\\\\Model\\\\TicketAggregate constructor expects AppBundle\\\\Event\\\\Model\\\\Invoice\\|null, mixed given\\.$#', 'identifier' => 'argument.type', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketRepository.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TicketTypeRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#', - 'identifier' => 'missingType.iterableValue', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TicketTypeRepository\\:\\:initMetadata\\(\\) should return M of CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata but returns CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\\\.$#', - 'identifier' => 'return.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$databaseName of method CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\\\:\\:setDatabase\\(\\) expects string, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php', -]; $ignoreErrors[] = [ 'message' => '#^Property AppBundle\\\\Event\\\\Model\\\\Room\\:\\:\\$name \\(string\\) does not accept mixed\\.$#', 'identifier' => 'assign.propertyType', @@ -5665,18 +5623,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Ticket.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', - 'identifier' => 'foreach.nonIterable', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/TicketType.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\TicketType\\:\\:getDays\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/TicketType.php', -]; $ignoreErrors[] = [ 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', 'identifier' => 'foreach.nonIterable', @@ -6031,12 +5977,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php', -]; $ignoreErrors[] = [ 'message' => '#^Method AppBundle\\\\Event\\\\Validator\\\\Constraints\\\\AvailableTicketValidator\\:\\:validate\\(\\) has parameter \\$ticket with no type specified\\.$#', 'identifier' => 'missingType.parameter', @@ -6062,8 +6002,8 @@ 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php', ]; $ignoreErrors[] = [ - 'message' => '#^Cannot call method getIsRestrictedToMembers\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', + 'message' => '#^Cannot access property \\$isRestrictedToMembers on AppBundle\\\\Event\\\\Entity\\\\TicketType\\|null\\.$#', + 'identifier' => 'property.nonObject', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php', ]; @@ -6074,8 +6014,8 @@ 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php', ]; $ignoreErrors[] = [ - 'message' => '#^Cannot call method getIsRestrictedToMembers\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', + 'message' => '#^Cannot access property \\$isRestrictedToMembers on AppBundle\\\\Event\\\\Entity\\\\TicketType\\|null\\.$#', + 'identifier' => 'property.nonObject', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php', ]; @@ -6086,8 +6026,8 @@ 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php', ]; $ignoreErrors[] = [ - 'message' => '#^Cannot call method getIsRestrictedToMembers\\(\\) on AppBundle\\\\Event\\\\Model\\\\TicketType\\|null\\.$#', - 'identifier' => 'method.nonObject', + 'message' => '#^Cannot access property \\$isRestrictedToMembers on AppBundle\\\\Event\\\\Entity\\\\TicketType\\|null\\.$#', + 'identifier' => 'property.nonObject', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Validator/Constraints/PublicTicketValidator.php', ]; diff --git a/sources/AppBundle/Association/Form/TicketEventType.php b/sources/AppBundle/Association/Form/TicketEventType.php index c123d253fd..7ca48114ac 100644 --- a/sources/AppBundle/Association/Form/TicketEventType.php +++ b/sources/AppBundle/Association/Form/TicketEventType.php @@ -5,7 +5,7 @@ namespace AppBundle\Association\Form; use AppBundle\Event\Entity\TicketEventType as ModelTicketEventType; -use AppBundle\Event\Model\TicketType; +use AppBundle\Event\Entity\TicketType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; diff --git a/sources/AppBundle/Controller/Admin/Event/PricesAddAction.php b/sources/AppBundle/Controller/Admin/Event/PricesAddAction.php index eb3b3b2f26..3d7e9d84b6 100644 --- a/sources/AppBundle/Controller/Admin/Event/PricesAddAction.php +++ b/sources/AppBundle/Controller/Admin/Event/PricesAddAction.php @@ -8,7 +8,7 @@ use AppBundle\Event\AdminEventSelection; use AppBundle\Event\Entity\Repository\TicketEventTypeRepository; use AppBundle\Event\Entity\TicketEventType as ModelTicketEventType; -use AppBundle\Event\Model\Repository\TicketTypeRepository; +use AppBundle\Event\Entity\Repository\TicketTypeRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; @@ -33,7 +33,7 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection): $ticketEventType->dateStart = $event->getDateStart() ?? new \DateTime(); $ticketEventType->dateEnd = $event->getDateEnd() ?? new \DateTime(); - $ticketTypes = $this->ticketTypeRepository->getAll(); + $ticketTypes = $this->ticketTypeRepository->findAllOrderedById(); $form = $this->createForm(TicketEventType::class, $ticketEventType, [ 'ticketTypes' => $ticketTypes, 'has_prices_defined_with_vat' => $event->hasPricesDefinedWithVat(), @@ -41,7 +41,7 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection): $form->handleRequest($request); if ($form->isSubmitted()) { - $ticketEventType->ticketTypeId = $ticketEventType->ticketType->getId(); + $ticketEventType->ticketTypeId = $ticketEventType->ticketType->id; // Vérification maison d'unicité : la clé primaire est composée de (ticketTypeId, eventId) $existant = $this->ticketEventTypeRepository->findOneBy([ diff --git a/sources/AppBundle/Controller/Admin/Event/PricesEditAction.php b/sources/AppBundle/Controller/Admin/Event/PricesEditAction.php index b45003fd9f..68b16bb2bb 100644 --- a/sources/AppBundle/Controller/Admin/Event/PricesEditAction.php +++ b/sources/AppBundle/Controller/Admin/Event/PricesEditAction.php @@ -8,7 +8,7 @@ use AppBundle\Controller\Event\EventActionHelper; use AppBundle\Event\Form\EventSelectType; use AppBundle\Event\Entity\Repository\TicketEventTypeRepository; -use AppBundle\Event\Model\Repository\TicketTypeRepository; +use AppBundle\Event\Entity\Repository\TicketTypeRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; @@ -29,18 +29,21 @@ public function __construct( public function __invoke(Request $request, int $event, int $id): Response { $event = $this->eventActionHelper->getEventById($event); - $ticketType = $this->ticketTypeRepository->get($id); + $ticketType = $this->ticketTypeRepository->find($id); + if ($ticketType === null) { + throw new NotFoundHttpException(); + } $ticketEventType = $this->ticketEventTypeRepository->find([ 'eventId' => $event->getId(), - 'ticketTypeId' => $ticketType->getId(), + 'ticketTypeId' => $ticketType->id, ]); if ($ticketEventType === null) { throw new NotFoundHttpException(); } $ticketEventType->ticketType = $ticketType; - $ticketTypes = $this->ticketTypeRepository->getAll(); + $ticketTypes = $this->ticketTypeRepository->findAllOrderedById(); $form = $this->createForm(TicketEventType::class, $ticketEventType, [ 'ticketTypes' => $ticketTypes, 'has_prices_defined_with_vat' => $event->hasPricesDefinedWithVat(), diff --git a/sources/AppBundle/Controller/Admin/Event/Ticket/IndexAction.php b/sources/AppBundle/Controller/Admin/Event/Ticket/IndexAction.php index edfa938293..2e169ff9af 100644 --- a/sources/AppBundle/Controller/Admin/Event/Ticket/IndexAction.php +++ b/sources/AppBundle/Controller/Admin/Event/Ticket/IndexAction.php @@ -7,6 +7,7 @@ use AppBundle\Event\AdminEventSelection; use AppBundle\Event\Entity\Repository\BilleteriePriveeRepository; use AppBundle\Event\Entity\Repository\TicketSpecialPriceRepository; +use AppBundle\Event\Entity\Repository\TicketTypeRepository; use AppBundle\Event\Model\Event; use AppBundle\Event\Model\EventStats; use AppBundle\Event\Model\Repository\EventStatsRepository; @@ -35,6 +36,7 @@ public function __construct( private readonly BilleteriePriveeRepository $billeteriePriveeRepository, private readonly TicketSpecialPriceRepository $ticketSpecialPriceRepository, private readonly FormFactoryInterface $formFactory, + private readonly TicketTypeRepository $ticketTypeRepository, ) {} public function __invoke(Request $request, AdminEventSelection $eventSelection): Response @@ -54,12 +56,12 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection): $data['sort_direction'] ??= 'desc'; $statistics = $this->eventStatsRepository->getStats($event->getId()); - $tickets = $this->ticketRepository->getByEventWithAll( + $tickets = $this->ticketTypeRepository->enrichTicketAggregates($this->ticketRepository->getByEventWithAll( event: $event, search: $data['filter'] ?? null, sortKey: $data['sort_key'], sortDirection: $data['sort_direction'], - ); + )); $computed = $this->computeStatistics($statistics, $event); $specialPriceLabels = $this->getSpecialPriceLabels($tickets); @@ -87,7 +89,7 @@ private function getSpecialPriceLabels(array $tickets): array $tokens = []; foreach ($tickets as $aggregate) { if ( - $aggregate->ticketType->getId() === Ticket::TYPE_SPECIAL_PRICE + $aggregate->ticketType?->id === Ticket::TYPE_SPECIAL_PRICE && $aggregate->ticket->getSpecialPriceToken() !== null ) { $tokens[] = $aggregate->ticket->getSpecialPriceToken(); diff --git a/sources/AppBundle/Controller/Event/Ticket/TicketAction.php b/sources/AppBundle/Controller/Event/Ticket/TicketAction.php index 85f9bb8d54..0b012a8493 100644 --- a/sources/AppBundle/Controller/Event/Ticket/TicketAction.php +++ b/sources/AppBundle/Controller/Event/Ticket/TicketAction.php @@ -97,7 +97,7 @@ public function __invoke($eventSlug, Request $request): Response foreach ($tickets as $ticket) { if ($ticket->getTicketEventType()?->ticketType !== null - && $ticket->getTicketEventType()->ticketType->getIsRestrictedToMembers() + && $ticket->getTicketEventType()->ticketType->isRestrictedToMembers && isset($memberId, $memberType)) { $ticket ->setMemberId($memberId) diff --git a/sources/AppBundle/Event/Entity/Repository/TicketEventTypeRepository.php b/sources/AppBundle/Event/Entity/Repository/TicketEventTypeRepository.php index e9b2c8dace..d4ac805fde 100644 --- a/sources/AppBundle/Event/Entity/Repository/TicketEventTypeRepository.php +++ b/sources/AppBundle/Event/Entity/Repository/TicketEventTypeRepository.php @@ -7,7 +7,7 @@ use AppBundle\Doctrine\EntityRepository; use AppBundle\Event\Entity\TicketEventType; use AppBundle\Event\Model\Event; -use AppBundle\Event\Model\Repository\TicketTypeRepository; +use AppBundle\Event\Entity\TicketType; use Doctrine\Persistence\ManagerRegistry; /** @@ -19,10 +19,8 @@ final class TicketEventTypeRepository extends EntityRepository public const int REMOVE_FUTURE_TICKETS = 2; public const int ACTUAL_TICKETS_ONLY = 3; // Combinaison de REMOVE_PAST_TICKETS et REMOVE_FUTURE_TICKETS - public function __construct( - ManagerRegistry $registry, - private readonly TicketTypeRepository $ticketTypeRepository, - ) { + public function __construct(ManagerRegistry $registry) + { parent::__construct($registry, TicketEventType::class); } @@ -58,11 +56,6 @@ public function getTicketsByEvent(Event $event, bool $publicOnly = true, ?int $d ->addOrderBy('tarif_event.price') ->addOrderBy('tarif.members_only', 'DESC'); - $ticketTypes = []; - foreach ($this->ticketTypeRepository->getAll() as $ticketType) { - $ticketTypes[$ticketType->getId()] = $ticketType; - } - $ticketEventTypes = []; foreach ($queryBuilder->executeQuery()->fetchAllAssociative() as $row) { if (!isset($row['id_tarif'], $row['id_event']) @@ -78,10 +71,11 @@ public function getTicketsByEvent(Event $event, bool $publicOnly = true, ?int $d if ($ticketEventType === null) { continue; } - $ticketEventType->ticketType = $ticketTypes[$ticketEventType->ticketTypeId] ?? null; $ticketEventTypes[] = $ticketEventType; } + $this->getEntityManager()->getRepository(TicketType::class)->attachTo($ticketEventTypes); + return $ticketEventTypes; } @@ -91,7 +85,7 @@ public function getTicketsByEvent(Event $event, bool $publicOnly = true, ?int $d public function doesEventHasRestrictedToMembersTickets(Event $event, bool $publicOnly = true, ?int $datesFilter = null): bool { foreach ($this->getTicketsByEvent($event, $publicOnly, $datesFilter) as $ticketEventType) { - if ($ticketEventType->ticketType?->getIsRestrictedToMembers() === true) { + if ($ticketEventType->ticketType?->isRestrictedToMembers === true) { return true; } } diff --git a/sources/AppBundle/Event/Entity/Repository/TicketTypeRepository.php b/sources/AppBundle/Event/Entity/Repository/TicketTypeRepository.php index 2eef022302..5929c9a932 100644 --- a/sources/AppBundle/Event/Entity/Repository/TicketTypeRepository.php +++ b/sources/AppBundle/Event/Entity/Repository/TicketTypeRepository.php @@ -5,7 +5,9 @@ namespace AppBundle\Event\Entity\Repository; use AppBundle\Doctrine\EntityRepository; +use AppBundle\Event\Entity\TicketEventType; use AppBundle\Event\Entity\TicketType; +use AppBundle\Event\Model\TicketAggregate; use Doctrine\Persistence\ManagerRegistry; /** @@ -28,4 +30,70 @@ public function findAllOrderedById(): array return $ticketTypes; } + + /** + * @param list $ids + * + * @return array + */ + public function findIndexedByIds(array $ids): array + { + if ($ids === []) { + return []; + } + + $ticketTypes = []; + foreach ($this->findBy(['id' => array_values(array_unique($ids))]) as $ticketType) { + $ticketTypes[$ticketType->id] = $ticketType; + } + + return $ticketTypes; + } + + /** + * Renseigne le type de tarif (champ non mappé) de chacun des tarifs d'évènement. + * + * @param iterable $ticketEventTypes + */ + public function attachTo(iterable $ticketEventTypes): void + { + $ticketEventTypes = is_array($ticketEventTypes) ? $ticketEventTypes : iterator_to_array($ticketEventTypes, false); + + $ticketTypes = $this->findIndexedByIds(array_values(array_map( + static fn(TicketEventType $ticketEventType): int => $ticketEventType->ticketTypeId, + $ticketEventTypes, + ))); + + foreach ($ticketEventTypes as $ticketEventType) { + $ticketEventType->ticketType = $ticketTypes[$ticketEventType->ticketTypeId] ?? null; + } + } + + /** + * Complète les agrégats d'inscriptions produits par TicketRepository (Ting) avec + * le type de tarif de chaque inscription, rechargé via Doctrine. + * + * @param array $ticketAggregates + * + * @return list + */ + public function enrichTicketAggregates(array $ticketAggregates): array + { + $ticketTypes = $this->findIndexedByIds(array_values(array_map( + static fn(TicketAggregate $ticketAggregate): int => (int) $ticketAggregate->ticket->getTicketTypeId(), + $ticketAggregates, + ))); + + $enriched = []; + foreach ($ticketAggregates as $ticketAggregate) { + $enriched[] = new TicketAggregate( + $ticketAggregate->ticket, + $ticketTypes[(int) $ticketAggregate->ticket->getTicketTypeId()] ?? null, + $ticketAggregate->invoice, + $ticketAggregate->lastSubscription, + ); + } + + return $enriched; + } } diff --git a/sources/AppBundle/Event/Entity/TicketEventType.php b/sources/AppBundle/Event/Entity/TicketEventType.php index bd1c798736..ba7be48966 100644 --- a/sources/AppBundle/Event/Entity/TicketEventType.php +++ b/sources/AppBundle/Event/Entity/TicketEventType.php @@ -5,7 +5,6 @@ namespace AppBundle\Event\Entity; use AppBundle\Event\Entity\Repository\TicketEventTypeRepository; -use AppBundle\Event\Model\TicketType; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: TicketEventTypeRepository::class)] @@ -35,11 +34,6 @@ class TicketEventType #[ORM\Column(name: 'max_tickets', nullable: true)] public ?int $maxTickets = null; - // Type de ticket associé, encore géré par Ting : champ non mappé, hydraté manuellement + // Type de tarif associé : champ non mappé, renseigné par TicketTypeRepository::attachTo() public ?TicketType $ticketType = null; - - public function setTicketType(?TicketType $ticketType): void - { - $this->ticketType = $ticketType; - } } diff --git a/sources/AppBundle/Event/Form/TicketType.php b/sources/AppBundle/Event/Form/TicketType.php index e88e819002..841a4ac745 100644 --- a/sources/AppBundle/Event/Form/TicketType.php +++ b/sources/AppBundle/Event/Form/TicketType.php @@ -11,7 +11,6 @@ use AppBundle\Event\Model\Repository\EventRepository; use AppBundle\Event\Entity\Repository\TicketEventTypeRepository; use AppBundle\Event\Entity\Repository\TicketSpecialPriceRepository; -use AppBundle\Event\Model\Repository\TicketTypeRepository as TingTicketTypeRepository; use AppBundle\Event\Model\Ticket; use AppBundle\Event\Entity\TicketEventType; use AppBundle\Event\Entity\TicketSpecialPrice; @@ -41,7 +40,6 @@ public function __construct( private readonly TicketTypeAvailability $ticketTypeAvailability, private readonly TicketSpecialPriceRepository $ticketSpecialPriceRepository, private readonly TicketTypeRepository $ticketTypeRepository, - private readonly TingTicketTypeRepository $tingTicketTypeRepository, private readonly AntenneRepository $antenneRepository, ) {} @@ -91,7 +89,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $formEvent) use ($eventTickets, $options, $event): void { $filteredEventTickets = []; foreach ($eventTickets as $eventTicket) { - if ($eventTicket->ticketType->getIsRestrictedToCfpSubmitter() && !$options['is_cfp_submitter']) { + if ($eventTicket->ticketType->isRestrictedToCfpSubmitter && !$options['is_cfp_submitter']) { continue; } $filteredEventTickets[] = $eventTicket; @@ -135,13 +133,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]; if ($type->ticketType !== null) { - $attr['data-members-only'] = (int) $type->ticketType->getIsRestrictedToMembers(); + $attr['data-members-only'] = (int) $type->ticketType->isRestrictedToMembers; $attr['data-stock'] = $this->ticketTypeAvailability->getStock($type, $event); - $attr['data-label'] = $type->ticketType->getPrettyName(); + $attr['data-label'] = $type->ticketType->prettyName; } if ( - ($type->ticketType?->getIsRestrictedToMembers() === true && $options['member_type'] === self::MEMBER_NOT) + ($type->ticketType?->isRestrictedToMembers === true && $options['member_type'] === self::MEMBER_NOT) || (isset($attr['data-stock']) && $attr['data-stock'] <= 0) ) { $attr['disabled'] = 'disabled'; @@ -196,8 +194,8 @@ public function configureOptions(OptionsResolver $resolver): void */ private function createSpecialPriceTicketEventType(TicketSpecialPrice $ticketSpecialPrice, array $filteredEventTickets): array { - $ticketType = $this->tingTicketTypeRepository->get(Ticket::TYPE_SPECIAL_PRICE); - if (!$ticketType instanceof \AppBundle\Event\Model\TicketType) { + $ticketType = $this->ticketTypeRepository->find(Ticket::TYPE_SPECIAL_PRICE); + if ($ticketType === null) { return $filteredEventTickets; } @@ -218,8 +216,8 @@ private function createSpecialPriceTicketEventType(TicketSpecialPrice $ticketSpe */ private function createBilleteriePriveeTicketEventType(BilleteriePrivee $billeteriePrivee, array $filteredEventTickets): array { - $ticketType = $this->tingTicketTypeRepository->get(Ticket::TYPE_SPECIAL_PRICE); - if (!$ticketType instanceof \AppBundle\Event\Model\TicketType) { + $ticketType = $this->ticketTypeRepository->find(Ticket::TYPE_SPECIAL_PRICE); + if ($ticketType === null) { return $filteredEventTickets; } diff --git a/sources/AppBundle/Event/JsonLd.php b/sources/AppBundle/Event/JsonLd.php index 66f0a38785..4dea9ee481 100644 --- a/sources/AppBundle/Event/JsonLd.php +++ b/sources/AppBundle/Event/JsonLd.php @@ -97,8 +97,8 @@ public function getDataForEvent(Event $event): array foreach ($eventTickets as $eventTicket) { $offers[] = [ '@type' => 'Offer', - 'name' => $eventTicket->ticketType?->getPrettyName(), - 'sku' => $eventTicket->ticketType?->getTechnicalName(), + 'name' => $eventTicket->ticketType?->prettyName, + 'sku' => $eventTicket->ticketType?->technicalName, 'priceCurrency' => 'EUR', 'price' => $eventTicket->price, 'validFrom' => $eventTicket->dateStart->format('c'), diff --git a/sources/AppBundle/Event/Model/Repository/TicketRepository.php b/sources/AppBundle/Event/Model/Repository/TicketRepository.php index bbbb0b00db..256de780f5 100644 --- a/sources/AppBundle/Event/Model/Repository/TicketRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TicketRepository.php @@ -9,7 +9,7 @@ use AppBundle\Event\Model\Invoice; use AppBundle\Event\Model\Ticket; use AppBundle\Event\Model\TicketAggregate; -use AppBundle\Event\Model\TicketType; +use AppBundle\Event\Entity\TicketType; use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean; use CCMBenchmark\Ting\Query\QueryException; use CCMBenchmark\Ting\Repository\CollectionInterface; @@ -110,8 +110,9 @@ public function getWithTicketTypeByReference(string $reference): array public function getByInvoiceWithDetail(Invoice $invoice) { - // Les tarifs sont hydratés par Ting via un JOIN : l'entité Doctrine - // TicketEventType est ré-attachée au ticket (TicketEventTypeHydrationRepository) + // Le tarif d'évènement est hydraté par Ting via un JOIN : l'entité Doctrine + // TicketEventType est ré-attachée au ticket (TicketEventTypeHydrationRepository). + // Son type de tarif n'est pas chargé. return $this->getPreparedQuery( 'SELECT inscriptions.id, inscriptions.date, inscriptions.reference, inscriptions.coupon, inscriptions.type_inscription, @@ -119,17 +120,14 @@ public function getByInvoiceWithDetail(Invoice $invoice) inscriptions.email, inscriptions.telephone, inscriptions.citer_societe, inscriptions.newsletter_afup, inscriptions.newsletter_nexen, inscriptions.commentaires, inscriptions.etat, inscriptions.facturation, inscriptions.id_forum, inscriptions.mail_partenaire, inscriptions.presence_day1, inscriptions.presence_day2, - tarif_event.id_tarif, tarif_event.id_event, tarif_event.price, tarif_event.date_start, tarif_event.date_end, tarif_event.description, tarif_event.max_tickets, - tarif.id, tarif.technical_name, tarif.day, tarif.pretty_name, tarif.public, tarif.members_only, tarif.default_price, tarif.active, tarif.cfp_submitter_only + tarif_event.id_tarif, tarif_event.id_event, tarif_event.price, tarif_event.date_start, tarif_event.date_end, tarif_event.description, tarif_event.max_tickets FROM afup_inscription_forum inscriptions JOIN afup_forum_tarif_event tarif_event ON tarif_event.id_tarif = inscriptions.type_inscription AND tarif_event.id_event = inscriptions.id_forum - JOIN afup_forum_tarif tarif ON tarif.id = tarif_event.id_tarif WHERE inscriptions.reference = :ref ', )->setParams(['ref' => $invoice->getReference()])->query( $this->getCollection( new HydratorSingleObject() - ->mapObjectTo('tarif', 'tarif_event', 'setTicketType') ->mapObjectTo('tarif_event', 'inscriptions', 'setTicketEventType'), ), ); @@ -167,7 +165,7 @@ public function getPublicSoldTicketsByDayOfType(Event $event, $day = null, ?Tick if ($ticketType instanceof TicketType) { $sql .= ' AND aif.type_inscription = :ticket_type_id'; - $params['ticket_type_id'] = $ticketType->getId(); + $params['ticket_type_id'] = $ticketType->id; } $tickets = $this->getPreparedQuery($sql) @@ -208,7 +206,9 @@ public function getByEvent(Event $event): CollectionInterface */ public function getByEventWithAll(Event $event, ?string $search, ?string $sortKey, ?string $sortDirection): array { - $sql = 'SELECT ticket.*, aff.*, aft.*, afto.*, + // Le type de tarif n'est plus hydraté par Ting : il est rechargé via Doctrine + // avec TicketTypeRepository::enrichTicketAggregates(). + $sql = 'SELECT ticket.*, aff.*, CASE WHEN ticket.id_member IS NOT NULL THEN (SELECT MAX(ac.date_fin) AS last_subscription FROM afup_cotisations ac @@ -224,7 +224,6 @@ public function getByEventWithAll(Event $event, ?string $search, ?string $sortKe LEFT JOIN afup_facturation_forum aff ON ticket.reference = aff.reference LEFT JOIN afup_forum_tarif_event afte ON afte.id_tarif = ticket.type_inscription AND afte.id_event = ticket.id_forum LEFT JOIN afup_forum_tarif aft ON aft.id = afte.id_tarif - LEFT JOIN afup_forum_tarif afto ON afto.id = ticket.type_inscription WHERE %s ORDER BY %s'; @@ -256,7 +255,7 @@ public function getByEventWithAll(Event $event, ?string $search, ?string $sortKe foreach ($result as $row) { $aggregates[] = new TicketAggregate( $row['ticket'], - $row['aft'] ?? $row['afto'], + null, $row['aff'], $row[0]->last_subscription ? new \DateTimeImmutable('@' . $row[0]->last_subscription) : null, ); diff --git a/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php b/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php deleted file mode 100644 index 2735ad5b63..0000000000 --- a/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php +++ /dev/null @@ -1,88 +0,0 @@ - - */ -class TicketTypeRepository extends Repository implements MetadataInitializer -{ - /** - * @inheritDoc - */ - public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = []) - { - $metadata = new Metadata($serializerFactory); - - $metadata->setEntity(TicketType::class); - $metadata->setConnectionName('main'); - $metadata->setDatabase($options['database']); - $metadata->setTable('afup_forum_tarif'); - - $metadata - ->addField([ - 'columnName' => 'id', - 'fieldName' => 'id', - 'primary' => true, - 'autoincrement' => true, - 'type' => 'int', - ]) - ->addField([ - 'columnName' => 'technical_name', - 'fieldName' => 'technicalName', - 'type' => 'string', - ]) - - ->addField([ - 'columnName' => 'pretty_name', - 'fieldName' => 'prettyName', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'public', - 'fieldName' => 'isPublic', - 'type' => 'bool', - 'serializer' => Boolean::class, - ]) - ->addField([ - 'columnName' => 'members_only', - 'fieldName' => 'isRestrictedToMembers', - 'type' => 'bool', - 'serializer' => Boolean::class, - ]) - ->addField([ - 'columnName' => 'cfp_submitter_only', - 'fieldName' => 'isRestrictedToCfpSubmitter', - 'type' => 'bool', - 'serializer' => Boolean::class, - ]) - ->addField([ - 'columnName' => 'default_price', - 'fieldName' => 'defaultPrice', - 'type' => 'float', - ]) - ->addField([ - 'columnName' => 'active', - 'fieldName' => 'isActive', - 'type' => 'bool', - 'serializer' => Boolean::class, - ]) - ->addField([ - 'columnName' => 'day', - 'fieldName' => 'day', - 'type' => 'string', - ]) - ; - - return $metadata; - } -} diff --git a/sources/AppBundle/Event/Model/TicketAggregate.php b/sources/AppBundle/Event/Model/TicketAggregate.php index f9c36f19df..d5dbada005 100644 --- a/sources/AppBundle/Event/Model/TicketAggregate.php +++ b/sources/AppBundle/Event/Model/TicketAggregate.php @@ -4,11 +4,14 @@ namespace AppBundle\Event\Model; +use AppBundle\Event\Entity\TicketType; + final readonly class TicketAggregate { public function __construct( public Ticket $ticket, - public TicketType $ticketType, + // Renseigné via Doctrine par TicketTypeRepository::enrichTicketAggregates() + public ?TicketType $ticketType, public ?Invoice $invoice, public ?\DateTimeImmutable $lastSubscription, ) {} diff --git a/sources/AppBundle/Event/Model/TicketType.php b/sources/AppBundle/Event/Model/TicketType.php deleted file mode 100644 index a4b1182dc4..0000000000 --- a/sources/AppBundle/Event/Model/TicketType.php +++ /dev/null @@ -1,264 +0,0 @@ -getTechnicalName(), - $this->getPrettyName(), - $this->getIsRestrictedToMembers() ? ' - (réservé aux membres)' : '', - $this->getPrettyDays(), - ); - } - - public function isEarly(): bool - { - return in_array($this->technicalName, self::EARLY_BIRD_TECHNICAL_NAME); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $id - */ - public function setId($id): self - { - $this->propertyChanged('id', $this->id, $id); - $this->id = $id; - return $this; - } - - /** - * @return string - */ - public function getTechnicalName() - { - return $this->technicalName; - } - - /** - * @param string $technicalName - */ - public function setTechnicalName($technicalName): self - { - $this->propertyChanged('technicalName', $this->technicalName, $technicalName); - $this->technicalName = $technicalName; - return $this; - } - - /** - * @return string - */ - public function getPrettyName() - { - return $this->prettyName; - } - - /** - * @param string $prettyName - */ - public function setPrettyName($prettyName): self - { - $this->propertyChanged('prettyName', $this->prettyName, $prettyName); - $this->prettyName = $prettyName; - return $this; - } - - /** - * @return bool - */ - public function getIsPublic() - { - return $this->isPublic; - } - - /** - * @param bool $isPublic - */ - public function setIsPublic($isPublic): self - { - $this->propertyChanged('isPublic', $this->isPublic, $isPublic); - $this->isPublic = $isPublic; - return $this; - } - - /** - * @return bool - */ - public function getIsRestrictedToMembers() - { - return $this->isRestrictedToMembers; - } - - /** - * @param bool $isRestrictedToMembers - */ - public function setIsRestrictedToMembers($isRestrictedToMembers): self - { - $this->propertyChanged('isRestrictedToMembers', $this->isRestrictedToMembers, $isRestrictedToMembers); - $this->isRestrictedToMembers = $isRestrictedToMembers; - return $this; - } - - /** - * @return bool - */ - public function getIsRestrictedToCfpSubmitter() - { - return $this->isRestrictedToCfpSubmitter; - } - - /** - * @param bool $isRestrictedToCfpSubmitter - */ - public function setIsRestrictedToCfpSubmitter($isRestrictedToCfpSubmitter): self - { - $this->propertyChanged('isRestrictedToCfpSubmitter', $this->isRestrictedToCfpSubmitter, $isRestrictedToCfpSubmitter); - $this->isRestrictedToCfpSubmitter = $isRestrictedToCfpSubmitter; - return $this; - } - - /** - * @return float - */ - public function getDefaultPrice() - { - return $this->defaultPrice; - } - - /** - * @param float $defaultPrice - */ - public function setDefaultPrice($defaultPrice): self - { - $this->propertyChanged('defaultPrice', $this->defaultPrice, $defaultPrice); - $this->defaultPrice = $defaultPrice; - return $this; - } - - /** - * @return bool - */ - public function getIsActive() - { - return $this->isActive; - } - - /** - * @param bool $isActive - */ - public function setIsActive($isActive): self - { - $this->propertyChanged('isActive', $this->isActive, $isActive); - $this->isActive = $isActive; - return $this; - } - - /** - * @return string - */ - public function getDay() - { - return $this->day; - } - - /** - * @param string $day - */ - public function setDay($day): self - { - $this->propertyChanged('day', $this->day, $day); - $this->day = $day; - return $this; - } - - public function getDays() - { - return explode(',', $this->day); - } - - public function getPrettyDays(): string - { - $days = []; - foreach ($this->getDays() as $day) { - switch ($day) { - case Ticket::DAY_ONE: - $days[] = 'JOUR 1'; - break; - case Ticket::DAY_TWO: - $days[] = 'JOUR 2'; - break; - default: - break; - } - } - - return implode(', ', $days); - } -} diff --git a/sources/AppBundle/Event/Ticket/RegistrationsExportGenerator.php b/sources/AppBundle/Event/Ticket/RegistrationsExportGenerator.php index 2fe08e4c44..b91a5acf83 100644 --- a/sources/AppBundle/Event/Ticket/RegistrationsExportGenerator.php +++ b/sources/AppBundle/Event/Ticket/RegistrationsExportGenerator.php @@ -7,12 +7,13 @@ use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; use AppBundle\Association\UserMembership\SeniorityComputer; +use AppBundle\Event\Entity\Repository\TicketTypeRepository; use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Invoice; use AppBundle\Event\Model\Repository\InvoiceRepository; use AppBundle\Event\Model\Repository\TicketRepository; use AppBundle\Event\Model\Ticket; -use AppBundle\Event\Model\TicketType; +use AppBundle\Event\Entity\TicketType; use AppBundle\Offices\OfficeFinder; use Symfony\Component\Security\Core\Exception\UserNotFoundException; @@ -24,6 +25,7 @@ public function __construct( private TicketRepository $ticketRepository, private InvoiceRepository $invoiceRepository, private UserRepository $userRepository, + private TicketTypeRepository $ticketTypeRepository, ) {} public function export(Event $event, \SplFileObject $toFile): void @@ -58,12 +60,12 @@ public function export(Event $event, \SplFileObject $toFile): void protected function getFromRegistrationsOnEvent(Event $event): \Generator { - $aggregates = $this->ticketRepository->getByEventWithAll( + $aggregates = $this->ticketTypeRepository->enrichTicketAggregates($this->ticketRepository->getByEventWithAll( event: $event, search: null, sortKey: 'date', sortDirection: 'desc', - ); + )); foreach ($aggregates as $aggregate) { $ticket = $aggregate->ticket; @@ -132,9 +134,13 @@ private function computeSeniority(User $user): int return $this->seniorityComputer->compute($user); } - private function getTypePass(TicketType $ticketType): string + private function getTypePass(?TicketType $ticketType): string { - $typePass = match ($ticketType->getId()) { + if ($ticketType === null) { + throw new \RuntimeException('Type de tarif de l\'inscription non trouvé'); + } + + $typePass = match ($ticketType->id) { Ticket::TYPE_ORGANIZATION => 'ORGANISATION', Ticket::TYPE_PRESS => 'PRESSE', Ticket::TYPE_SPEAKER => 'CONFERENCIER', @@ -145,13 +151,13 @@ private function getTypePass(TicketType $ticketType): string return $typePass; } - if ($ticketType->getDay() === 'one') { + if ($ticketType->day === 'one') { return 'PASS JOUR 1'; } - if ($ticketType->getDay() === 'two') { + if ($ticketType->day === 'two') { return 'PASS JOUR 2'; } - if ($ticketType->getDay() === 'one,two') { + if ($ticketType->day === 'one,two') { return 'PASS 2 JOURS'; } diff --git a/sources/AppBundle/Event/Ticket/TicketOffers.php b/sources/AppBundle/Event/Ticket/TicketOffers.php index 5e83b69e51..4df3941c0d 100644 --- a/sources/AppBundle/Event/Ticket/TicketOffers.php +++ b/sources/AppBundle/Event/Ticket/TicketOffers.php @@ -38,7 +38,7 @@ public function getAllOffersForEvent(Event $event): array $ticketTypeId = $ticketEventType->ticketTypeId; $offers[$ticketTypeId] = new TicketOffer( $ticketTypeId, - $ticketEventType->ticketType?->getPrettyName() ?? '', + $ticketEventType->ticketType->prettyName ?? '', $ticketEventType->price ?? 0.0, $this->ticketTypeAvailability->getStock($ticketEventType, $event), $event, diff --git a/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php b/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php index 1b9b3edd9a..e3d6ddb406 100644 --- a/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php +++ b/sources/AppBundle/Event/Ticket/TicketTypeAvailability.php @@ -7,7 +7,7 @@ use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Repository\TicketRepository; use AppBundle\Event\Entity\TicketEventType; -use AppBundle\Event\Model\TicketType; +use AppBundle\Event\Entity\TicketType; class TicketTypeAvailability { @@ -20,7 +20,7 @@ public function __construct(private readonly TicketRepository $ticketRepository) public function getStock(TicketEventType $ticketEventType, Event $event): int { // Les tickets depuis les tokens doivent fonctionner même après le sold out - if ($ticketEventType->ticketType !== null && $ticketEventType->ticketType->getTechnicalName() == TicketType::SPECIAL_PRICE_TECHNICAL_NAME) { + if ($ticketEventType->ticketType !== null && $ticketEventType->ticketType->technicalName == TicketType::SPECIAL_PRICE_TECHNICAL_NAME) { return PHP_INT_MAX; } @@ -34,8 +34,8 @@ public function getStock(TicketEventType $ticketEventType, Event $event): int $allTickets = $this->ticketRepository->getPublicSoldTickets($event); $typeTickets = $this->ticketRepository->getPublicSoldTicketsOfType($event, $ticketType); } else { - $allTickets = $this->ticketRepository->getPublicSoldTicketsByDay($ticketType->getDay(), $event); - $typeTickets = $this->ticketRepository->getPublicSoldTicketsByDayOfType($event, $ticketType->getDay(), $ticketType); + $allTickets = $this->ticketRepository->getPublicSoldTicketsByDay($ticketType->day, $event); + $typeTickets = $this->ticketRepository->getPublicSoldTicketsByDayOfType($event, $ticketType->day, $ticketType); } // on regarde combien de tickets il nous reste diff --git a/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php b/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php index e9447d3d02..1aa2a04a4f 100644 --- a/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php @@ -33,7 +33,7 @@ public function validate($tickets, Constraint $constraint): void $eventId = null; foreach ($tickets as $ticket) { - if (!($ticket instanceof Ticket) || !$ticket->getTicketEventType() instanceof TicketEventType || $ticket->getTicketEventType()->ticketType->getIsRestrictedToMembers() === false) { + if (!($ticket instanceof Ticket) || !$ticket->getTicketEventType() instanceof TicketEventType || $ticket->getTicketEventType()->ticketType->isRestrictedToMembers === false) { continue; } if ($eventId === null) { diff --git a/sources/AppBundle/Event/Validator/Constraints/EarlyBirdTicketValidator.php b/sources/AppBundle/Event/Validator/Constraints/EarlyBirdTicketValidator.php index c8b4744043..cb8ae58374 100644 --- a/sources/AppBundle/Event/Validator/Constraints/EarlyBirdTicketValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/EarlyBirdTicketValidator.php @@ -30,7 +30,7 @@ public function validate($value, Constraint $constraint): void // On autorise qu'un seul ticket if ($count > 1) { $this->context->buildViolation($constraint->message) - ->setParameter('{{ ticket_pretty_name }}', $ticket->getTicketEventType()->ticketType->getPrettyName()) + ->setParameter('{{ ticket_pretty_name }}', $ticket->getTicketEventType()->ticketType->prettyName) ->atPath('[' . $index . '].ticketEventType') ->addViolation() ; diff --git a/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php b/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php index 677caa4d74..3f48872413 100644 --- a/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/LoggedInMemberValidator.php @@ -22,7 +22,7 @@ public function validate($ticket, Constraint $constraint): void throw new UnexpectedTypeException($constraint, LoggedInMember::class); } - if (!($ticket instanceof Ticket) || !$ticket->getTicketEventType() instanceof TicketEventType || $ticket->getTicketEventType()->ticketType->getIsRestrictedToMembers() === false) { + if (!($ticket instanceof Ticket) || !$ticket->getTicketEventType() instanceof TicketEventType || $ticket->getTicketEventType()->ticketType->isRestrictedToMembers === false) { return ; } diff --git a/sources/AppBundle/Event/Validator/Constraints/PublicTicketValidator.php b/sources/AppBundle/Event/Validator/Constraints/PublicTicketValidator.php index 9772f9347d..abe861f3e3 100644 --- a/sources/AppBundle/Event/Validator/Constraints/PublicTicketValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/PublicTicketValidator.php @@ -22,7 +22,7 @@ public function validate($ticket, Constraint $constraint): void return ; } - if ($ticket->getTicketEventType()->ticketType->getIsRestrictedToMembers() === true) { + if ($ticket->getTicketEventType()->ticketType->isRestrictedToMembers === true) { $this->context->buildViolation($constraint->messageNotLoggedIn) ->atPath('email') ->addViolation(); diff --git a/sources/AppBundle/Event/Validator/Constraints/TicketsCfpSubmitterValidator.php b/sources/AppBundle/Event/Validator/Constraints/TicketsCfpSubmitterValidator.php index 3d36433eab..08b3cbb045 100644 --- a/sources/AppBundle/Event/Validator/Constraints/TicketsCfpSubmitterValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/TicketsCfpSubmitterValidator.php @@ -20,13 +20,13 @@ public function validate($value, Constraint $constraint): void foreach ($value as $index => $ticket) { if ($ticket->getTicketEventType()?->ticketType !== null - && $ticket->getTicketEventType()->ticketType->getIsRestrictedToCfpSubmitter()) { + && $ticket->getTicketEventType()->ticketType->isRestrictedToCfpSubmitter) { $specialCFPSubmitter++; // On autorise qu'un seul ticket au tarif CFP submitter if ($specialCFPSubmitter > 1) { $this->context->buildViolation($constraint->messageTooMuchCfpSubmitterTickets) - ->setParameter('{{ ticket_pretty_name }}', $ticket->getTicketEventType()->ticketType->getPrettyName()) + ->setParameter('{{ ticket_pretty_name }}', $ticket->getTicketEventType()->ticketType->prettyName) ->atPath('[' . $index . '].ticketEventType') ->addViolation() ; diff --git a/tests/integration/AppBundle/Event/Entity/Repository/TicketEventTypeRepositoryTest.php b/tests/integration/AppBundle/Event/Entity/Repository/TicketEventTypeRepositoryTest.php index 3da9ba1f25..2fe9e5eda2 100644 --- a/tests/integration/AppBundle/Event/Entity/Repository/TicketEventTypeRepositoryTest.php +++ b/tests/integration/AppBundle/Event/Entity/Repository/TicketEventTypeRepositoryTest.php @@ -23,9 +23,9 @@ public function testGetTicketsByEventRetourneLesTarifsDEvenement(): void self::assertSame(9001, $ticketEventTypes[0]->ticketTypeId); self::assertSame(150.0, $ticketEventTypes[0]->price); self::assertSame(2, $ticketEventTypes[0]->maxTickets); - self::assertSame('Tarif public', $ticketEventTypes[0]->ticketType->getPrettyName()); + self::assertSame('Tarif public', $ticketEventTypes[0]->ticketType->prettyName); self::assertSame(9002, $ticketEventTypes[1]->ticketTypeId); - self::assertTrue($ticketEventTypes[1]->ticketType->getIsRestrictedToMembers()); + self::assertTrue($ticketEventTypes[1]->ticketType->isRestrictedToMembers); } public function testGetTicketsByEventAvecFiltrePublic(): void diff --git a/tests/integration/AppBundle/Event/Entity/Repository/TicketTypeRepositoryTest.php b/tests/integration/AppBundle/Event/Entity/Repository/TicketTypeRepositoryTest.php index 0984ba27ce..5b1dde3423 100644 --- a/tests/integration/AppBundle/Event/Entity/Repository/TicketTypeRepositoryTest.php +++ b/tests/integration/AppBundle/Event/Entity/Repository/TicketTypeRepositoryTest.php @@ -6,7 +6,10 @@ use Afup\Tests\Support\IntegrationTestCase; use AppBundle\Event\Entity\Repository\TicketTypeRepository; +use AppBundle\Event\Entity\TicketEventType; use AppBundle\Event\Entity\TicketType; +use AppBundle\Event\Model\Ticket; +use AppBundle\Event\Model\TicketAggregate; use Doctrine\DBAL\Connection; final class TicketTypeRepositoryTest extends IntegrationTestCase @@ -79,6 +82,42 @@ public function testFindReturnsNullForUnknownId(): void self::assertNull($repository->find(999999)); } + public function testAttachToRenseigneLeTypeDeTarif(): void + { + $repository = self::getContainer()->get(TicketTypeRepository::class); + $connection = self::getContainer()->get(Connection::class); + + $id = $this->insertTicketType($connection, ['pretty_name' => 'Tarif rattaché']); + + $connu = new TicketEventType(); + $connu->ticketTypeId = $id; + // Tarif d'évènement dont le type n'existe plus + $inconnu = new TicketEventType(); + $inconnu->ticketTypeId = 999999; + + $repository->attachTo([$connu, $inconnu]); + + self::assertSame('Tarif rattaché', $connu->ticketType?->prettyName); + self::assertNull($inconnu->ticketType); + } + + public function testEnrichTicketAggregatesChargeLeTypeDeTarif(): void + { + $repository = self::getContainer()->get(TicketTypeRepository::class); + $connection = self::getContainer()->get(Connection::class); + + $id = $this->insertTicketType($connection, ['pretty_name' => 'Tarif inscrit']); + + $aggregates = $repository->enrichTicketAggregates([ + new TicketAggregate(new Ticket()->setTicketTypeId($id), null, null, null), + new TicketAggregate(new Ticket()->setTicketTypeId(999999), null, null, null), + ]); + + self::assertCount(2, $aggregates); + self::assertSame('Tarif inscrit', $aggregates[0]->ticketType?->prettyName); + self::assertNull($aggregates[1]->ticketType); + } + /** * @param array $data */