PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.10
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.10
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Hooks / Handlers / DataExporter.php

DataExporter.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.10, at app/Hooks/Handlers/DataExporter.php

108 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Hooks\Handlers;
4
5
6 use FluentBooking\App\Models\Booking;
7 use FluentBooking\App\Services\PermissionManager;
8
9 class DataExporter
10 {
11 public function exportBookingHosts()
12 {
13 if (!PermissionManager::hasAllCalendarAccess()) {
14 die(esc_html__('You do not have permission to export data', 'fluent-booking'));
15 }
16
17 $groupId = (int)$_REQUEST['group_id']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
18
19 if (!$groupId) {
20 die(esc_html__('Please provide Group ID', 'fluent-booking'));
21 }
22
23 $attendees = Booking::where('group_id', $groupId)->get();
24
25 $csvData[] = [
26 'First Name',
27 'Last Name',
28 'Email',
29 'Message',
30 'Location Details',
31 'Source',
32 'Booking Type',
33 'Status',
34 'Source URL',
35 'Duration',
36 'Start Time',
37 'End Time',
38 'Payment Status',
39 'Payment Order Status',
40 'Payment Method',
41 'Currency',
42 'Total Amount',
43 'Order Created At',
44 'Transaction ID',
45 'Vendor Charge ID',
46 'Transaction Payment Method',
47 'Transaction Status',
48 'Transaction Total',
49 'Transaction Created At',
50 ];
51
52 foreach ($attendees as $attendee) {
53 $row = [
54 $attendee->first_name,
55 $attendee->last_name,
56 $attendee->email,
57 $attendee->message,
58 $attendee->getLocationAsText(),
59 $attendee->source,
60 $attendee->booking_type,
61 $attendee->status,
62 $attendee->source_url,
63 $attendee->slot_minutes,
64 $attendee->start_time,
65 $attendee->end_time,
66 $attendee->payment_status,
67 ];
68
69 if ($attendee->payment_status) {
70 $order = $attendee->payment_order;
71 if ($order) {
72 $order->load(['items', 'transaction']);
73 $row[] = $order->status;
74 $row[] = $order->payment_method;
75 $row[] = $order->currency;
76 $row[] = $order->total_amount / 100;
77 $row[] = $order->created_at;
78 $row[] = $order->transaction->id;
79 $row[] = $order->transaction->vendor_charge_id;
80 $row[] = $order->transaction->payment_method;
81 $row[] = $order->transaction->status;
82 $row[] = $order->transaction->total / 100;
83 $row[] = $order->transaction->created_at;
84 }
85 } else {
86 // Fill empty columns for payment related data if payment_status is false
87 $row = array_pad($row, 11, '');
88 }
89
90 $csvData[] = $row;
91 }
92
93 $csvData = apply_filters('fluent_booking/exporting_booking_data_csv', $csvData, $attendees);
94
95 $output = fopen('php://output', 'w');
96 header('Content-Type: text/csv');
97 header('Content-Disposition: attachment; filename=Booking-Event-Guests-' . $groupId . '.csv');
98
99 foreach ($csvData as $row) {
100 fputcsv($output, $row);
101 }
102
103 fclose($output); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
104 exit();
105 }
106
107 }
108