PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / trunk
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution vtrunk
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 / Services / ExportHelper.php

ExportHelper.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution trunk, at app/Services/ExportHelper.php

82 lines 3.6 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\Services;
4
5 use FluentBooking\App\Models\Booking;
6
7 class ExportHelper
8 {
9 public static function mapBooking(Booking $booking): array
10 {
11 $event = $booking->calendar_event;
12 $host = $booking->user;
13
14 return [
15 'id' => (int) $booking->id,
16 'group_id' => (int) $booking->group_id,
17 'event_type' => self::sanitizeCell($booking->event_type),
18 'event_title' => self::sanitizeCell($event ? $event->title : ''),
19 'host_name' => self::sanitizeCell($host ? $host->display_name : ''),
20 'first_name' => self::sanitizeCell($booking->first_name),
21 'last_name' => self::sanitizeCell($booking->last_name),
22 'email' => self::sanitizeCell($booking->email),
23 'phone' => self::sanitizeCell($booking->phone),
24 'message' => self::compactText($booking->message),
25 'internal_note' => self::compactText($booking->internal_note),
26 'status' => self::sanitizeCell($booking->status),
27 'cancelled' => $booking->status === 'cancelled' ? 'Yes' : 'No',
28 'cancelled_by' => self::sanitizeCell($booking->getMeta('cancelled_by_type', 'host')),
29 'cancellation_reason' => self::compactText($booking->getCancelReason(true)),
30 'person_time_zone' => self::sanitizeCell($booking->person_time_zone),
31 'start_time' => (string) $booking->start_time,
32 'end_time' => (string) $booking->end_time,
33 'duration' => (int) $booking->slot_minutes,
34 'meeting_location' => self::compactText($booking->getLocationAsText()),
35 'source' => self::sanitizeCell($booking->source),
36 'source_url' => self::sanitizeCell($booking->source_url),
37 'utm_source' => self::sanitizeCell($booking->utm_source),
38 'utm_medium' => self::sanitizeCell($booking->utm_medium),
39 'utm_campaign' => self::sanitizeCell($booking->utm_campaign),
40 'utm_term' => self::sanitizeCell($booking->utm_term),
41 'utm_content' => self::sanitizeCell($booking->utm_content),
42 'created_at' => (string) $booking->created_at,
43 'event_price' => $event ? $event->getEventPrice($booking->slot_minutes) : 0,
44 'payment_status' => self::sanitizeCell($booking->payment_status),
45 'payment_method' => self::sanitizeCell($booking->payment_method),
46 ];
47 }
48
49 public static function sanitizeCell($value)
50 {
51 if (empty($value) && $value !== '0' && $value !== 0) {
52 return '';
53 }
54
55 $value = (string) $value;
56 $value = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $value);
57
58 $check = ltrim($value, " \t\xC2\xA0");
59 $first = isset($check[0]) ? $check[0] : '';
60 if (in_array($first, ['=', '+', '-', '@'], true)) {
61 $value = "'" . $value;
62 }
63
64 return $value;
65 }
66
67 public static function compactText($value)
68 {
69 if (empty($value) && $value !== '0' && $value !== 0) {
70 return '';
71 }
72
73 $value = wp_strip_all_tags((string) $value);
74 $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5, 'UTF-8');
75 $value = str_replace(["\r\n", "\r", "\n", "\t"], ' ', $value);
76 $value = preg_replace('/\s+/', ' ', $value);
77 $value = trim($value);
78
79 return self::sanitizeCell($value);
80 }
81 }
82