EventDetails.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\EventTickets\ViewModels; |
| 4 | |
| 5 | use Give\DonationForms\Models\DonationForm; |
| 6 | use Give\EventTickets\Actions\AttachAttendeeDataToTicketData; |
| 7 | use Give\EventTickets\DataTransferObjects\EventTicketTypeData; |
| 8 | use Give\EventTickets\Models\Event; |
| 9 | use Give\EventTickets\Models\EventTicketType; |
| 10 | |
| 11 | /** |
| 12 | * @since 3.6.0 |
| 13 | */ |
| 14 | class EventDetails |
| 15 | { |
| 16 | |
| 17 | /** |
| 18 | * @since 3.6.0 |
| 19 | * @var Event |
| 20 | */ |
| 21 | protected $event; |
| 22 | |
| 23 | /** |
| 24 | * @since 3.6.0 |
| 25 | */ |
| 26 | public function __construct(Event $event) |
| 27 | { |
| 28 | $this->event = $event; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @since 3.6.0 |
| 33 | */ |
| 34 | public function exports(): array |
| 35 | { |
| 36 | $tickets = $this->event->eventTickets()->getAll() ?? []; |
| 37 | |
| 38 | return array_merge($this->event->toArray(), [ |
| 39 | 'ticketTypes' => array_map(function (EventTicketType $ticketType) { |
| 40 | return EventTicketTypeData::make($ticketType)->toArray(); |
| 41 | }, $this->event->ticketTypes()->getAll() ?? []), |
| 42 | 'forms' => array_map(function (DonationForm $form) { |
| 43 | return ['id' => $form->id, 'title' => $form->title]; |
| 44 | }, $this->event->forms()->getAll() ?? []), |
| 45 | 'tickets' => array_map(new AttachAttendeeDataToTicketData($tickets), $tickets), |
| 46 | ]); |
| 47 | } |
| 48 | } |
| 49 |