PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1
Booking for Appointments and Events Calendar – Amelia v2.1
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Domain / Factory / Booking / Appointment / CustomerBookingFactory.php
ameliabooking / src / Domain / Factory / Booking / Appointment Last commit date
AppointmentFactory.php 6 months ago CustomerBookingExtraFactory.php 6 months ago CustomerBookingFactory.php 6 months ago
CustomerBookingFactory.php
357 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Domain\Factory\Booking\Appointment;
9
10 use AmeliaBooking\Domain\Collection\Collection;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Domain\Entity\Bookable\Service\PackageCustomerService;
13 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
14 use AmeliaBooking\Domain\Factory\Bookable\Service\PackageCustomerServiceFactory;
15 use AmeliaBooking\Domain\Factory\Booking\Event\CustomerBookingEventTicketFactory;
16 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
17 use AmeliaBooking\Domain\Factory\Payment\PaymentFactory;
18 use AmeliaBooking\Domain\Factory\User\UserFactory;
19 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
20 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
21 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
22 use AmeliaBooking\Domain\ValueObjects\Json;
23 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
24 use AmeliaBooking\Domain\ValueObjects\PositiveDuration;
25 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
26 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
27 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
28 use AmeliaBooking\Domain\ValueObjects\String\Token;
29
30 /**
31 * Class CustomerBookingFactory
32 *
33 * @package AmeliaBooking\Domain\Factory\Booking\Appointment
34 */
35 class CustomerBookingFactory
36 {
37 /**
38 * @param $data
39 *
40 * @return CustomerBooking
41 * @throws InvalidArgumentException
42 */
43 public static function create($data)
44 {
45 $customerBooking = new CustomerBooking();
46
47 if (isset($data['id'])) {
48 $customerBooking->setId(new Id($data['id']));
49 }
50
51 if (isset($data['customerId'])) {
52 $customerBooking->setCustomerId(new Id($data['customerId']));
53 }
54
55 if (isset($data['status'])) {
56 $customerBooking->setStatus(new BookingStatus($data['status']));
57 }
58
59 if (isset($data['persons'])) {
60 $customerBooking->setPersons(new IntegerValue($data['persons']));
61 }
62
63 if (isset($data['price'])) {
64 $customerBooking->setPrice(new Price($data['price']));
65 }
66
67 if (isset($data['appointmentId'])) {
68 $customerBooking->setAppointmentId(new Id($data['appointmentId']));
69 }
70
71 if (isset($data['couponId'])) {
72 $customerBooking->setCouponId(new Id($data['couponId']));
73 }
74
75 if (isset($data['coupon'])) {
76 $customerBooking->setCoupon(CouponFactory::create($data['coupon']));
77 }
78
79 if (isset($data['customer'])) {
80 $customerBooking->setCustomer(UserFactory::create($data['customer']));
81 }
82
83 if (isset($data['customFields'])) {
84 if (is_string($data['customFields'])) {
85 $customerBooking->setCustomFields(new Json($data['customFields']));
86 } elseif (json_encode($data['customFields']) !== false) {
87 $customerBooking->setCustomFields(new Json(json_encode($data['customFields'])));
88 }
89 }
90
91 if (isset($data['info'])) {
92 $customerBooking->setInfo(new Json($data['info']));
93 }
94
95 if (isset($data['qrCodes'])) {
96 if (is_string($data['qrCodes'])) {
97 $customerBooking->setQrCodes(new Json($data['qrCodes']));
98 } elseif (json_encode($data['qrCodes']) !== false) {
99 $customerBooking->setQrCodes(new Json(json_encode($data['qrCodes'])));
100 }
101 }
102
103 if (isset($data['utcOffset'])) {
104 $customerBooking->setUtcOffset(new IntegerValue($data['utcOffset']));
105 }
106
107 if (isset($data['aggregatedPrice'])) {
108 $customerBooking->setAggregatedPrice(new BooleanValueObject($data['aggregatedPrice']));
109 }
110
111 if (isset($data['isChangedStatus'])) {
112 $customerBooking->setChangedStatus(new BooleanValueObject($data['isChangedStatus']));
113 }
114
115 if (isset($data['isLastBooking'])) {
116 $customerBooking->setLastBooking(new BooleanValueObject($data['isLastBooking']));
117 }
118
119 if (isset($data['setIcsFiles'])) {
120 $customerBooking->setIcsFiles($data['setIcsFiles']);
121 }
122
123 if (isset($data['isNew'])) {
124 $customerBooking->setNew(new BooleanValueObject($data['isNew']));
125 }
126
127 if (isset($data['isUpdated'])) {
128 $customerBooking->setUpdated(new BooleanValueObject($data['isUpdated']));
129 }
130
131 if (isset($data['deposit'])) {
132 $customerBooking->setDeposit(new BooleanValueObject($data['deposit']));
133 }
134
135 if (isset($data['packageCustomerService'])) {
136 /** @var PackageCustomerService $packageCustomerService */
137 $packageCustomerService = PackageCustomerServiceFactory::create($data['packageCustomerService']);
138
139 $customerBooking->setPackageCustomerService($packageCustomerService);
140 }
141
142 if (isset($data['duration'])) {
143 $customerBooking->setDuration(new PositiveDuration($data['duration']));
144 }
145
146 $payments = new Collection();
147
148 if (isset($data['payments'])) {
149 foreach ((array)$data['payments'] as $key => $value) {
150 $payments->addItem(
151 PaymentFactory::create($value),
152 $key
153 );
154 }
155 }
156
157 $customerBooking->setPayments($payments);
158
159 $extras = new Collection();
160
161 if (isset($data['extras'])) {
162 foreach ((array)$data['extras'] as $key => $value) {
163 $extras->addItem(
164 CustomerBookingExtraFactory::create($value),
165 $key
166 );
167 }
168 }
169
170 $customerBooking->setExtras($extras);
171
172 if (isset($data['token'])) {
173 $customerBooking->setToken(new Token($data['token']));
174 }
175
176 $ticketsBooking = new Collection();
177
178 if (!empty($data['ticketsData'])) {
179 foreach ((array)$data['ticketsData'] as $key => $value) {
180 $ticketsBooking->addItem(
181 CustomerBookingEventTicketFactory::create($value),
182 $key
183 );
184 }
185 }
186
187 $customerBooking->setTicketsBooking($ticketsBooking);
188
189 if (!empty($data['created'])) {
190 $customerBooking->setCreated(new DateTimeValue(DateTimeService::getCustomDateTimeObjectFromUtc($data['created'])));
191 }
192
193 if (!empty($data['tax'])) {
194 if (is_string($data['tax'])) {
195 $customerBooking->setTax(new Json($data['tax']));
196 } elseif (json_encode($data['tax']) !== false) {
197 $customerBooking->setTax(new Json(json_encode($data['tax'])));
198 }
199 }
200
201 return $customerBooking;
202 }
203
204 /**
205 * @param array $rows
206 *
207 * @return array
208 */
209 public static function reformat($rows)
210 {
211 $data = [];
212
213 foreach ($rows as $row) {
214 $id = (int)$row['booking_id'];
215
216 $customerId = !empty($row['customer_id']) ? (int)$row['customer_id'] : null;
217
218 $paymentId = !empty($row['payment_id']) ? (int)$row['payment_id'] : null;
219
220 $couponId = !empty($row['coupon_id']) ? (int)$row['coupon_id'] : null;
221
222 $bookingEventTicketId = !empty($row['booking_ticket_id']) ? (int)$row['booking_ticket_id'] : null;
223
224 $eventPeriodId = !empty($row['event_periodId']) ? (int)$row['event_periodId'] : null;
225
226 $eventProviderId = !empty($row['provider_id']) ? (int)$row['provider_id'] : null;
227
228 $eventId = !empty($row['event_id']) ? (int)$row['event_id'] : null;
229
230 if ($id && empty($data[$id])) {
231 $data[$id] = [
232 'id' => $id,
233 'appointmentId' => isset($row['booking_appointmentId']) ? (int)$row['booking_appointmentId'] : null,
234 'customerId' => isset($row['booking_customerId']) ? (int)$row['booking_customerId'] : null,
235 'status' => $row['booking_status'],
236 'price' => $row['booking_price'],
237 'persons' => isset($row['booking_persons']) ? (int)$row['booking_persons'] : null,
238 'couponId' => isset($row['booking_couponId']) ? (int)$row['booking_couponId'] : null,
239 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null,
240 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null,
241 'utcOffset' => isset($row['booking_utcOffset']) ? (int)$row['booking_utcOffset'] : null,
242 'aggregatedPrice' => isset($row['booking_aggregatedPrice']) ? (int)$row['booking_aggregatedPrice'] : null,
243 'duration' => !empty($row['booking_duration']) ? (int)$row['booking_duration'] : null,
244 'token' => isset($row['booking_token']) ? $row['booking_token'] : null,
245 'tax' => isset($row['booking_tax']) ? $row['booking_tax'] : null,
246 'qrCodes' => isset($row['booking_qrCodes']) ? $row['booking_qrCodes'] : (isset($row['qrCodes']) ? $row['qrCodes'] : null),
247 ];
248 }
249
250 if ($data[$id] && $customerId && empty($data[$id]['customer'])) {
251 $data[$id]['customer'] = [
252 'id' => $customerId,
253 'firstName' => $row['customer_firstName'],
254 'lastName' => $row['customer_lastName'],
255 'email' => $row['customer_email'],
256 'note' => $row['customer_note'],
257 'phone' => $row['customer_phone'],
258 'gender' => $row['customer_gender'],
259 'birthday' => $row['customer_birthday'],
260 'customFields' => !empty($row['customer_customFields']) ? $row['customer_customFields'] : null,
261 ];
262 }
263
264 if ($data[$id] && $paymentId && empty($data[$id]['payments'][$paymentId])) {
265 $data[$id]['payments'][$paymentId] = [
266 'id' => $paymentId,
267 'customerBookingId' => $id,
268 'amount' => $row['payment_amount'],
269 'dateTime' => $row['payment_dateTime'],
270 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
271 'status' => $row['payment_status'],
272 'gateway' => $row['payment_gateway'],
273 'gatewayTitle' => $row['payment_gatewayTitle'],
274 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
275 'parentId' => isset($row['payment_parentId']) ? (int)$row['payment_parentId'] : null,
276 'data' => $row['payment_data'],
277 'wcOrderId' => isset($row['payment_wcOrderId']) ? (int)$row['payment_wcOrderId'] : null,
278 'wcOrderItemId' => isset($row['payment_wcOrderItemId']) ? (int)$row['payment_wcOrderItemId'] : null,
279 'invoiceNumber' => isset($row['payment_invoiceNumber']) ? (int)$row['payment_invoiceNumber'] : null
280 ];
281 }
282
283 if ($data[$id] && $couponId && empty($data[$id]['coupon'])) {
284 $data[$id]['coupon'] = [
285 'id' => $couponId,
286 'code' => $row['coupon_code'],
287 'discount' => $row['coupon_discount'],
288 'deduction' => $row['coupon_deduction'],
289 'limit' => isset($row['coupon_limit']) ? (int)$row['coupon_limit'] : null,
290 'customerLimit' => isset($row['coupon_customerLimit']) ? (int)$row['coupon_customerLimit'] : null,
291 'status' => $row['coupon_status'],
292 ];
293 }
294
295 if ($data[$id] && $bookingEventTicketId && empty($data[$id]['ticketsData'][$bookingEventTicketId])) {
296 $data[$id]['ticketsData'][$bookingEventTicketId] = [
297 'id' => $bookingEventTicketId,
298 'eventTicketId' => (int)$row['booking_ticket_eventTicketId'],
299 'customerBookingId' => $id,
300 'persons' => (int)$row['booking_ticket_persons'],
301 'price' => $row['booking_ticket_price'],
302 ];
303 }
304
305 if ($data[$id] && $eventId && empty($data[$id]['event'])) {
306 $data[$id]['event'] = [
307 'id' => $eventId,
308 'name' => $row['event_name'],
309 'status' => $row['event_status'],
310 'customPricing' => $row['event_customPricing'],
311 'organizerId' => isset($row['event_organizerId']) ? (int)$row['event_organizerId'] : null,
312 'settings' => $row['event_settings'],
313 'isWaitingList' => $row['event_settings']
314 ? json_decode($row['event_settings'], true)['waitingList']['enabled']
315 : false,
316 ];
317 }
318
319 if ($data[$id] && $eventProviderId) {
320 if ($data[$id]['event']['organizerId'] === $eventProviderId && empty($data[$id]['event']['organizer'])) {
321 $data[$id]['event']['organizer'] = [
322 'id' => $eventProviderId,
323 'firstName' => $row['provider_firstName'],
324 'lastName' => $row['provider_lastName'],
325 'email' => $row['provider_email'],
326 'picture' => $row['provider_pictureThumbPath'],
327 'badgeId' => $row['provider_badgeId'],
328 ];
329 } elseif ($data[$id]['event']['organizerId'] !== $eventProviderId && empty($data[$id]['event']['providers'][$eventProviderId])) {
330 $data[$id]['event']['providers'][$eventProviderId] = [
331 'id' => $eventProviderId,
332 'firstName' => $row['provider_firstName'],
333 'lastName' => $row['provider_lastName'],
334 'email' => $row['provider_email'],
335 'picture' => $row['provider_pictureThumbPath'],
336 'badgeId' => $row['provider_badgeId'],
337 ];
338 }
339 }
340
341 if ($data[$id] && $eventPeriodId && empty($data[$id]['event']['periods'][$eventPeriodId])) {
342 $data[$id]['event']['periods'][$eventPeriodId] = [
343 'id' => $eventPeriodId,
344 'periodStart' => $row['event_periodStart'],
345 'periodEnd' => $row['event_periodEnd'],
346 'zoomMeeting' => $row['event_zoomMeeting'],
347 'googleMeetUrl' => $row['event_googleMeetUrl'],
348 'microsoftTeamsUrl' => $row['event_microsoftTeamsUrl'],
349 'lessonSpace' => $row['event_lessonSpace'],
350 ];
351 }
352 }
353
354 return $data;
355 }
356 }
357