setId(new Id($data['id'])); } if (isset($data['parentId'])) { $event->setParentId(new Id($data['parentId'])); } if (!empty($data['bookingOpens'])) { $event->setBookingOpens(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingOpens']))); } if (!empty($data['bookingCloses'])) { $event->setBookingCloses(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['bookingCloses']))); } if (isset($data['notifyParticipants'])) { $event->setNotifyParticipants($data['notifyParticipants']); } if (isset($data['status'])) { $event->setStatus(new BookingStatus($data['status'])); } if (isset($data['recurring']['cycle'], $data['recurring']['until'])) { $event->setRecurring(RecurringFactory::create($data['recurring'])); } if (isset($data['maxCapacity'])) { $event->setMaxCapacity(new IntegerValue($data['maxCapacity'])); } if (isset($data['description'])) { $event->setDescription(new Description($data['description'])); } if (!empty($data['locationId'])) { $event->setLocationId(new Id($data['locationId'])); } if (!empty($data['customLocation'])) { $event->setCustomLocation(new Name($data['customLocation'])); } if (isset($data['color'])) { $event->setColor(new Color($data['color'])); } if (isset($data['show'])) { $event->setShow(new BooleanValueObject($data['show'])); } if (isset($data['created'])) { $event->setCreated(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['created']))); } $tags = new Collection(); if (isset($data['tags'])) { foreach ((array)$data['tags'] as $key => $value) { $tags->addItem( EventTagFactory::create($value), $key ); } } $event->setTags($tags); $bookings = new Collection(); if (isset($data['bookings'])) { foreach ((array)$data['bookings'] as $key => $value) { $bookings->addItem( CustomerBookingFactory::create($value), $key ); } } $event->setBookings($bookings); $periods = new Collection(); if (isset($data['periods'])) { foreach ((array)$data['periods'] as $key => $value) { $periods->addItem(EventPeriodFactory::create($value)); } } $event->setPeriods($periods); $gallery = new Collection(); if (!empty($data['gallery'])) { foreach ((array)$data['gallery'] as $image) { $galleryImage = new GalleryImage( new EntityType(Entities::EVENT), new Picture($image['pictureFullPath'], $image['pictureThumbPath']), new PositiveInteger($image['position']) ); if (!empty($image['id'])) { $galleryImage->setId(new Id($image['id'])); } if ($event->getId()) { $galleryImage->setEntityId($event->getId()); } $gallery->addItem($galleryImage); } } $event->setGallery($gallery); $coupons = new Collection(); if (!empty($data['coupons'])) { /** @var array $couponsList */ $couponsList = $data['coupons']; foreach ($couponsList as $couponKey => $coupon) { $coupons->addItem(CouponFactory::create($coupon), $couponKey); } } $event->setCoupons($coupons); $providers = new Collection(); if (!empty($data['providers'])) { /** @var array $providerList */ $providerList = $data['providers']; foreach ($providerList as $providerKey => $provider) { $providers->addItem(ProviderFactory::create($provider), $providerKey); } } $event->setProviders($providers); return $event; } /** * @param array $rows * * @return Collection * @throws InvalidArgumentException */ public static function createCollection($rows) { $events = []; foreach ($rows as $row) { $eventId = $row['event_id']; $eventPeriodId = isset($row['event_periodId']) ? $row['event_periodId'] : null; $galleryId = isset($row['gallery_id']) ? $row['gallery_id'] : null; $customerId = isset($row['customer_id']) ? $row['customer_id'] : null; $bookingId = isset($row['booking_id']) ? $row['booking_id'] : null; $paymentId = isset($row['payment_id']) ? $row['payment_id'] : null; $tagId = isset($row['event_tagId']) ? $row['event_tagId'] : null; $providerId = isset($row['provider_id']) ? $row['provider_id'] : null; if (!array_key_exists($eventId, $events)) { $events[$eventId] = [ 'id' => $eventId, 'name' => $row['event_name'], 'status' => $row['event_status'], 'bookingOpens' => $row['event_bookingOpens'] ? DateTimeService::getCustomDateTimeFromUtc($row['event_bookingOpens']) : null, 'bookingCloses' => $row['event_bookingCloses'] ? DateTimeService::getCustomDateTimeFromUtc($row['event_bookingCloses']) : null, 'recurring' => [ 'cycle' => $row['event_recurringCycle'], 'order' => $row['event_recurringOrder'], 'until' => DateTimeService::getCustomDateTimeFromUtc($row['event_recurringUntil']) ], 'maxCapacity' => $row['event_maxCapacity'], 'price' => $row['event_price'], 'description' => $row['event_description'], 'color' => $row['event_color'], 'show' => $row['event_show'], 'notifyParticipants' => $row['event_notifyParticipants'], 'locationId' => $row['event_locationId'], 'customLocation' => $row['event_customLocation'], 'parentId' => $row['event_parentId'], 'created' => $row['event_created'], ]; } if ($galleryId) { $events[$eventId]['gallery'][$galleryId]['id'] = $row['gallery_id']; $events[$eventId]['gallery'][$galleryId]['pictureFullPath'] = $row['gallery_picture_full']; $events[$eventId]['gallery'][$galleryId]['pictureThumbPath'] = $row['gallery_picture_thumb']; $events[$eventId]['gallery'][$galleryId]['position'] = $row['gallery_position']; } if ($providerId) { $events[$eventId]['providers'][$providerId] = [ 'id' => $providerId, 'firstName' => $row['provider_firstName'], 'lastName' => $row['provider_lastName'], 'email' => $row['provider_email'], 'note' => $row['provider_note'], 'phone' => $row['provider_phone'], 'pictureFullPath' => isset($row['provider_pictureFullPath']) ? $row['provider_pictureFullPath'] : null, 'pictureThumbPath' => isset($row['provider_pictureFullPath']) ? $row['provider_pictureThumbPath'] : null, 'type' => 'provider', ]; } if ($eventPeriodId && !isset($events[$eventId]['periods'][$eventPeriodId])) { $events[$eventId]['periods'][$eventPeriodId] = [ 'id' => $eventPeriodId, 'eventId' => $eventId, 'periodStart' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodStart']), 'periodEnd' => DateTimeService::getCustomDateTimeFromUtc($row['event_periodEnd']), 'bookings' => [] ]; } if ($tagId && !isset($events[$eventId]['tags'][$tagId])) { $events[$eventId]['tags'][$tagId] = [ 'id' => $tagId, 'eventId' => $eventId, 'name' => $row['event_tagName'] ]; } if ($bookingId && !isset($events[$eventId]['bookings'][$bookingId])) { $events[$eventId]['bookings'][$bookingId] = [ 'id' => $bookingId, 'appointmentId' => null, 'customerId' => $row['booking_customerId'], 'status' => $row['booking_status'], 'price' => $row['booking_price'], 'persons' => $row['booking_persons'], 'customFields' => isset($row['booking_customFields']) ? $row['booking_customFields'] : null, 'info' => isset($row['booking_info']) ? $row['booking_info'] : null, 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null ]; } if ($bookingId && !isset($events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId])) { $events[$eventId]['periods'][$eventPeriodId]['bookings'][$bookingId] = [ 'id' => $bookingId, 'appointmentId' => null, 'customerId' => $row['booking_customerId'], 'status' => $row['booking_status'], 'price' => $row['booking_price'], 'persons' => $row['booking_persons'], 'customFields' => isset($row['booking_customFields']) ? $row['booking_customFields'] : null, 'info' => isset($row['booking_info']) ? $row['booking_info'] : null, 'utcOffset' => isset($row['booking_utcOffset']) ? $row['booking_utcOffset'] : null ]; } if ($bookingId && $paymentId) { $events[$eventId]['bookings'][$bookingId]['payments'][$paymentId] = [ 'id' => $paymentId, 'customerBookingId' => $bookingId, 'status' => $row['payment_status'], 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']), 'gateway' => $row['payment_gateway'], 'gatewayTitle' => $row['payment_gatewayTitle'], 'amount' => $row['payment_amount'], 'data' => $row['payment_data'], ]; } if ($bookingId && $customerId) { $events[$eventId]['bookings'][$bookingId]['customer'] = [ 'id' => $customerId, 'firstName' => $row['customer_firstName'], 'lastName' => $row['customer_lastName'], 'email' => $row['customer_email'], 'note' => $row['customer_note'], 'phone' => $row['customer_phone'], 'gender' => $row['customer_gender'], 'type' => 'customer', ]; } } $collection = new Collection(); foreach ($events as $key => $value) { $collection->addItem( self::create($value), $key ); } return $collection; } }