Server IP : 192.158.238.246 / Your IP : 3.138.101.1 Web Server : LiteSpeed System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64 User : jenniferflocom ( 1321) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/7779/task/7779/cwd/plugins/give/src/EventTickets/Actions/ |
Upload File : |
<?php namespace Give\EventTickets\Actions; use Give\EventTickets\Models\EventTicket; use Give\Framework\QueryBuilder\QueryBuilder; /** * @since 3.6.0 */ class AttachAttendeeDataToTicketData { /** * @since 3.6.0 * @var array */ protected $attendeeDataLookup; /** * @since 3.6.0 * @param EventTicket[] $tickets */ public function __construct(array $tickets) { $this->attendeeDataLookup = array_reduce($this->getAttendeeDataForTickets($tickets), function ($lookup, $data) { $lookup[$data->donationId] = ['name' => $data->attendeeName, 'email' => $data->attendeeEmail]; return $lookup; }, []); } /** * @since 3.6.0 */ public function __invoke(EventTicket $ticket): array { return array_merge($ticket->toArray(), [ 'attendee' => $this->attendeeDataLookup[$ticket->donationId] ?? null, ]); } /** * This query relates donors names to tickets through donations. * * @since 3.6.0 * * @param EventTicket[] $tickets */ protected function getAttendeeDataForTickets(array $tickets): array { if (empty($tickets)) { return []; } return (new QueryBuilder) ->from('posts', 'Donation') ->select( ['Donation.ID', 'donationId'], ['Donor.name', 'attendeeName'], ['Donor.email', 'attendeeEmail'] ) ->join(function($builder) { $builder ->leftJoin('give_donationmeta', $tableAlias = 'DonationDonorId' ) ->on('Donation.ID', "DonationDonorId.donation_id") ->andOn("DonationDonorId.meta_key", '_give_payment_donor_id', true); }) ->join(function($builder) { $builder ->leftJoin('give_donors', $tableAlias = 'Donor' ) ->on('DonationDonorId.meta_value', "Donor.id"); }) ->where('post_type', 'give_payment') ->whereIn('Donation.ID', array_column($tickets, 'donationId')) ->getAll(); } }