CustomerBookingEventPeriodFactory.php
6 months ago
CustomerBookingEventTicketFactory.php
6 months ago
EventFactory.php
2 weeks ago
EventPeriodFactory.php
6 months ago
EventTagFactory.php
6 months ago
EventTicketFactory.php
6 months ago
RecurringFactory.php
6 months ago
EventFactory.php
627 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' => (int)$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 | 'countryPhoneIso' => |
| 418 | !empty($row['provider_countryPhoneIso']) ? $row['provider_countryPhoneIso'] : null, |
| 419 | 'pictureFullPath' => |
| 420 | isset($row['provider_pictureFullPath']) ? $row['provider_pictureFullPath'] : null, |
| 421 | 'pictureThumbPath' => |
| 422 | isset($row['provider_pictureFullPath']) ? $row['provider_pictureThumbPath'] : null, |
| 423 | 'type' => 'provider', |
| 424 | 'googleCalendar' => [ |
| 425 | 'id' => isset($row['google_calendar_id']) ? $row['google_calendar_id'] : null, |
| 426 | 'token' => isset($row['google_calendar_token']) ? $row['google_calendar_token'] : null, |
| 427 | 'calendarId' => isset($row['google_calendar_calendar_id']) ? $row['google_calendar_calendar_id'] : null |
| 428 | ], |
| 429 | 'translations' => $row['provider_translations'], |
| 430 | 'timeZone' => isset($row['provider_timeZone']) ? $row['provider_timeZone'] : null, |
| 431 | 'outlookCalendar' => [ |
| 432 | 'id' => isset($row['outlook_calendar_id']) ? $row['outlook_calendar_id'] : null, |
| 433 | 'token' => isset($row['outlook_calendar_token']) ? $row['outlook_calendar_token'] : null, |
| 434 | 'calendarId' => isset($row['outlook_calendar_calendar_id']) ? $row['outlook_calendar_calendar_id'] : null |
| 435 | ], |
| 436 | ]; |
| 437 | } |
| 438 | |
| 439 | if ($organizerId) { |
| 440 | $events[$eventId]['organizer'] = |
| 441 | [ |
| 442 | 'id' => $organizerId, |
| 443 | 'firstName' => $row['organizer_firstName'], |
| 444 | 'lastName' => $row['organizer_lastName'], |
| 445 | 'email' => $row['organizer_email'], |
| 446 | 'badgeId' => !empty($row['organizer_badgeId']) ? $row['organizer_badgeId'] : null, |
| 447 | 'pictureThumbPath' => isset($row['organizer_pictureThumbPath']) ? $row['organizer_pictureThumbPath'] : null, |
| 448 | 'pictureFullPath' => isset($row['organizer_pictureFullPath']) ? $row['organizer_pictureFullPath'] : null, |
| 449 | 'type' => 'provider', |
| 450 | ]; |
| 451 | } |
| 452 | |
| 453 | if ($locationId) { |
| 454 | $events[$eventId]['location'] = |
| 455 | [ |
| 456 | 'id' => $locationId, |
| 457 | 'name' => $row['location_name'], |
| 458 | ]; |
| 459 | } |
| 460 | |
| 461 | if ($eventPeriodId && !isset($events[$eventId]['periods'][$eventPeriodId])) { |
| 462 | $zoomMeetingJson = !empty($row['event_periodZoomMeeting']) ? |
| 463 | json_decode($row['event_periodZoomMeeting'], true) : null; |
| 464 | |
| 465 | $events[$eventId]['periods'][$eventPeriodId] = [ |
| 466 | 'id' => $eventPeriodId, |
| 467 | 'eventId' => $eventId, |
| 468 | 'periodStart' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodStart']), |
| 469 | 'periodEnd' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodEnd']), |
| 470 | 'zoomMeeting' => [ |
| 471 | 'id' => $zoomMeetingJson ? $zoomMeetingJson['id'] : null, |
| 472 | 'startUrl' => $zoomMeetingJson ? $zoomMeetingJson['startUrl'] : null, |
| 473 | 'joinUrl' => $zoomMeetingJson ? $zoomMeetingJson['joinUrl'] : null, |
| 474 | ], |
| 475 | 'lessonSpace' => !empty($row['event_periodLessonSpace']) ? |
| 476 | $row['event_periodLessonSpace'] : null, |
| 477 | 'bookings' => [], |
| 478 | 'googleCalendarEventId' => !empty($row['event_googleCalendarEventId']) ? |
| 479 | $row['event_googleCalendarEventId'] : null, |
| 480 | 'googleMeetUrl' => !empty($row['event_googleMeetUrl']) ? |
| 481 | $row['event_googleMeetUrl'] : null, |
| 482 | 'outlookCalendarEventId' => !empty($row['event_outlookCalendarEventId']) ? |
| 483 | $row['event_outlookCalendarEventId'] : null, |
| 484 | 'microsoftTeamsUrl' => !empty($row['event_microsoftTeamsUrl']) ? |
| 485 | $row['event_microsoftTeamsUrl'] : null, |
| 486 | 'appleCalendarEventId' => !empty($row['event_appleCalendarEventId']) ? |
| 487 | $row['event_appleCalendarEventId'] : null |
| 488 | ]; |
| 489 | } |
| 490 | |
| 491 | if ($tagId && !isset($events[$eventId]['tags'][$tagId])) { |
| 492 | $events[$eventId]['tags'][$tagId] = [ |
| 493 | 'id' => $tagId, |
| 494 | 'eventId' => $eventId, |
| 495 | 'name' => $row['event_tagName'] |
| 496 | ]; |
| 497 | } |
| 498 | |
| 499 | if ($bookingId && !isset($events[$eventId]['bookings'][$bookingId])) { |
| 500 | $events[$eventId]['bookings'][$bookingId] = [ |
| 501 | 'id' => $bookingId, |
| 502 | 'appointmentId' => null, |
| 503 | 'customerId' => $row['booking_customerId'], |
| 504 | 'status' => $row['booking_status'], |
| 505 | 'price' => $row['booking_price'], |
| 506 | 'persons' => $row['booking_persons'], |
| 507 | 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null, |
| 508 | 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null, |
| 509 | 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null, |
| 510 | 'aggregatedPrice' => isset($row['booking_aggregatedPrice']) ? |
| 511 | $row['booking_aggregatedPrice'] : null, |
| 512 | 'token' => isset($row['booking_token']) ? $row['booking_token'] : null, |
| 513 | 'created' => !empty($row['booking_created']) ? DateTimeService::getCustomDateTimeFromUtc($row['booking_created']) : null, |
| 514 | 'tax' => isset($row['booking_tax']) ? $row['booking_tax'] : null, |
| 515 | 'ivyEntryId' => isset($row['booking_ivyEntryId']) ? $row['booking_ivyEntryId'] : null, |
| 516 | ]; |
| 517 | } |
| 518 | |
| 519 | if ($bookingTicketId && !isset($events[$eventId]['bookings'][$bookingId]['ticketsData'][$bookingTicketId])) { |
| 520 | $events[$eventId]['bookings'][$bookingId]['ticketsData'][$bookingTicketId] = [ |
| 521 | 'id' => $bookingTicketId, |
| 522 | 'eventTicketId' => $row['booking_ticket_eventTicketId'], |
| 523 | 'customerBookingId' => $bookingId, |
| 524 | 'persons' => $row['booking_ticket_persons'], |
| 525 | 'price' => $row['booking_ticket_price'], |
| 526 | ]; |
| 527 | } |
| 528 | |
| 529 | if ($ticketId && !isset($events[$eventId]['customTickets'][$ticketId])) { |
| 530 | $events[$eventId]['customTickets'][$ticketId] = [ |
| 531 | 'id' => $ticketId, |
| 532 | 'eventId' => $eventId, |
| 533 | 'name' => $row['ticket_name'], |
| 534 | 'enabled' => $row['ticket_enabled'], |
| 535 | 'spots' => $row['ticket_spots'], |
| 536 | 'waitingListSpots' => !empty($row['ticket_waiting_list_spots']) ? $row['ticket_waiting_list_spots'] : 0, |
| 537 | 'price' => $row['ticket_price'], |
| 538 | 'dateRanges' => $row['ticket_dateRanges'], |
| 539 | 'translations' => $row['ticket_translations'], |
| 540 | ]; |
| 541 | } |
| 542 | |
| 543 | if ($bookingId && !isset($events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId])) { |
| 544 | $events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId] = [ |
| 545 | 'id' => $bookingId, |
| 546 | 'appointmentId' => null, |
| 547 | 'customerId' => $row['booking_customerId'], |
| 548 | 'status' => $row['booking_status'], |
| 549 | 'price' => $row['booking_price'], |
| 550 | 'persons' => $row['booking_persons'], |
| 551 | 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null, |
| 552 | 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null, |
| 553 | 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null |
| 554 | ]; |
| 555 | } |
| 556 | |
| 557 | if ($bookingId && $paymentId) { |
| 558 | $events[$eventId]['bookings'][$bookingId]['payments'][$paymentId] = |
| 559 | [ |
| 560 | 'id' => $paymentId, |
| 561 | 'customerBookingId' => $bookingId, |
| 562 | 'status' => $row['payment_status'], |
| 563 | 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']), |
| 564 | 'gateway' => $row['payment_gateway'], |
| 565 | 'gatewayTitle' => $row['payment_gatewayTitle'], |
| 566 | 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null, |
| 567 | 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null, |
| 568 | 'amount' => $row['payment_amount'], |
| 569 | 'data' => $row['payment_data'], |
| 570 | 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null, |
| 571 | 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ? |
| 572 | $row['payment_wcOrderItemId'] : null, |
| 573 | 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null, |
| 574 | ]; |
| 575 | } |
| 576 | |
| 577 | if ($bookingId && $customerId) { |
| 578 | $events[$eventId]['bookings'][$bookingId]['customer'] = |
| 579 | [ |
| 580 | 'id' => $customerId, |
| 581 | 'firstName' => $row['customer_firstName'], |
| 582 | 'lastName' => $row['customer_lastName'], |
| 583 | 'email' => $row['customer_email'], |
| 584 | 'note' => $row['customer_note'], |
| 585 | 'phone' => $row['customer_phone'], |
| 586 | 'countryPhoneIso' => |
| 587 | !empty($row['customer_countryPhoneIso']) ? $row['customer_countryPhoneIso'] : null, |
| 588 | 'gender' => $row['customer_gender'], |
| 589 | 'birthday' => !empty($row['customer_birthday']) ? $row['customer_birthday'] : null, |
| 590 | 'type' => 'customer', |
| 591 | ]; |
| 592 | } |
| 593 | |
| 594 | if ($bookingId && $couponId) { |
| 595 | $events[$eventId]['bookings'][$bookingId]['coupon']['id'] = $couponId; |
| 596 | $events[$eventId]['bookings'][$bookingId]['coupon']['code'] = $row['coupon_code']; |
| 597 | $events[$eventId]['bookings'][$bookingId]['coupon']['discount'] = $row['coupon_discount']; |
| 598 | $events[$eventId]['bookings'][$bookingId]['coupon']['deduction'] = $row['coupon_deduction']; |
| 599 | $events[$eventId]['bookings'][$bookingId]['coupon']['limit'] = $row['coupon_limit']; |
| 600 | $events[$eventId]['bookings'][$bookingId]['coupon']['customerLimit'] = $row['coupon_customerLimit']; |
| 601 | $events[$eventId]['bookings'][$bookingId]['coupon']['status'] = $row['coupon_status']; |
| 602 | } |
| 603 | |
| 604 | if ($couponId) { |
| 605 | $events[$eventId]['coupons'][$couponId]['id'] = $couponId; |
| 606 | $events[$eventId]['coupons'][$couponId]['code'] = $row['coupon_code']; |
| 607 | $events[$eventId]['coupons'][$couponId]['discount'] = $row['coupon_discount']; |
| 608 | $events[$eventId]['coupons'][$couponId]['deduction'] = $row['coupon_deduction']; |
| 609 | $events[$eventId]['coupons'][$couponId]['limit'] = $row['coupon_limit']; |
| 610 | $events[$eventId]['coupons'][$couponId]['customerLimit'] = $row['coupon_customerLimit']; |
| 611 | $events[$eventId]['coupons'][$couponId]['status'] = $row['coupon_status']; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | $collection = new Collection(); |
| 616 | |
| 617 | foreach ($events as $key => $value) { |
| 618 | $collection->addItem( |
| 619 | self::create($value), |
| 620 | $key |
| 621 | ); |
| 622 | } |
| 623 | |
| 624 | return $collection; |
| 625 | } |
| 626 | } |
| 627 |