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 / 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 4 months ago PackageCustomerServiceFactory.php 6 months ago PackageFactory.php 6 months ago PackageServiceFactory.php 6 months ago ResourceFactory.php 6 months ago ServiceFactory.php 6 months ago
PackageCustomerFactory.php
290 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 (!empty($data['tax'])) {
118 if (is_string($data['tax'])) {
119 $packageCustomer->setTax(new Json($data['tax']));
120 } elseif (json_encode($data['tax']) !== false) {
121 $packageCustomer->setTax(new Json(json_encode($data['tax'])));
122 }
123 }
124
125 $packageCustomerServices = new Collection();
126 if (!empty($data['packageCustomerServices'])) {
127 /** @var array $packageCustomerServicesList */
128 $packageCustomerServicesList = $data['packageCustomerServices'];
129 foreach ($packageCustomerServicesList as $packageCustomerServiceKey => $packageCustomerService) {
130 $packageCustomerServices->addItem(PackageCustomerServiceFactory::create($packageCustomerService), $packageCustomerServiceKey);
131 }
132 }
133 $packageCustomer->setPackageCustomerServices($packageCustomerServices);
134
135
136 $appointments = new Collection();
137 if (!empty($data['appointments'])) {
138 $appointmentsList = $data['appointments'];
139 foreach ($appointmentsList as $appointmentKey => $appointment) {
140 $appointments->addItem(AppointmentFactory::create($appointment), $appointmentKey);
141 }
142 }
143 $packageCustomer->setAppointments($appointments);
144
145 if (isset($data['token'])) {
146 $packageCustomer->setToken(new Token($data['token']));
147 }
148
149 return $packageCustomer;
150 }
151
152
153 /**
154 * @param array $rows
155 *
156 * @return Collection
157 * @throws InvalidArgumentException
158 */
159 public static function createCollection($rows)
160 {
161 $packageCustomers = [];
162
163 foreach ($rows as $row) {
164 $packageCustomerId = !empty($row['package_customer_id']) ? $row['package_customer_id'] : null;
165 $packageId = !empty($row['package_id']) ? $row['package_id'] : null;
166 $serviceId = !empty($row['service_id']) ? $row['service_id'] : null;
167 $packageServiceId = !empty($row['package_service_id']) ? $row['package_service_id'] : null;
168 $packageCustomerServiceId = !empty($row['package_customer_service_id']) ? $row['package_customer_service_id'] : null;
169 $customerId = !empty($row['package_customer_customerId']) ? $row['package_customer_customerId'] : null;
170 $appointmentId = !empty($row['appointment_id']) ? $row['appointment_id'] : null;
171 $paymentId = !empty($row['payment_id']) ? $row['payment_id'] : null;
172 $couponId = !empty($row['coupon_id']) ? $row['coupon_id'] : null;
173 $providerId = !empty($row['provider_id']) ? $row['provider_id'] : null;
174
175 if (!array_key_exists($packageCustomerId, $packageCustomers)) {
176 $packageCustomers[$packageCustomerId] = [
177 'id' => $packageCustomerId,
178 'packageId' => $row['package_customer_packageId'],
179 'purchased' => $row['package_customer_purchased'],
180 'end' => $row['package_customer_end'],
181 'status' => $row['package_customer_status'],
182 'customerId' => $row['package_customer_customerId'],
183 'bookingsCount' => $row['package_customer_bookingsCount'],
184 'price' => $row['package_customer_price'],
185 'tax' => $row['package_customer_tax'],
186 'couponId' => $row['package_customer_couponId'],
187 'token' => !empty($row['package_customer_token']) ? $row['package_customer_token'] : null,
188 ];
189 }
190
191 if ($packageId && empty($packageCustomers[$packageCustomerId]['package'])) {
192 $packageCustomers[$packageCustomerId]['package'] = [
193 'id' => $packageId,
194 'name' => $row['package_name'],
195 'color' => $row['package_color'],
196 'pictureThumbPath' => $row['package_pictureThumbPath'],
197 'pictureFullPath' => $row['package_pictureFullPath'],
198 'calculatedPrice' => $row['package_calculatedPrice'],
199 'discount' => $row['package_discount'],
200 'bookable' => []
201 ];
202 }
203
204 if ($packageServiceId && $serviceId && !empty($packageCustomers[$packageCustomerId]['package'])) {
205 $packageCustomers[$packageCustomerId]['package']['bookable'][$packageServiceId] = [
206 'service' => [
207 'id' => $row['service_id'],
208 'name' => $row['service_name']
209 ]
210 ];
211 }
212
213 if ($customerId && empty($packageCustomers[$packageCustomerId]['customer'])) {
214 $packageCustomers[$packageCustomerId]['customer'] = [
215 'id' => $customerId,
216 'firstName' => $row['customer_firstName'],
217 'lastName' => $row['customer_lastName'],
218 'note' => $row['customer_note'],
219 'email' => $row['customer_email'],
220 'type' => 'customer'
221 ];
222 }
223
224
225 if ($packageCustomerServiceId && empty($packageCustomers[$packageCustomerId]['packageCustomerServices'][$packageCustomerServiceId])) {
226 $packageCustomers[$packageCustomerId]['packageCustomerServices'][$packageCustomerServiceId] = [
227 'id' => $packageCustomerServiceId,
228 'bookingsCount' => $row['package_customer_service_bookingsCount'],
229 ];
230 }
231
232 if ($paymentId && empty($packageCustomers[$packageCustomerId]['payments'][$paymentId])) {
233 $packageCustomers[$packageCustomerId]['payments'][$paymentId] = [
234 'id' => $paymentId,
235 'status' => $row['payment_status'],
236 'amount' => $row['payment_amount'],
237 'gateway' => $row['payment_gateway'],
238 'dateTime' => $row['payment_dateTime'],
239 'wcOrderId' => $row['payment_wcOrderId'],
240 'wcOrderItemId' => $row['payment_wcOrderItemId'],
241 'created' => $row['payment_created']
242 ];
243 }
244
245 if ($appointmentId && empty($packageCustomers[$packageCustomerId]['appointments'][$appointmentId])) {
246 $packageCustomers[$packageCustomerId]['appointments'][$appointmentId] = [
247 'id' => $appointmentId,
248 'customerBookingId' => !empty($row['booking_id']) ? $row['booking_id'] : null,
249 'providerId' => $row['appointment_providerId'],
250 'serviceId' => $row['appointment_serviceId'],
251 'provider' => !empty($row['provider_id']) ? [
252 'id' => $row['provider_id'],
253 'firstName' => $row['provider_firstName'],
254 'lastName' => $row['provider_lastName'],
255 'email' => $row['provider_email'],
256 'type' => 'provider',
257 'badgeId' => $row['provider_badgeId'],
258 'pictureFullPath' => $row['provider_pictureFullPath'],
259 'pictureThumbPath' => $row['provider_pictureThumbPath'],
260 ] : null,
261 'notifyParticipants' => $row['appointment_notifyParticipants'],
262 'bookingStart' => $row['appointment_bookingStart'],
263 'bookingEnd' => $row['appointment_bookingEnd'],
264 'status' => $row['appointment_status']
265 ];
266 }
267
268 if ($couponId && empty($packageCustomers[$packageCustomerId]['coupon'])) {
269 $packageCustomers[$packageCustomerId]['coupon'] = [
270 'id' => $couponId,
271 'discount' => $row['coupon_discount'],
272 'deduction' => $row['coupon_deduction'],
273 'status' => $row['coupon_status'],
274 ];
275 }
276 }
277
278 $packageCustomersCollection = new Collection();
279
280 foreach ($packageCustomers as $packageCustomerKey => $packageCustomerArray) {
281 $packageCustomersCollection->addItem(
282 self::create($packageCustomerArray),
283 $packageCustomerKey
284 );
285 }
286
287 return $packageCustomersCollection;
288 }
289 }
290