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 / AppointmentFactory.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
AppointmentFactory.php
398 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\Booking\Appointment\Appointment;
13 use AmeliaBooking\Domain\Factory\Bookable\Service\ServiceFactory;
14 use AmeliaBooking\Domain\Factory\Location\LocationFactory;
15 use AmeliaBooking\Domain\Factory\User\UserFactory;
16 use AmeliaBooking\Domain\Factory\Zoom\ZoomFactory;
17 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
18 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
19 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
20 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
21 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
22 use AmeliaBooking\Domain\ValueObjects\String\Description;
23 use AmeliaBooking\Domain\ValueObjects\String\Label;
24 use AmeliaBooking\Domain\ValueObjects\String\Token;
25
26 /**
27 * Class AppointmentFactory
28 *
29 * @package AmeliaBooking\Domain\Factory\Booking\Appointment
30 */
31 class AppointmentFactory
32 {
33 /**
34 * @param $data
35 *
36 * @return Appointment
37 * @throws InvalidArgumentException
38 */
39 public static function create($data)
40 {
41 $appointment = new Appointment(
42 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingStart'])),
43 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingEnd'])),
44 $data['notifyParticipants'],
45 new Id($data['serviceId']),
46 new Id($data['providerId'])
47 );
48
49 if (isset($data['createPaymentLinks'])) {
50 $appointment->setCreatePaymentLinks($data['createPaymentLinks']);
51 }
52
53 if (!empty($data['id'])) {
54 $appointment->setId(new Id($data['id']));
55 }
56
57 if (!empty($data['parentId'])) {
58 $appointment->setParentId(new Id($data['parentId']));
59 }
60
61 if (!empty($data['locationId'])) {
62 $appointment->setLocationId(new Id($data['locationId']));
63 }
64
65 if (!empty($data['location'])) {
66 $appointment->setLocation(LocationFactory::create($data['location']));
67 }
68
69 if (isset($data['internalNotes'])) {
70 $appointment->setInternalNotes(new Description($data['internalNotes']));
71 }
72
73 if (isset($data['status'])) {
74 $appointment->setStatus(new BookingStatus($data['status']));
75 }
76
77 if (isset($data['provider'])) {
78 $appointment->setProvider(UserFactory::create($data['provider']));
79 }
80
81 if (isset($data['service'])) {
82 $appointment->setService(ServiceFactory::create($data['service']));
83 }
84
85 if (!empty($data['googleCalendarEventId'])) {
86 $appointment->setGoogleCalendarEventId(new Token($data['googleCalendarEventId']));
87 }
88
89 if (!empty($data['googleMeetUrl'])) {
90 $appointment->setGoogleMeetUrl($data['googleMeetUrl']);
91 }
92
93 if (!empty($data['outlookCalendarEventId'])) {
94 $appointment->setOutlookCalendarEventId(new Label($data['outlookCalendarEventId']));
95 }
96
97 if (!empty($data['microsoftTeamsUrl'])) {
98 $appointment->setMicrosoftTeamsUrl($data['microsoftTeamsUrl']);
99 }
100
101 if (!empty($data['appleCalendarEventId'])) {
102 $appointment->setAppleCalendarEventId(new Label($data['appleCalendarEventId']));
103 }
104
105 if (!empty($data['zoomMeeting']['id'])) {
106 $zoomMeeting = ZoomFactory::create(
107 $data['zoomMeeting']
108 );
109
110 $appointment->setZoomMeeting($zoomMeeting);
111 }
112
113 if (isset($data['lessonSpace']) && !empty($data['lessonSpace'])) {
114 $appointment->setLessonSpace($data['lessonSpace']);
115 }
116
117 if (isset($data['isRescheduled'])) {
118 $appointment->setRescheduled(new BooleanValueObject($data['isRescheduled']));
119 }
120
121 if (array_key_exists('isChangedStatus', $data)) {
122 $appointment->setChangedStatus(new BooleanValueObject($data['isChangedStatus']));
123 }
124
125 if (!empty($data['initialAppointmentDateTime']['bookingStart'])) {
126 $appointment->setInitialBookingStart(
127 new DateTimeValue(
128 DateTimeService::getCustomDateTimeObject($data['initialAppointmentDateTime']['bookingStart'])
129 )
130 );
131 }
132
133 if (!empty($data['initialAppointmentDateTime']['bookingEnd'])) {
134 $appointment->setInitialBookingEnd(
135 new DateTimeValue(
136 DateTimeService::getCustomDateTimeObject($data['initialAppointmentDateTime']['bookingEnd'])
137 )
138 );
139 }
140
141 $bookings = new Collection();
142
143 if (isset($data['bookings'])) {
144 foreach ((array)$data['bookings'] as $key => $value) {
145 $bookings->addItem(
146 CustomerBookingFactory::create($value),
147 $key
148 );
149 }
150 }
151
152 $appointment->setBookings($bookings);
153
154 return $appointment;
155 }
156
157 /**
158 * @param array $rows
159 *
160 * @return Collection
161 * @throws InvalidArgumentException
162 */
163 public static function createCollection($rows)
164 {
165 $appointments = [];
166
167 foreach ($rows as $row) {
168 $appointmentId = $row['appointment_id'];
169 $bookingId = isset($row['booking_id']) ? $row['booking_id'] : null;
170 $bookingExtraId = isset($row['bookingExtra_id']) ? $row['bookingExtra_id'] : null;
171 $paymentId = isset($row['payment_id']) ? $row['payment_id'] : null;
172 $couponId = isset($row['coupon_id']) ? $row['coupon_id'] : null;
173 $customerId = isset($row['customer_id']) ? $row['customer_id'] : null;
174 $providerId = isset($row['provider_id']) ? $row['provider_id'] : null;
175 $locationId = isset($row['location_id']) ? $row['location_id'] : null;
176 $serviceId = isset($row['service_id']) ? $row['service_id'] : null;
177
178 if (!array_key_exists($appointmentId, $appointments)) {
179 $zoomMeetingJson = !empty($row['appointment_zoom_meeting']) ?
180 json_decode($row['appointment_zoom_meeting'], true) : null;
181
182 $appointments[$appointmentId] = [
183 'id' => $appointmentId,
184 'parentId' => isset($row['appointment_parentId']) ?
185 $row['appointment_parentId'] : null,
186 'bookingStart' => DateTimeService::getCustomDateTimeFromUtc(
187 $row['appointment_bookingStart']
188 ),
189 'bookingEnd' => DateTimeService::getCustomDateTimeFromUtc(
190 $row['appointment_bookingEnd']
191 ),
192 'notifyParticipants' => isset($row['appointment_notifyParticipants']) ?
193 $row['appointment_notifyParticipants'] : null,
194 'createPaymentLinks' => isset($row['appointment_createPaymentLinks']) ?
195 $row['appointment_createPaymentLinks'] : null,
196 'serviceId' => $row['appointment_serviceId'],
197 'providerId' => $row['appointment_providerId'],
198 'locationId' => isset($row['appointment_locationId']) ?
199 $row['appointment_locationId'] : null,
200 'internalNotes' => isset($row['appointment_internalNotes']) ?
201 $row['appointment_internalNotes'] : null,
202 'status' => $row['appointment_status'],
203 'googleCalendarEventId' => isset($row['appointment_google_calendar_event_id']) ?
204 $row['appointment_google_calendar_event_id'] : null,
205 'googleMeetUrl' => isset($row['appointment_google_meet_url']) ?
206 $row['appointment_google_meet_url'] : null,
207 'outlookCalendarEventId' => isset($row['appointment_outlook_calendar_event_id']) ?
208 $row['appointment_outlook_calendar_event_id'] : null,
209 'microsoftTeamsUrl' => isset($row['appointment_microsoft_teams_url']) ?
210 $row['appointment_microsoft_teams_url'] : null,
211 'appleCalendarEventId' => isset($row['appointment_apple_calendar_event_id']) ?
212 $row['appointment_apple_calendar_event_id'] : null,
213 'zoomMeeting' => [
214 'id' => $zoomMeetingJson ? $zoomMeetingJson['id'] : null,
215 'startUrl' => $zoomMeetingJson ? $zoomMeetingJson['startUrl'] : null,
216 'joinUrl' => $zoomMeetingJson ? $zoomMeetingJson['joinUrl'] : null,
217 ],
218 'lessonSpace' => !empty($row['appointment_lesson_space']) ? $row['appointment_lesson_space'] : null,
219 ];
220 }
221
222 if ($bookingId && !isset($appointments[$appointmentId]['bookings'][$bookingId])) {
223 $appointments[$appointmentId]['bookings'][$bookingId] = [
224 'id' => $bookingId,
225 'appointmentId' => $appointmentId,
226 'customerId' => $row['booking_customerId'],
227 'status' => $row['booking_status'],
228 'couponId' => $couponId,
229 'price' => $row['booking_price'],
230 'persons' => $row['booking_persons'],
231 'customFields' => isset($row['booking_customFields']) ? $row['booking_customFields'] : null,
232 'info' => isset($row['booking_info']) ? $row['booking_info'] : null,
233 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null,
234 'aggregatedPrice' => isset($row['booking_aggregatedPrice']) ?
235 $row['booking_aggregatedPrice'] : null,
236 'packageCustomerService' => !empty($row['booking_packageCustomerServiceId']) ? [
237 'id' => $row['booking_packageCustomerServiceId'],
238 'serviceId' => !empty($row['package_customer_service_serviceId']) ?
239 $row['package_customer_service_serviceId'] : null,
240 'bookingsCount' => !empty($row['package_customer_service_bookingsCount']) ?
241 $row['package_customer_service_bookingsCount'] : null,
242 'packageCustomer' => [
243 'id' => !empty($row['package_customer_id']) ?
244 $row['package_customer_id'] : null,
245 'packageId' => !empty($row['package_customer_packageId']) ?
246 $row['package_customer_packageId'] : null,
247 'price' => !empty($row['package_customer_price']) ?
248 $row['package_customer_price'] : null,
249 'couponId' => !empty($row['package_customer_couponId']) ?
250 $row['package_customer_couponId'] : null,
251 'tax' => !empty($row['package_customer_tax']) ?
252 $row['package_customer_tax'] : null,
253 ]
254 ] : null,
255 'duration' => isset($row['booking_duration']) ? $row['booking_duration'] : null,
256 'created' => !empty($row['booking_created']) ? DateTimeService::getCustomDateTimeFromUtc($row['booking_created']) : null,
257 'tax' => isset($row['booking_tax']) ? $row['booking_tax'] : null,
258 ];
259 }
260
261 if ($bookingId && $bookingExtraId) {
262 $appointments[$appointmentId]['bookings'][$bookingId]['extras'][$bookingExtraId] =
263 [
264 'id' => $bookingExtraId,
265 'customerBookingId' => $bookingId,
266 'extraId' => $row['bookingExtra_extraId'],
267 'quantity' => $row['bookingExtra_quantity'],
268 'price' => $row['bookingExtra_price'],
269 'aggregatedPrice' => $row['bookingExtra_aggregatedPrice'],
270 'tax' => isset($row['bookingExtra_tax']) ? $row['bookingExtra_tax'] : null,
271 ];
272 }
273
274 if ($bookingId && $paymentId) {
275 $appointments[$appointmentId]['bookings'][$bookingId]['payments'][$paymentId] =
276 [
277 'id' => $paymentId,
278 'customerBookingId' => $bookingId,
279 'packageCustomerId' => !empty($row['payment_packageCustomerId']) ? $row['payment_packageCustomerId'] : null,
280 'status' => $row['payment_status'],
281 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']),
282 'gateway' => $row['payment_gateway'],
283 'gatewayTitle' => $row['payment_gatewayTitle'],
284 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
285 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
286 'amount' => $row['payment_amount'],
287 'data' => $row['payment_data'],
288 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null,
289 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
290 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ?
291 $row['payment_wcOrderItemId'] : null,
292 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
293 ];
294 }
295
296 if ($bookingId && $couponId) {
297 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['id'] = $couponId;
298 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['code'] = $row['coupon_code'];
299 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['discount'] = $row['coupon_discount'];
300 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['deduction'] = $row['coupon_deduction'];
301 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['limit'] = $row['coupon_limit'];
302 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['customerLimit'] = $row['coupon_customerLimit'];
303 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['status'] = $row['coupon_status'];
304 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['expirationDate'] = $row['coupon_expirationDate'];
305 $appointments[$appointmentId]['bookings'][$bookingId]['coupon']['startDate'] = $row['coupon_startDate'];
306 }
307
308 if ($bookingId && $customerId) {
309 $appointments[$appointmentId]['bookings'][$bookingId]['customer'] =
310 [
311 'id' => $customerId,
312 'firstName' => $row['customer_firstName'],
313 'lastName' => $row['customer_lastName'],
314 'email' => $row['customer_email'],
315 'note' => $row['customer_note'],
316 'phone' => $row['customer_phone'],
317 'gender' => $row['customer_gender'],
318 'status' => $row['customer_status'],
319 'birthday' => !empty($row['customer_birthday']) ? $row['customer_birthday'] : null,
320 'type' => 'customer',
321 ];
322 }
323
324 if ($bookingId && $locationId) {
325 $appointments[$appointmentId]['location'] =
326 [
327 'id' => $locationId,
328 'name' => !empty($row['location_name']) ? $row['location_name'] : '',
329 'address' => !empty($row['location_address']) ? $row['location_address'] : '',
330 'description' => !empty($row['location_description']) ? $row['location_description'] : null,
331 'status' => !empty($row['location_status']) ? $row['location_status'] : null,
332 'phone' => !empty($row['location_phone']) ? $row['location_phone'] : null,
333 'latitude' => !empty($row['location_latitude']) ? $row['location_latitude'] : null,
334 'longitude' => !empty($row['location_longitude']) ? $row['location_longitude'] : null,
335 'pictureFullPath' => !empty($row['location_pictureFullPath']) ? $row['location_pictureFullPath'] : null,
336 'pictureThumbPath' => !empty($row['location_pictureThumbPath']) ? $row['location_pictureThumbPath'] : null,
337 'pin' => !empty($row['location_pin']) ? $row['location_pin'] : null,
338 'translations' => !empty($row['location_translations']) ? $row['location_translations'] : null
339 ];
340 }
341
342 if ($bookingId && $providerId) {
343 $appointments[$appointmentId]['provider'] =
344 [
345 'id' => $providerId,
346 'firstName' => $row['provider_firstName'],
347 'lastName' => $row['provider_lastName'],
348 'email' => $row['provider_email'],
349 'note' => !empty($row['provider_note']) ? $row['provider_note'] : null,
350 'description' => !empty($row['provider_description']) ? $row['provider_description'] : null,
351 'phone' => !empty($row['provider_phone']) ? $row['provider_phone'] : null,
352 'gender' => !empty($row['provider_gender']) ? $row['provider_gender'] : null,
353 'timeZone' => !empty($row['provider_timeZone']) ? $row['provider_timeZone'] : null,
354 'type' => 'provider',
355 'badgeId' => !empty($row['provider_badgeId']) ? $row['provider_badgeId'] : null,
356 'pictureFullPath' => !empty($row['provider_pictureFullPath']) ? $row['provider_pictureFullPath'] : null,
357 'pictureThumbPath' => !empty($row['provider_pictureThumbPath']) ? $row['provider_pictureThumbPath'] : null,
358 ];
359 }
360
361 if ($serviceId) {
362 $appointments[$appointmentId]['service']['id'] = $row['service_id'];
363 $appointments[$appointmentId]['service']['name'] = isset($row['service_name']) ? $row['service_name'] : null;
364 $appointments[$appointmentId]['service']['description'] = isset($row['service_description']) ? $row['service_description'] : null;
365 $appointments[$appointmentId]['service']['pictureFullPath'] = isset($row['service_pictureFullPath']) ? $row['service_pictureFullPath'] : null;
366 $appointments[$appointmentId]['service']['pictureThumbPath'] = isset($row['service_pictureThumbPath']) ?
367 $row['service_pictureThumbPath'] : null;
368 $appointments[$appointmentId]['service']['color'] = isset($row['service_color']) ? $row['service_color'] : null;
369 $appointments[$appointmentId]['service']['price'] = isset($row['service_price']) ? $row['service_price'] : null;
370 $appointments[$appointmentId]['service']['status'] = isset($row['service_status']) ? $row['service_status'] : null;
371 $appointments[$appointmentId]['service']['categoryId'] = isset($row['service_categoryId']) ? $row['service_categoryId'] : null;
372 $appointments[$appointmentId]['service']['minCapacity'] = isset($row['service_minCapacity']) ? $row['service_minCapacity'] : null;
373 $appointments[$appointmentId]['service']['maxCapacity'] = isset($row['service_maxCapacity']) ? $row['service_maxCapacity'] : null;
374 $appointments[$appointmentId]['service']['duration'] = isset($row['service_duration']) ? $row['service_duration'] : null;
375 $appointments[$appointmentId]['service']['timeBefore'] = isset($row['service_timeBefore'])
376 ? $row['service_timeBefore'] : null;
377 $appointments[$appointmentId]['service']['timeAfter'] = isset($row['service_timeAfter'])
378 ? $row['service_timeAfter'] : null;
379 $appointments[$appointmentId]['service']['aggregatedPrice'] = isset($row['service_aggregatedPrice'])
380 ? $row['service_aggregatedPrice'] : null;
381 $appointments[$appointmentId]['service']['settings'] = isset($row['service_settings'])
382 ? $row['service_settings'] : null;
383 }
384 }
385
386 $collection = new Collection();
387
388 foreach ($appointments as $key => $value) {
389 $collection->addItem(
390 self::create($value),
391 $key
392 );
393 }
394
395 return $collection;
396 }
397 }
398