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