PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / Bookable / Service / PackageCustomerFactory.php
ameliabooking / src / Domain / Factory / Bookable / Service Last commit date
CategoryFactory.php 6 months ago ExtraFactory.php 2 years ago PackageCustomerFactory.php 2 weeks ago PackageCustomerServiceFactory.php 2 weeks ago PackageFactory.php 2 months ago PackageServiceFactory.php 6 months ago ResourceFactory.php 6 months ago ServiceFactory.php 6 months ago
PackageCustomerFactory.php
295 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\Bookable\Service;
9
10 use AmeliaBooking\Domain\Collection\Collection;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Domain\Entity\Bookable\Service\PackageCustomer;
13 use AmeliaBooking\Domain\Factory\Booking\Appointment\AppointmentFactory;
14 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
15 use AmeliaBooking\Domain\Factory\Payment\PaymentFactory;
16 use AmeliaBooking\Domain\Factory\User\UserFactory;
17 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
18 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
19 use AmeliaBooking\Domain\ValueObjects\Json;
20 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
21 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
22 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
23 use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber;
24 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
25 use mageekguy\atoum\scripts\treemap\analyzers\size;
26 use AmeliaBooking\Domain\ValueObjects\String\Token;
27
28 /**
29 * Class PackageCustomerFactory
30 *
31 * @package AmeliaBooking\Domain\Factory\Bookable\Service
32 */
33 class PackageCustomerFactory
34 {
35 /**
36 * @param $data
37 *
38 * @return PackageCustomer
39 * @throws InvalidArgumentException
40 */
41 public static function create($data)
42 {
43 /** @var PackageCustomer $packageCustomer */
44 $packageCustomer = new PackageCustomer();
45
46 if (isset($data['id'])) {
47 $packageCustomer->setId(new Id($data['id']));
48 }
49
50 if (isset($data['packageId'])) {
51 $packageCustomer->setPackageId(new Id($data['packageId']));
52 }
53
54 if (!empty($data['package'])) {
55 $packageCustomer->setPackage(PackageFactory::create($data['package']));
56 }
57
58 if (isset($data['customerId'])) {
59 $packageCustomer->setCustomerId(new Id($data['customerId']));
60 }
61
62 if (isset($data['customer'])) {
63 $packageCustomer->setCustomer(UserFactory::create($data['customer']));
64 }
65
66 if (isset($data['price'])) {
67 $packageCustomer->setPrice(new Price($data['price']));
68 }
69
70 $payments = new Collection();
71 if (!empty($data['payments'])) {
72 /** @var array $paymentsList */
73 $paymentsList = $data['payments'];
74 foreach ($paymentsList as $paymentKey => $payment) {
75 $payments->addItem(PaymentFactory::create($payment), $paymentKey);
76 }
77 }
78 $packageCustomer->setPayments($payments);
79
80
81 if (!empty($data['end'])) {
82 $packageCustomer->setEnd(
83 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['end']))
84 );
85 }
86
87 if (!empty($data['start'])) {
88 $packageCustomer->setStart(
89 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['start']))
90 );
91 }
92
93 if (!empty($data['purchased'])) {
94 $packageCustomer->setPurchased(
95 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['purchased']))
96 );
97 }
98
99 if (!empty($data['status'])) {
100 $packageCustomer->setStatus(
101 new BookingStatus($data['status'])
102 );
103 }
104
105 if (isset($data['bookingsCount'])) {
106 $packageCustomer->setBookingsCount(new WholeNumber($data['bookingsCount']));
107 }
108
109 if (isset($data['couponId'])) {
110 $packageCustomer->setCouponId(new Id($data['couponId']));
111 }
112
113 if (isset($data['coupon'])) {
114 $packageCustomer->setCoupon(CouponFactory::create($data['coupon']));
115 }
116
117 if (isset($data['ivyEntryId'])) {
118 $packageCustomer->setIvyEntryId(new Id($data['ivyEntryId']));
119 }
120
121 if (!empty($data['tax'])) {
122 if (is_string($data['tax'])) {
123 $packageCustomer->setTax(new Json($data['tax']));
124 } elseif (json_encode($data['tax']) !== false) {
125 $packageCustomer->setTax(new Json(json_encode($data['tax'])));
126 }
127 }
128
129 $packageCustomerServices = new Collection();
130 if (!empty($data['packageCustomerServices'])) {
131 /** @var array $packageCustomerServicesList */
132 $packageCustomerServicesList = $data['packageCustomerServices'];
133 foreach ($packageCustomerServicesList as $packageCustomerServiceKey => $packageCustomerService) {
134 $packageCustomerServices->addItem(PackageCustomerServiceFactory::create($packageCustomerService), $packageCustomerServiceKey);
135 }
136 }
137 $packageCustomer->setPackageCustomerServices($packageCustomerServices);
138
139
140 $appointments = new Collection();
141 if (!empty($data['appointments'])) {
142 $appointmentsList = $data['appointments'];
143 foreach ($appointmentsList as $appointmentKey => $appointment) {
144 $appointments->addItem(AppointmentFactory::create($appointment), $appointmentKey);
145 }
146 }
147 $packageCustomer->setAppointments($appointments);
148
149 if (isset($data['token'])) {
150 $packageCustomer->setToken(new Token($data['token']));
151 }
152
153 return $packageCustomer;
154 }
155
156
157 /**
158 * @param array $rows
159 *
160 * @return Collection
161 * @throws InvalidArgumentException
162 */
163 public static function createCollection($rows)
164 {
165 $packageCustomers = [];
166
167 foreach ($rows as $row) {
168 $packageCustomerId = !empty($row['package_customer_id']) ? $row['package_customer_id'] : null;
169 $packageId = !empty($row['package_id']) ? $row['package_id'] : null;
170 $serviceId = !empty($row['service_id']) ? $row['service_id'] : null;
171 $packageServiceId = !empty($row['package_service_id']) ? $row['package_service_id'] : null;
172 $packageCustomerServiceId = !empty($row['package_customer_service_id']) ? $row['package_customer_service_id'] : null;
173 $customerId = !empty($row['package_customer_customerId']) ? $row['package_customer_customerId'] : null;
174 $appointmentId = !empty($row['appointment_id']) ? $row['appointment_id'] : null;
175 $paymentId = !empty($row['payment_id']) ? $row['payment_id'] : null;
176 $couponId = !empty($row['coupon_id']) ? $row['coupon_id'] : null;
177 $providerId = !empty($row['provider_id']) ? $row['provider_id'] : null;
178
179 if (!array_key_exists($packageCustomerId, $packageCustomers)) {
180 $packageCustomers[$packageCustomerId] = [
181 'id' => $packageCustomerId,
182 'packageId' => $row['package_customer_packageId'],
183 'purchased' => $row['package_customer_purchased'],
184 'end' => $row['package_customer_end'],
185 'status' => $row['package_customer_status'],
186 'customerId' => $row['package_customer_customerId'],
187 'bookingsCount' => $row['package_customer_bookingsCount'],
188 'price' => $row['package_customer_price'],
189 'tax' => $row['package_customer_tax'],
190 'couponId' => $row['package_customer_couponId'],
191 'token' => !empty($row['package_customer_token']) ? $row['package_customer_token'] : null,
192 'ivyEntryId' => !empty($row['package_customer_ivyEntryId']) ? $row['package_customer_ivyEntryId'] : null,
193 ];
194 }
195
196 if ($packageId && empty($packageCustomers[$packageCustomerId]['package'])) {
197 $packageCustomers[$packageCustomerId]['package'] = [
198 'id' => $packageId,
199 'name' => $row['package_name'],
200 'color' => $row['package_color'],
201 'pictureThumbPath' => $row['package_pictureThumbPath'],
202 'pictureFullPath' => $row['package_pictureFullPath'],
203 'calculatedPrice' => $row['package_calculatedPrice'],
204 'discount' => $row['package_discount'],
205 'bookable' => []
206 ];
207 }
208
209 if ($packageServiceId && $serviceId && !empty($packageCustomers[$packageCustomerId]['package'])) {
210 $packageCustomers[$packageCustomerId]['package']['bookable'][$packageServiceId] = [
211 'service' => [
212 'id' => $row['service_id'],
213 'name' => $row['service_name']
214 ]
215 ];
216 }
217
218 if ($customerId && empty($packageCustomers[$packageCustomerId]['customer'])) {
219 $packageCustomers[$packageCustomerId]['customer'] = [
220 'id' => $customerId,
221 'firstName' => $row['customer_firstName'],
222 'lastName' => $row['customer_lastName'],
223 'note' => $row['customer_note'],
224 'email' => $row['customer_email'],
225 'type' => 'customer'
226 ];
227 }
228
229
230 if ($packageCustomerServiceId && empty($packageCustomers[$packageCustomerId]['packageCustomerServices'][$packageCustomerServiceId])) {
231 $packageCustomers[$packageCustomerId]['packageCustomerServices'][$packageCustomerServiceId] = [
232 'id' => $packageCustomerServiceId,
233 'bookingsCount' => $row['package_customer_service_bookingsCount'],
234 ];
235 }
236
237 if ($paymentId && empty($packageCustomers[$packageCustomerId]['payments'][$paymentId])) {
238 $packageCustomers[$packageCustomerId]['payments'][$paymentId] = [
239 'id' => $paymentId,
240 'status' => $row['payment_status'],
241 'amount' => $row['payment_amount'],
242 'gateway' => $row['payment_gateway'],
243 'dateTime' => $row['payment_dateTime'],
244 'wcOrderId' => $row['payment_wcOrderId'],
245 'wcOrderItemId' => $row['payment_wcOrderItemId'],
246 'created' => $row['payment_created']
247 ];
248 }
249
250 if ($appointmentId && empty($packageCustomers[$packageCustomerId]['appointments'][$appointmentId])) {
251 $packageCustomers[$packageCustomerId]['appointments'][$appointmentId] = [
252 'id' => $appointmentId,
253 'customerBookingId' => !empty($row['booking_id']) ? $row['booking_id'] : null,
254 'providerId' => $row['appointment_providerId'],
255 'serviceId' => $row['appointment_serviceId'],
256 'provider' => !empty($row['provider_id']) ? [
257 'id' => $row['provider_id'],
258 'firstName' => $row['provider_firstName'],
259 'lastName' => $row['provider_lastName'],
260 'email' => $row['provider_email'],
261 'type' => 'provider',
262 'badgeId' => $row['provider_badgeId'],
263 'pictureFullPath' => $row['provider_pictureFullPath'],
264 'pictureThumbPath' => $row['provider_pictureThumbPath'],
265 ] : null,
266 'notifyParticipants' => $row['appointment_notifyParticipants'],
267 'bookingStart' => $row['appointment_bookingStart'],
268 'bookingEnd' => $row['appointment_bookingEnd'],
269 'status' => $row['appointment_status']
270 ];
271 }
272
273 if ($couponId && empty($packageCustomers[$packageCustomerId]['coupon'])) {
274 $packageCustomers[$packageCustomerId]['coupon'] = [
275 'id' => $couponId,
276 'discount' => $row['coupon_discount'],
277 'deduction' => $row['coupon_deduction'],
278 'status' => $row['coupon_status'],
279 ];
280 }
281 }
282
283 $packageCustomersCollection = new Collection();
284
285 foreach ($packageCustomers as $packageCustomerKey => $packageCustomerArray) {
286 $packageCustomersCollection->addItem(
287 self::create($packageCustomerArray),
288 $packageCustomerKey
289 );
290 }
291
292 return $packageCustomersCollection;
293 }
294 }
295