PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / CustomerBookingFactory.php
ameliabooking / src / Domain / Factory / Booking / Appointment Last commit date
AppointmentFactory.php 1 year ago CustomerBookingExtraFactory.php 1 year ago CustomerBookingFactory.php 1 year ago
CustomerBookingFactory.php
337 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\Bookable\Service\PackageCustomerService;
12 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
13 use AmeliaBooking\Domain\Factory\Bookable\Service\PackageCustomerServiceFactory;
14 use AmeliaBooking\Domain\Factory\Booking\Event\CustomerBookingEventTicketFactory;
15 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
16 use AmeliaBooking\Domain\Factory\Payment\PaymentFactory;
17 use AmeliaBooking\Domain\Factory\User\UserFactory;
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\PositiveDuration;
24 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
25 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
26 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
27 use AmeliaBooking\Domain\ValueObjects\String\Token;
28
29 /**
30 * Class CustomerBookingFactory
31 *
32 * @package AmeliaBooking\Domain\Factory\Booking\Appointment
33 */
34 class CustomerBookingFactory
35 {
36
37 /**
38 * @param $data
39 *
40 * @return CustomerBooking
41 * @throws InvalidArgumentException
42 */
43 public static function create($data)
44 {
45 $customerBooking = new CustomerBooking();
46
47 if (isset($data['id'])) {
48 $customerBooking->setId(new Id($data['id']));
49 }
50
51 if (isset($data['customerId'])) {
52 $customerBooking->setCustomerId(new Id($data['customerId']));
53 }
54
55 if (isset($data['status'])) {
56 $customerBooking->setStatus(new BookingStatus($data['status']));
57 }
58
59 if (isset($data['persons'])) {
60 $customerBooking->setPersons(new IntegerValue($data['persons']));
61 }
62
63 if (isset($data['price'])) {
64 $customerBooking->setPrice(new Price($data['price']));
65 }
66
67 if (isset($data['appointmentId'])) {
68 $customerBooking->setAppointmentId(new Id($data['appointmentId']));
69 }
70
71 if (isset($data['couponId'])) {
72 $customerBooking->setCouponId(new Id($data['couponId']));
73 }
74
75 if (isset($data['coupon'])) {
76 $customerBooking->setCoupon(CouponFactory::create($data['coupon']));
77 }
78
79 if (isset($data['customer'])) {
80 $customerBooking->setCustomer(UserFactory::create($data['customer']));
81 }
82
83 if (isset($data['customFields'])) {
84 if (is_string($data['customFields'])) {
85 $customerBooking->setCustomFields(new Json($data['customFields']));
86 } else if (json_encode($data['customFields']) !== false) {
87 $customerBooking->setCustomFields(new Json(json_encode($data['customFields'])));
88 }
89 }
90
91 if (isset($data['info'])) {
92 $customerBooking->setInfo(new Json($data['info']));
93 }
94
95 if (isset($data['utcOffset'])) {
96 $customerBooking->setUtcOffset(new IntegerValue($data['utcOffset']));
97 }
98
99 if (isset($data['aggregatedPrice'])) {
100 $customerBooking->setAggregatedPrice(new BooleanValueObject($data['aggregatedPrice']));
101 }
102
103 if (isset($data['isChangedStatus'])) {
104 $customerBooking->setChangedStatus(new BooleanValueObject($data['isChangedStatus']));
105 }
106
107 if (isset($data['isLastBooking'])) {
108 $customerBooking->setLastBooking(new BooleanValueObject($data['isLastBooking']));
109 }
110
111 if (isset($data['setIcsFiles'])) {
112 $customerBooking->setIcsFiles($data['setIcsFiles']);
113 }
114
115 if (isset($data['isNew'])) {
116 $customerBooking->setNew(new BooleanValueObject($data['isNew']));
117 }
118
119 if (isset($data['isUpdated'])) {
120 $customerBooking->setUpdated(new BooleanValueObject($data['isUpdated']));
121 }
122
123 if (isset($data['deposit'])) {
124 $customerBooking->setDeposit(new BooleanValueObject($data['deposit']));
125 }
126
127 if (isset($data['packageCustomerService'])) {
128 /** @var PackageCustomerService $packageCustomerService */
129 $packageCustomerService = PackageCustomerServiceFactory::create($data['packageCustomerService']);
130
131 $customerBooking->setPackageCustomerService($packageCustomerService);
132 }
133
134 if (isset($data['duration'])) {
135 $customerBooking->setDuration(new PositiveDuration($data['duration']));
136 }
137
138 $payments = new Collection();
139
140 if (isset($data['payments'])) {
141 foreach ((array)$data['payments'] as $key => $value) {
142 $payments->addItem(
143 PaymentFactory::create($value),
144 $key
145 );
146 }
147 }
148
149 $customerBooking->setPayments($payments);
150
151 $extras = new Collection();
152
153 if (isset($data['extras'])) {
154 foreach ((array)$data['extras'] as $key => $value) {
155 $extras->addItem(
156 CustomerBookingExtraFactory::create($value),
157 $key
158 );
159 }
160 }
161
162 $customerBooking->setExtras($extras);
163
164 if (isset($data['token'])) {
165 $customerBooking->setToken(new Token($data['token']));
166 }
167
168 $ticketsBooking = new Collection();
169
170 if (!empty($data['ticketsData'])) {
171 foreach ((array)$data['ticketsData'] as $key => $value) {
172 $ticketsBooking->addItem(
173 CustomerBookingEventTicketFactory::create($value),
174 $key
175 );
176 }
177 }
178
179 $customerBooking->setTicketsBooking($ticketsBooking);
180
181 if (!empty($data['created'])) {
182 $customerBooking->setCreated(new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['created'])));
183 }
184
185 if (!empty($data['tax'])) {
186 if (is_string($data['tax'])) {
187 $customerBooking->setTax(new Json($data['tax']));
188 } else if (json_encode($data['tax']) !== false) {
189 $customerBooking->setTax(new Json(json_encode($data['tax'])));
190 }
191 }
192
193 return $customerBooking;
194 }
195
196 /**
197 * @param array $rows
198 *
199 * @return array
200 */
201 public static function reformat($rows)
202 {
203 $data = [];
204
205 foreach ($rows as $row) {
206 $id = $row['booking_id'];
207
208 $customerId = !empty($row['customer_id']) ? $row['customer_id'] : null;
209
210 $paymentId = !empty($row['payment_id']) ? $row['payment_id'] : null;
211
212 $couponId = !empty($row['coupon_id']) ? $row['coupon_id'] : null;
213
214 $bookingEventTicketId = !empty($row['booking_ticket_id']) ? $row['booking_ticket_id'] : null;
215
216 $eventPeriodId = !empty($row['event_periodId']) ? $row['event_periodId'] : null;
217
218 $eventProviderId = !empty($row['provider_id']) ? $row['provider_id'] : null;
219
220 $eventId = !empty($row['event_id']) ? $row['event_id'] : null;
221
222 if ($id && empty($data[$id])) {
223 $data[$id] = [
224 'id' => $id,
225 'appointmentId' => $row['booking_appointmentId'],
226 'customerId' => $row['booking_customerId'],
227 'status' => $row['booking_status'],
228 'price' => $row['booking_price'],
229 'persons' => $row['booking_persons'],
230 'couponId' => $row['booking_couponId'],
231 'customFields' => !empty($row['booking_customFields']) ? $row['booking_customFields'] : null,
232 'info' => !empty($row['booking_info']) ? $row['booking_info'] : null,
233 'utcOffset' => $row['booking_utcOffset'],
234 'aggregatedPrice' => $row['booking_aggregatedPrice'],
235 'duration' => !empty($row['booking_duration']) ? $row['booking_duration'] : null,
236 'token' => isset($row['booking_token']) ? $row['booking_token'] : null,
237 'tax' => isset($row['booking_tax']) ? $row['booking_tax'] : null,
238 ];
239 }
240
241 if ($data[$id] && $customerId && empty($data[$id]['customer'])) {
242 $data[$id]['customer'] = [
243 'id' => $customerId,
244 'firstName' => $row['customer_firstName'],
245 'lastName' => $row['customer_lastName'],
246 'email' => $row['customer_email'],
247 'note' => $row['customer_note'],
248 'phone' => $row['customer_phone'],
249 'gender' => $row['customer_gender'],
250 'birthday' => $row['customer_birthday'],
251 ];
252 }
253
254 if ($data[$id] && $paymentId && empty($data[$id]['payments'][$paymentId])) {
255 $data[$id]['payments'][$paymentId] = [
256 'id' => $paymentId,
257 'customerBookingId' => $id,
258 'amount' => $row['payment_amount'],
259 'dateTime' => $row['payment_dateTime'],
260 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
261 'status' => $row['payment_status'],
262 'gateway' => $row['payment_gateway'],
263 'gatewayTitle' => $row['payment_gatewayTitle'],
264 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
265 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
266 'data' => $row['payment_data'],
267 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
268 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ? $row['payment_wcOrderItemId'] : null,
269 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null
270 ];
271 }
272
273 if ($data[$id] && $couponId && empty($data[$id]['coupon'])) {
274 $data[$id]['coupon'] = [
275 'id' => $couponId,
276 'code' => $row['coupon_code'],
277 'discount' => $row['coupon_discount'],
278 'deduction' => $row['coupon_deduction'],
279 'limit' => $row['coupon_limit'],
280 'customerLimit' => $row['coupon_customerLimit'],
281 'status' => $row['coupon_status'],
282 ];
283 }
284
285 if ($data[$id] && $bookingEventTicketId && empty($data[$id]['ticketsData'][$bookingEventTicketId])) {
286 $data[$id]['ticketsData'][$bookingEventTicketId] = [
287 'id' => $bookingEventTicketId,
288 'eventTicketId' => $row['booking_ticket_eventTicketId'],
289 'customerBookingId' => $id,
290 'persons' => $row['booking_ticket_persons'],
291 'price' => $row['booking_ticket_price'],
292 ];
293 }
294
295 if ($data[$id] && $eventId && empty($data[$id]['event'])) {
296 $data[$id]['event'] = [
297 'id' => $eventId,
298 'name' => $row['event_name'],
299 'status' => $row['event_status'],
300 'customPricing' => $row['event_customPricing'],
301 'organizerId' => $row['event_organizerId'],
302 'isWaitingList' => $row['event_settings'] ? json_decode($row['event_settings'], true)['waitingList']['enabled'] : false,
303 ];
304 }
305
306 if ($data[$id] && $eventProviderId) {
307 if ($data[$id]['event']['organizerId'] === $eventProviderId && empty($data[$id]['event']['organizer'])) {
308 $data[$id]['event']['organizer'] = [
309 'id' => $eventProviderId,
310 'firstName' => $row['provider_firstName'],
311 'lastName' => $row['provider_lastName'],
312 'picture' => $row['provider_pictureThumbPath']
313 ];
314 } else if ($data[$id]['event']['organizerId'] !== $eventProviderId && empty($data[$id]['event']['providers'][$eventProviderId])) {
315 $data[$id]['event']['providers'][$eventProviderId] = [
316 'id' => $eventProviderId,
317 'firstName' => $row['provider_firstName'],
318 'lastName' => $row['provider_lastName'],
319 'picture' => $row['provider_pictureThumbPath']
320 ];
321 }
322 }
323
324 if ($data[$id] && $eventPeriodId && empty($data[$id]['eventPeriods'][$eventPeriodId])) {
325 $data[$id]['eventPeriods'][$eventPeriodId] = [
326 'id' => $eventPeriodId,
327 'periodStart' => $row['event_periodStart'],
328 'zoomMeeting' => $row['event_zoomMeeting'],
329 'googleMeetUrl' => $row['event_googleMeetUrl']
330 ];
331 }
332 }
333
334 return $data;
335 }
336 }
337