diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ef695058c..3fd49b9ae 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 c123d253f..7ca48114a 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 eb3b3b2f2..3d7e9d84b 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 b45003fd9..68b16bb2b 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 edfa93829..2e169ff9a 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 85f9bb8d5..0b012a849 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 e9b2c8dac..d4ac805fd 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 2eef02230..5929c9a93 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 bd1c79873..ba7be4896 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 e88e81900..841a4ac74 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 66f0a3878..4dea9ee48 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 bbbb0b00d..256de780f 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 2735ad5b6..000000000 --- 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 f9c36f19d..d5dbada00 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 a4b1182dc..000000000 --- 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 2fe08e4c4..b91a5acf8 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 5e83b69e5..4df3941c0 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 1b9b3edd9..e3d6ddb40 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 e9447d3d0..1aa2a04a4 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 c8b474404..cb8ae5837 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 677caa4d7..3f4887241 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 9772f9347..abe861f3e 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 3d36433ea..08b3cbb04 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 3da9ba1f2..2fe9e5eda 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 0984ba27c..5b1dde342 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 */