From 35c33744417a64a69e9f42a2602a4b6cdd56f9f4 Mon Sep 17 00:00:00 2001 From: Dave Earley Date: Fri, 20 Dec 2024 16:07:50 +0000 Subject: [PATCH] Add ticket name to export --- backend/app/Exports/AttendeesExport.php | 15 +++++++++++++++ .../Actions/Attendees/ExportAttendeesAction.php | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/backend/app/Exports/AttendeesExport.php b/backend/app/Exports/AttendeesExport.php index 54e11a6e..7f5d0d42 100644 --- a/backend/app/Exports/AttendeesExport.php +++ b/backend/app/Exports/AttendeesExport.php @@ -5,7 +5,10 @@ use Carbon\Carbon; use HiEvents\DomainObjects\AttendeeDomainObject; use HiEvents\DomainObjects\Enums\QuestionTypeEnum; +use HiEvents\DomainObjects\Enums\TicketType; use HiEvents\DomainObjects\QuestionDomainObject; +use HiEvents\DomainObjects\TicketDomainObject; +use HiEvents\DomainObjects\TicketPriceDomainObject; use HiEvents\Resources\Attendee\AttendeeResource; use HiEvents\Services\Domain\Question\QuestionAnswerFormatter; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -51,6 +54,7 @@ public function headings(): array 'Is Checked In', 'Checked In At', 'Ticket ID', + 'Ticket Name', 'Event ID', 'Public ID', 'Short ID', @@ -75,6 +79,16 @@ public function map($attendee): array ); }); + /** @var TicketDomainObject $ticket */ + $ticket = $attendee->getTicket(); + $ticketName = $ticket->getTitle(); + if ($attendee->getTicket()?->getType() === TicketType::TIERED->name) { + $ticketName .= ' - ' . $ticket + ->getTicketPrices() + ->first(fn(TicketPriceDomainObject $tp) => $tp->getId() === $attendee->getTicketPriceId()) + ->getLabel(); + } + return array_merge([ $attendee->getId(), $attendee->getFirstName(), @@ -86,6 +100,7 @@ public function map($attendee): array ? Carbon::parse($attendee->getCheckIn()->getCreatedAt())->format('Y-m-d H:i:s') : '', $attendee->getTicketId(), + $ticketName, $attendee->getEventId(), $attendee->getPublicId(), $attendee->getShortId(), diff --git a/backend/app/Http/Actions/Attendees/ExportAttendeesAction.php b/backend/app/Http/Actions/Attendees/ExportAttendeesAction.php index 35679239..729b5c8a 100644 --- a/backend/app/Http/Actions/Attendees/ExportAttendeesAction.php +++ b/backend/app/Http/Actions/Attendees/ExportAttendeesAction.php @@ -6,6 +6,8 @@ use HiEvents\DomainObjects\Enums\QuestionBelongsTo; use HiEvents\DomainObjects\EventDomainObject; use HiEvents\DomainObjects\QuestionAndAnswerViewDomainObject; +use HiEvents\DomainObjects\TicketDomainObject; +use HiEvents\DomainObjects\TicketPriceDomainObject; use HiEvents\Exports\AttendeesExport; use HiEvents\Http\Actions\BaseAction; use HiEvents\Repository\Eloquent\Value\Relationship; @@ -37,6 +39,15 @@ public function __invoke(int $eventId): BinaryFileResponse domainObject: AttendeeCheckInDomainObject::class, name: 'check_in', )) + ->loadRelation(new Relationship( + domainObject: TicketDomainObject::class, + nested: [ + new Relationship( + domainObject: TicketPriceDomainObject::class, + ), + ], + name: 'ticket' + )) ->findByEventIdForExport($eventId); $questions = $this->questionRepository->findWhere([