PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1.3
Booking for Appointments and Events Calendar – Amelia v2.1.3
2.4.5 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 4 months ago CustomerBookingExtraFactory.php 6 months ago CustomerBookingFactory.php 4 months ago
CustomerBookingFactory.php
358 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 'created' => isset($row['booking_created']) ? $row['booking_created'] : null,
248 ];
249 }
250
251 if ($data[$id] && $customerId && empty($data[$id]['customer'])) {
252 $data[$id]['customer'] = [
253 'id' => $customerId,
254 'firstName' => $row['customer_firstName'],
255 'lastName' => $row['customer_lastName'],
256 'email' => $row['customer_email'],
257 'note' => $row['customer_note'],
258 'phone' => $row['customer_phone'],
259 'gender' => $row['customer_gender'],
260 'birthday' => $row['customer_birthday'],
261 'customFields' => !empty($row['customer_customFields']) ? $row['customer_customFields'] : null,
262 ];
263 }
264
265 if ($data[$id] && $paymentId && empty($data[$id]['payments'][$paymentId])) {
266 $data[$id]['payments'][$paymentId] = [
267 'id' => $paymentId,
268 'customerBookingId' => $id,
269 'amount' => $row['payment_amount'],
270 'dateTime' => $row['payment_dateTime'],
271 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
272 'status' => $row['payment_status'],
273 'gateway' => $row['payment_gateway'],
274 'gatewayTitle' => $row['payment_gatewayTitle'],
275 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
276 'parentId' => isset($row['payment_parentId']) ? (int)$row['payment_parentId'] : null,
277 'data' => $row['payment_data'],
278 'wcOrderId' => isset($row['payment_wcOrderId']) ? (int)$row['payment_wcOrderId'] : null,
279 'wcOrderItemId' => isset($row['payment_wcOrderItemId']) ? (int)$row['payment_wcOrderItemId'] : null,
280 'invoiceNumber' => isset($row['payment_invoiceNumber']) ? (int)$row['payment_invoiceNumber'] : null
281 ];
282 }
283
284 if ($data[$id] && $couponId && empty($data[$id]['coupon'])) {
285 $data[$id]['coupon'] = [
286 'id' => $couponId,
287 'code' => $row['coupon_code'],
288 'discount' => $row['coupon_discount'],
289 'deduction' => $row['coupon_deduction'],
290 'limit' => isset($row['coupon_limit']) ? (int)$row['coupon_limit'] : null,
291 'customerLimit' => isset($row['coupon_customerLimit']) ? (int)$row['coupon_customerLimit'] : null,
292 'status' => $row['coupon_status'],
293 ];
294 }
295
296 if ($data[$id] && $bookingEventTicketId && empty($data[$id]['ticketsData'][$bookingEventTicketId])) {
297 $data[$id]['ticketsData'][$bookingEventTicketId] = [
298 'id' => $bookingEventTicketId,
299 'eventTicketId' => (int)$row['booking_ticket_eventTicketId'],
300 'customerBookingId' => $id,
301 'persons' => (int)$row['booking_ticket_persons'],
302 'price' => $row['booking_ticket_price'],
303 ];
304 }
305
306 if ($data[$id] && $eventId && empty($data[$id]['event'])) {
307 $data[$id]['event'] = [
308 'id' => $eventId,
309 'name' => $row['event_name'],
310 'status' => $row['event_status'],
311 'customPricing' => $row['event_customPricing'],
312 'organizerId' => isset($row['event_organizerId']) ? (int)$row['event_organizerId'] : null,
313 'settings' => $row['event_settings'],
314 'isWaitingList' => $row['event_settings']
315 ? json_decode($row['event_settings'], true)['waitingList']['enabled']
316 : false,
317 ];
318 }
319
320 if ($data[$id] && $eventProviderId) {
321 if ($data[$id]['event']['organizerId'] === $eventProviderId && empty($data[$id]['event']['organizer'])) {
322 $data[$id]['event']['organizer'] = [
323 'id' => $eventProviderId,
324 'firstName' => $row['provider_firstName'],
325 'lastName' => $row['provider_lastName'],
326 'email' => $row['provider_email'],
327 'picture' => $row['provider_pictureThumbPath'],
328 'badgeId' => $row['provider_badgeId'],
329 ];
330 } elseif ($data[$id]['event']['organizerId'] !== $eventProviderId && empty($data[$id]['event']['providers'][$eventProviderId])) {
331 $data[$id]['event']['providers'][$eventProviderId] = [
332 'id' => $eventProviderId,
333 'firstName' => $row['provider_firstName'],
334 'lastName' => $row['provider_lastName'],
335 'email' => $row['provider_email'],
336 'picture' => $row['provider_pictureThumbPath'],
337 'badgeId' => $row['provider_badgeId'],
338 ];
339 }
340 }
341
342 if ($data[$id] && $eventPeriodId && empty($data[$id]['event']['periods'][$eventPeriodId])) {
343 $data[$id]['event']['periods'][$eventPeriodId] = [
344 'id' => $eventPeriodId,
345 'periodStart' => $row['event_periodStart'],
346 'periodEnd' => $row['event_periodEnd'],
347 'zoomMeeting' => $row['event_zoomMeeting'],
348 'googleMeetUrl' => $row['event_googleMeetUrl'],
349 'microsoftTeamsUrl' => $row['event_microsoftTeamsUrl'],
350 'lessonSpace' => $row['event_lessonSpace'],
351 ];
352 }
353 }
354
355 return $data;
356 }
357 }
358