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 / Event / EventFactory.php
ameliabooking / src / Domain / Factory / Booking / Event Last commit date
CustomerBookingEventPeriodFactory.php 6 months ago CustomerBookingEventTicketFactory.php 6 months ago EventFactory.php 6 months ago EventPeriodFactory.php 6 months ago EventTagFactory.php 6 months ago EventTicketFactory.php 6 months ago RecurringFactory.php 6 months ago
EventFactory.php
622 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\Event;
9
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Domain\Entity\Gallery\GalleryImage;
14 use AmeliaBooking\Domain\Factory\Booking\Appointment\CustomerBookingFactory;
15 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
16 use AmeliaBooking\Domain\Factory\Location\LocationFactory;
17 use AmeliaBooking\Domain\Factory\User\ProviderFactory;
18 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
19 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
20 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
21 use AmeliaBooking\Domain\ValueObjects\Json;
22 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
23 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
24 use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger;
25 use AmeliaBooking\Domain\ValueObjects\Picture;
26 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
27 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
28 use AmeliaBooking\Domain\Collection\Collection;
29 use AmeliaBooking\Domain\ValueObjects\String\Color;
30 use AmeliaBooking\Domain\ValueObjects\String\DepositType;
31 use AmeliaBooking\Domain\ValueObjects\String\Description;
32 use AmeliaBooking\Domain\ValueObjects\String\EntityType;
33 use AmeliaBooking\Domain\ValueObjects\String\Name;
34 use AmeliaBooking\Infrastructure\Licence;
35
36 /**
37 * Class EventFactory
38 *
39 * @package AmeliaBooking\Domain\Factory\Booking\Event
40 */
41 class EventFactory
42 {
43 /**
44 * @param array $data
45 *
46 * @return Event
47 * @throws InvalidArgumentException
48 */
49 public static function create($data)
50 {
51 Licence\DataModifier::eventFactory($data);
52
53 $event = new Event();
54
55 if (isset($data['id'])) {
56 $event->setId(new Id($data['id']));
57 }
58
59 if (isset($data['name'])) {
60 $event->setName(new Name($data['name']));
61 }
62
63 if (isset($data['price'])) {
64 $event->setPrice(new Price($data['price']));
65 }
66
67 if (isset($data['parentId'])) {
68 $event->setParentId(new Id($data['parentId']));
69 }
70
71 if (!empty($data['bookingOpens'])) {
72 $event->setBookingOpens(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingOpens'])));
73 }
74
75 if (!empty($data['bookingCloses'])) {
76 $event->setBookingCloses(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingCloses'])));
77 }
78
79 if (!empty($data['bookingOpensRec'])) {
80 $event->setBookingOpensRec($data['bookingOpensRec']);
81 }
82
83 if (!empty($data['bookingClosesRec'])) {
84 $event->setBookingClosesRec($data['bookingClosesRec']);
85 }
86
87 if (!empty($data['ticketRangeRec'])) {
88 $event->setTicketRangeRec($data['ticketRangeRec']);
89 }
90
91 if (isset($data['notifyParticipants'])) {
92 $event->setNotifyParticipants($data['notifyParticipants']);
93 }
94
95 if (isset($data['status'])) {
96 $event->setStatus(new BookingStatus($data['status']));
97 }
98
99 if (isset($data['recurring']['cycle'], $data['recurring']['until'])) {
100 $event->setRecurring(RecurringFactory::create($data['recurring']));
101 }
102
103 if (isset($data['bringingAnyone'])) {
104 $event->setBringingAnyone(new BooleanValueObject($data['bringingAnyone']));
105 }
106
107 if (isset($data['bookMultipleTimes'])) {
108 $event->setBookMultipleTimes(new BooleanValueObject($data['bookMultipleTimes']));
109 }
110
111 if (isset($data['maxCapacity'])) {
112 $event->setMaxCapacity(new IntegerValue($data['maxCapacity']));
113 }
114
115 if (isset($data['maxCustomCapacity'])) {
116 $event->setMaxCustomCapacity(new IntegerValue($data['maxCustomCapacity']));
117 }
118
119 if (isset($data['description'])) {
120 $event->setDescription(new Description($data['description']));
121 }
122
123 if (!empty($data['locationId'])) {
124 $event->setLocationId(new Id($data['locationId']));
125 }
126
127 if (!empty($data['location'])) {
128 $event->setLocation(LocationFactory::create($data['location']));
129 }
130
131 if (!empty($data['customLocation'])) {
132 $event->setCustomLocation(new Name($data['customLocation']));
133 }
134
135 if (isset($data['color'])) {
136 $event->setColor(new Color($data['color']));
137 }
138
139 if (isset($data['show'])) {
140 $event->setShow(new BooleanValueObject($data['show']));
141 }
142
143 if (isset($data['created'])) {
144 $event->setCreated(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['created'])));
145 }
146
147 if (!empty($data['settings'])) {
148 $event->setSettings(new Json($data['settings']));
149 }
150
151 if (isset($data['deposit'])) {
152 $event->setDeposit(new Price($data['deposit']));
153 }
154
155 if (isset($data['depositPayment'])) {
156 $event->setDepositPayment(new DepositType($data['depositPayment']));
157 }
158
159 if (isset($data['fullPayment'])) {
160 $event->setFullPayment(new BooleanValueObject($data['fullPayment']));
161 }
162
163 if (isset($data['customPricing'])) {
164 $event->setCustomPricing(new BooleanValueObject($data['customPricing']));
165 }
166
167 if (isset($data['depositPerPerson'])) {
168 $event->setDepositPerPerson(new BooleanValueObject($data['depositPerPerson']));
169 }
170
171 if (isset($data['closeAfterMin'])) {
172 $event->setCloseAfterMin(new IntegerValue($data['closeAfterMin']));
173 }
174
175 if (isset($data['closeAfterMinBookings'])) {
176 $event->setCloseAfterMinBookings(new BooleanValueObject($data['closeAfterMinBookings']));
177 }
178
179 if (isset($data['aggregatedPrice'])) {
180 $event->setAggregatedPrice(new BooleanValueObject($data['aggregatedPrice']));
181 }
182
183
184 if (isset($data['maxExtraPeople'])) {
185 $event->setMaxExtraPeople(new IntegerValue($data['maxExtraPeople']));
186 }
187
188 $tickets = new Collection();
189
190 if (isset($data['customTickets'])) {
191 foreach ($data['customTickets'] as $key => $value) {
192 $tickets->addItem(
193 EventTicketFactory::create($value),
194 $key
195 );
196 }
197 }
198
199 $event->setCustomTickets($tickets);
200
201 $tags = new Collection();
202
203 if (isset($data['tags'])) {
204 foreach ((array)$data['tags'] as $key => $value) {
205 $tags->addItem(
206 EventTagFactory::create($value),
207 $key
208 );
209 }
210 }
211
212 $event->setTags($tags);
213
214 $bookings = new Collection();
215
216 if (isset($data['bookings'])) {
217 foreach ((array)$data['bookings'] as $key => $value) {
218 $bookings->addItem(
219 CustomerBookingFactory::create($value),
220 $key
221 );
222 }
223 }
224
225 $event->setBookings($bookings);
226
227 $periods = new Collection();
228
229 if (isset($data['periods'])) {
230 foreach ((array)$data['periods'] as $key => $value) {
231 $periods->addItem(EventPeriodFactory::create($value));
232 }
233 }
234
235 $event->setPeriods($periods);
236
237 $gallery = new Collection();
238
239 if (!empty($data['gallery'])) {
240 foreach ((array)$data['gallery'] as $image) {
241 $galleryImage = new GalleryImage(
242 new EntityType(Entities::EVENT),
243 new Picture($image['pictureFullPath'], $image['pictureThumbPath']),
244 new PositiveInteger($image['position'])
245 );
246
247 if (!empty($image['id'])) {
248 $galleryImage->setId(new Id($image['id']));
249 }
250
251 if ($event->getId()) {
252 $galleryImage->setEntityId($event->getId());
253 }
254
255 $gallery->addItem($galleryImage);
256 }
257 }
258
259 $event->setGallery($gallery);
260
261 $coupons = new Collection();
262
263 if (!empty($data['coupons'])) {
264 /** @var array $couponsList */
265 $couponsList = $data['coupons'];
266
267 foreach ($couponsList as $couponKey => $coupon) {
268 $coupons->addItem(CouponFactory::create($coupon), $couponKey);
269 }
270 }
271
272 $event->setCoupons($coupons);
273
274 $providers = new Collection();
275
276 if (!empty($data['providers'])) {
277 /** @var array $providerList */
278 $providerList = $data['providers'];
279
280 foreach ($providerList as $providerKey => $provider) {
281 $provider['type'] = 'provider';
282 $providers->addItem(ProviderFactory::create($provider), $providerKey);
283 }
284 }
285
286 $event->setProviders($providers);
287
288 if (!empty($data['organizerId'])) {
289 $event->setOrganizerId(new Id($data['organizerId']));
290 }
291
292 if (!empty($data['organizer'])) {
293 $data['organizer']['type'] = 'provider';
294 $event->setOrganizer(ProviderFactory::create($data['organizer']));
295 }
296
297 if (!empty($data['zoomUserId'])) {
298 $event->setZoomUserId(new Name($data['zoomUserId']));
299 }
300
301 if (!empty($data['translations'])) {
302 $event->setTranslations(new Json($data['translations']));
303 }
304
305 if (!empty($data['pictureFullPath']) && !empty($data['pictureThumbPath'])) {
306 $event->setPicture(new Picture($data['pictureFullPath'], $data['pictureThumbPath']));
307 }
308
309 return $event;
310 }
311
312 /**
313 * @param array $rows
314 *
315 * @return Collection
316 * @throws InvalidArgumentException
317 */
318 public static function createCollection($rows)
319 {
320 $events = [];
321
322 foreach ($rows as $row) {
323 $eventId = $row['event_id'];
324 $eventPeriodId = isset($row['event_periodId']) ? $row['event_periodId'] : null;
325 $galleryId = isset($row['gallery_id']) ? $row['gallery_id'] : null;
326 $customerId = isset($row['customer_id']) ? $row['customer_id'] : null;
327 $bookingId = isset($row['booking_id']) ? $row['booking_id'] : null;
328 $bookingTicketId = isset($row['booking_ticket_id']) ? $row['booking_ticket_id'] : null;
329 $paymentId = isset($row['payment_id']) ? $row['payment_id'] : null;
330 $tagId = isset($row['event_tagId']) ? $row['event_tagId'] : null;
331 $ticketId = isset($row['ticket_id']) ? $row['ticket_id'] : null;
332 $providerId = isset($row['provider_id']) ? $row['provider_id'] : null;
333 $organizerId = isset($row['organizer_id']) ? $row['organizer_id'] : null;
334 $locationId = isset($row['location_id']) ? $row['location_id'] : null;
335 $couponId = isset($row['coupon_id']) ? $row['coupon_id'] : null;
336
337 if (!array_key_exists($eventId, $events)) {
338 $events[$eventId] = [
339 'id' => $eventId,
340 'name' => $row['event_name'],
341 'status' => $row['event_status'],
342 'bookingOpens' => $row['event_bookingOpens'] && $row['event_bookingOpens'] !== '0000-00-00 00:00:00' ?
343 DateTimeService::getCustomDateTimeFromUtc($row['event_bookingOpens']) : null,
344 'bookingCloses' => $row['event_bookingCloses'] && $row['event_bookingCloses'] !== '0000-00-00 00:00:00' ?
345 DateTimeService::getCustomDateTimeFromUtc($row['event_bookingCloses']) : null,
346 'bookingOpensRec' => isset($row['event_bookingOpensRec']) ?
347 $row['event_bookingOpensRec'] : null,
348 'bookingClosesRec' => isset($row['event_bookingClosesRec']) ?
349 $row['event_bookingClosesRec'] : null,
350 'ticketRangeRec' => isset($row['event_ticketRangeRec']) ?
351 $row['event_ticketRangeRec'] : null,
352 'recurring' => [
353 'cycle' => $row['event_recurringCycle'],
354 'order' => $row['event_recurringOrder'],
355 'cycleInterval' => $row['event_recurringInterval'],
356 'monthlyRepeat' => isset($row['event_recurringMonthly']) ? $row['event_recurringMonthly'] : null,
357 'monthDate' => !empty($row['event_monthlyDate']) && $row['event_monthlyDate'] !== '0000-00-00 00:00:00' ?
358 DateTimeService::getCustomDateTimeFromUtc($row['event_monthlyDate']) : null,
359 'monthlyOnRepeat' => isset($row['event_monthlyOnRepeat']) ? $row['event_monthlyOnRepeat'] : null,
360 'monthlyOnDay' => isset($row['event_monthlyOnDay']) ? $row['event_monthlyOnDay'] : null,
361 'until' => !empty($row['event_recurringUntil']) && $row['event_recurringUntil'] !== '0000-00-00 00:00:00' ?
362 DateTimeService::getCustomDateTimeFromUtc($row['event_recurringUntil']) : null,
363 ],
364 'bringingAnyone' => $row['event_bringingAnyone'],
365 'bookMultipleTimes' => $row['event_bookMultipleTimes'],
366 'maxCapacity' => !empty($row['event_maxCapacity']) ? $row['event_maxCapacity'] : null,
367 'maxCustomCapacity' => !empty($row['event_maxCustomCapacity']) ? $row['event_maxCustomCapacity'] : null,
368 'maxExtraPeople' => !empty($row['event_maxExtraPeople']) ? $row['event_maxExtraPeople'] : null,
369 'price' => $row['event_price'],
370 'description' => $row['event_description'],
371 'color' => $row['event_color'],
372 'show' => $row['event_show'],
373 'notifyParticipants' => $row['event_notifyParticipants'],
374 'locationId' => $row['event_locationId'],
375 'customLocation' => $row['event_customLocation'],
376 'parentId' => $row['event_parentId'],
377 'created' => $row['event_created'],
378 'settings' => isset($row['event_settings']) ? $row['event_settings'] : null,
379 'zoomUserId' => isset($row['event_zoomUserId']) ? $row['event_zoomUserId'] : null,
380 'organizerId' => isset($row['event_organizerId']) ? $row['event_organizerId'] : null,
381 'translations' => isset($row['event_translations']) ? $row['event_translations'] : null,
382 'deposit' => isset($row['event_deposit']) ? $row['event_deposit'] : null,
383 'depositPayment' => isset($row['event_depositPayment']) ?
384 $row['event_depositPayment'] : null,
385 'depositPerPerson' => isset($row['event_depositPerPerson']) ?
386 $row['event_depositPerPerson'] : null,
387 'fullPayment' => isset($row['event_fullPayment']) ?
388 $row['event_fullPayment'] : null,
389 'customPricing' => isset($row['event_customPricing']) ?
390 $row['event_customPricing'] : null,
391 'closeAfterMin' => isset($row['event_closeAfterMin']) ? $row['event_closeAfterMin'] : null,
392 'closeAfterMinBookings' => isset($row['event_closeAfterMinBookings']) ? $row['event_closeAfterMinBookings'] : null,
393 'aggregatedPrice' => isset($row['event_aggregatedPrice']) ? $row['event_aggregatedPrice'] : null,
394 'pictureFullPath' => !empty($row['event_pictureFullPath']) ? $row['event_pictureFullPath'] : null,
395 'pictureThumbPath' => !empty($row['event_pictureThumbPath']) ? $row['event_pictureThumbPath'] : null,
396 ];
397 }
398
399 if ($galleryId) {
400 $events[$eventId]['gallery'][$galleryId]['id'] = $row['gallery_id'];
401 $events[$eventId]['gallery'][$galleryId]['pictureFullPath'] = $row['gallery_picture_full'];
402 $events[$eventId]['gallery'][$galleryId]['pictureThumbPath'] = $row['gallery_picture_thumb'];
403 $events[$eventId]['gallery'][$galleryId]['position'] = $row['gallery_position'];
404 }
405
406 if ($providerId) {
407 $events[$eventId]['providers'][$providerId] =
408 [
409 'id' => $providerId,
410 'firstName' => $row['provider_firstName'],
411 'lastName' => $row['provider_lastName'],
412 'email' => $row['provider_email'],
413 'badgeId' => !empty($row['provider_badgeId']) ? $row['provider_badgeId'] : null,
414 'note' => $row['provider_note'],
415 'description' => $row['provider_description'],
416 'phone' => $row['provider_phone'],
417 'pictureFullPath' =>
418 isset($row['provider_pictureFullPath']) ? $row['provider_pictureFullPath'] : null,
419 'pictureThumbPath' =>
420 isset($row['provider_pictureFullPath']) ? $row['provider_pictureThumbPath'] : null,
421 'type' => 'provider',
422 'googleCalendar' => [
423 'id' => isset($row['google_calendar_id']) ? $row['google_calendar_id'] : null,
424 'token' => isset($row['google_calendar_token']) ? $row['google_calendar_token'] : null,
425 'calendarId' => isset($row['google_calendar_calendar_id']) ? $row['google_calendar_calendar_id'] : null
426 ],
427 'translations' => $row['provider_translations'],
428 'timeZone' => isset($row['provider_timeZone']) ? $row['provider_timeZone'] : null,
429 'outlookCalendar' => [
430 'id' => isset($row['outlook_calendar_id']) ? $row['outlook_calendar_id'] : null,
431 'token' => isset($row['outlook_calendar_token']) ? $row['outlook_calendar_token'] : null,
432 'calendarId' => isset($row['outlook_calendar_calendar_id']) ? $row['outlook_calendar_calendar_id'] : null
433 ],
434 ];
435 }
436
437 if ($organizerId) {
438 $events[$eventId]['organizer'] =
439 [
440 'id' => $organizerId,
441 'firstName' => $row['organizer_firstName'],
442 'lastName' => $row['organizer_lastName'],
443 'email' => $row['organizer_email'],
444 'badgeId' => !empty($row['organizer_badgeId']) ? $row['organizer_badgeId'] : null,
445 'pictureThumbPath' => isset($row['organizer_pictureThumbPath']) ? $row['organizer_pictureThumbPath'] : null,
446 'pictureFullPath' => isset($row['organizer_pictureFullPath']) ? $row['organizer_pictureFullPath'] : null,
447 'type' => 'provider',
448 ];
449 }
450
451 if ($locationId) {
452 $events[$eventId]['location'] =
453 [
454 'id' => $locationId,
455 'name' => $row['location_name'],
456 ];
457 }
458
459 if ($eventPeriodId && !isset($events[$eventId]['periods'][$eventPeriodId])) {
460 $zoomMeetingJson = !empty($row['event_periodZoomMeeting']) ?
461 json_decode($row['event_periodZoomMeeting'], true) : null;
462
463 $events[$eventId]['periods'][$eventPeriodId] = [
464 'id' => $eventPeriodId,
465 'eventId' => $eventId,
466 'periodStart' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodStart']),
467 'periodEnd' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodEnd']),
468 'zoomMeeting' => [
469 'id' => $zoomMeetingJson ? $zoomMeetingJson['id'] : null,
470 'startUrl' => $zoomMeetingJson ? $zoomMeetingJson['startUrl'] : null,
471 'joinUrl' => $zoomMeetingJson ? $zoomMeetingJson['joinUrl'] : null,
472 ],
473 'lessonSpace' => !empty($row['event_periodLessonSpace']) ?
474 $row['event_periodLessonSpace'] : null,
475 'bookings' => [],
476 'googleCalendarEventId' => !empty($row['event_googleCalendarEventId']) ?
477 $row['event_googleCalendarEventId'] : null,
478 'googleMeetUrl' => !empty($row['event_googleMeetUrl']) ?
479 $row['event_googleMeetUrl'] : null,
480 'outlookCalendarEventId' => !empty($row['event_outlookCalendarEventId']) ?
481 $row['event_outlookCalendarEventId'] : null,
482 'microsoftTeamsUrl' => !empty($row['event_microsoftTeamsUrl']) ?
483 $row['event_microsoftTeamsUrl'] : null,
484 'appleCalendarEventId' => !empty($row['event_appleCalendarEventId']) ?
485 $row['event_appleCalendarEventId'] : null
486 ];
487 }
488
489 if ($tagId && !isset($events[$eventId]['tags'][$tagId])) {
490 $events[$eventId]['tags'][$tagId] = [
491 'id' => $tagId,
492 'eventId' => $eventId,
493 'name' => $row['event_tagName']
494 ];
495 }
496
497 if ($bookingId && !isset($events[$eventId]['bookings'][$bookingId])) {
498 $events[$eventId]['bookings'][$bookingId] = [
499 'id' => $bookingId,
500 'appointmentId' => null,
501 'customerId' => $row['booking_customerId'],
502 'status' => $row['booking_status'],
503 'price' => $row['booking_price'],
504 'persons' => $row['booking_persons'],
505 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null,
506 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null,
507 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null,
508 'aggregatedPrice' => isset($row['booking_aggregatedPrice']) ?
509 $row['booking_aggregatedPrice'] : null,
510 'token' => isset($row['booking_token']) ? $row['booking_token'] : null,
511 'created' => !empty($row['booking_created']) ? DateTimeService::getCustomDateTimeFromUtc($row['booking_created']) : null,
512 'tax' => isset($row['booking_tax']) ? $row['booking_tax'] : null,
513 ];
514 }
515
516 if ($bookingTicketId && !isset($events[$eventId]['bookings'][$bookingId]['ticketsData'][$bookingTicketId])) {
517 $events[$eventId]['bookings'][$bookingId]['ticketsData'][$bookingTicketId] = [
518 'id' => $bookingTicketId,
519 'eventTicketId' => $row['booking_ticket_eventTicketId'],
520 'customerBookingId' => $bookingId,
521 'persons' => $row['booking_ticket_persons'],
522 'price' => $row['booking_ticket_price'],
523 ];
524 }
525
526 if ($ticketId && !isset($events[$eventId]['customTickets'][$ticketId])) {
527 $events[$eventId]['customTickets'][$ticketId] = [
528 'id' => $ticketId,
529 'eventId' => $eventId,
530 'name' => $row['ticket_name'],
531 'enabled' => $row['ticket_enabled'],
532 'spots' => $row['ticket_spots'],
533 'waitingListSpots' => !empty($row['ticket_waiting_list_spots']) ? $row['ticket_waiting_list_spots'] : null,
534 'price' => $row['ticket_price'],
535 'dateRanges' => $row['ticket_dateRanges'],
536 'translations' => $row['ticket_translations'],
537 ];
538 }
539
540 if ($bookingId && !isset($events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId])) {
541 $events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId] = [
542 'id' => $bookingId,
543 'appointmentId' => null,
544 'customerId' => $row['booking_customerId'],
545 'status' => $row['booking_status'],
546 'price' => $row['booking_price'],
547 'persons' => $row['booking_persons'],
548 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null,
549 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null,
550 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null
551 ];
552 }
553
554 if ($bookingId && $paymentId) {
555 $events[$eventId]['bookings'][$bookingId]['payments'][$paymentId] =
556 [
557 'id' => $paymentId,
558 'customerBookingId' => $bookingId,
559 'status' => $row['payment_status'],
560 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']),
561 'gateway' => $row['payment_gateway'],
562 'gatewayTitle' => $row['payment_gatewayTitle'],
563 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
564 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
565 'amount' => $row['payment_amount'],
566 'data' => $row['payment_data'],
567 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
568 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ?
569 $row['payment_wcOrderItemId'] : null,
570 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null,
571 ];
572 }
573
574 if ($bookingId && $customerId) {
575 $events[$eventId]['bookings'][$bookingId]['customer'] =
576 [
577 'id' => $customerId,
578 'firstName' => $row['customer_firstName'],
579 'lastName' => $row['customer_lastName'],
580 'email' => $row['customer_email'],
581 'note' => $row['customer_note'],
582 'phone' => $row['customer_phone'],
583 'gender' => $row['customer_gender'],
584 'birthday' => !empty($row['customer_birthday']) ? $row['customer_birthday'] : null,
585 'type' => 'customer',
586 ];
587 }
588
589 if ($bookingId && $couponId) {
590 $events[$eventId]['bookings'][$bookingId]['coupon']['id'] = $couponId;
591 $events[$eventId]['bookings'][$bookingId]['coupon']['code'] = $row['coupon_code'];
592 $events[$eventId]['bookings'][$bookingId]['coupon']['discount'] = $row['coupon_discount'];
593 $events[$eventId]['bookings'][$bookingId]['coupon']['deduction'] = $row['coupon_deduction'];
594 $events[$eventId]['bookings'][$bookingId]['coupon']['limit'] = $row['coupon_limit'];
595 $events[$eventId]['bookings'][$bookingId]['coupon']['customerLimit'] = $row['coupon_customerLimit'];
596 $events[$eventId]['bookings'][$bookingId]['coupon']['status'] = $row['coupon_status'];
597 }
598
599 if ($couponId) {
600 $events[$eventId]['coupons'][$couponId]['id'] = $couponId;
601 $events[$eventId]['coupons'][$couponId]['code'] = $row['coupon_code'];
602 $events[$eventId]['coupons'][$couponId]['discount'] = $row['coupon_discount'];
603 $events[$eventId]['coupons'][$couponId]['deduction'] = $row['coupon_deduction'];
604 $events[$eventId]['coupons'][$couponId]['limit'] = $row['coupon_limit'];
605 $events[$eventId]['coupons'][$couponId]['customerLimit'] = $row['coupon_customerLimit'];
606 $events[$eventId]['coupons'][$couponId]['status'] = $row['coupon_status'];
607 }
608 }
609
610 $collection = new Collection();
611
612 foreach ($events as $key => $value) {
613 $collection->addItem(
614 self::create($value),
615 $key
616 );
617 }
618
619 return $collection;
620 }
621 }
622