PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.11
Booking for Appointments and Events Calendar – Amelia v1.2.11
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 / PackageCustomerServiceFactory.php
ameliabooking / src / Domain / Factory / Bookable / Service Last commit date
CategoryFactory.php 2 years ago ExtraFactory.php 2 years ago PackageCustomerFactory.php 1 year ago PackageCustomerServiceFactory.php 1 year ago PackageFactory.php 2 years ago PackageServiceFactory.php 2 years ago ResourceFactory.php 2 years ago ServiceFactory.php 1 year ago
PackageCustomerServiceFactory.php
143 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\Bookable\Service;
8
9 use AmeliaBooking\Domain\Collection\Collection;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Bookable\Service\PackageCustomer;
12 use AmeliaBooking\Domain\Entity\Bookable\Service\PackageCustomerService;
13 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
14 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
15 use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber;
16
17 /**
18 * Class PackageCustomerFactory
19 *
20 * @package AmeliaBooking\Domain\Factory\Bookable\Service
21 */
22 class PackageCustomerServiceFactory
23 {
24 /**
25 * @param $data
26 *
27 * @return PackageCustomerService
28 * @throws InvalidArgumentException
29 */
30 public static function create($data)
31 {
32 /** @var PackageCustomerService $packageCustomerService */
33 $packageCustomerService = new PackageCustomerService();
34
35 if (isset($data['id'])) {
36 $packageCustomerService->setId(new Id($data['id']));
37 }
38
39 if (isset($data['packageCustomer'])) {
40 /** @var PackageCustomer $packageCustomer */
41 $packageCustomer = PackageCustomerFactory::create($data['packageCustomer']);
42
43 $packageCustomerService->setPackageCustomer($packageCustomer);
44 }
45
46 if (isset($data['serviceId'])) {
47 $packageCustomerService->setServiceId(new Id($data['serviceId']));
48 }
49
50 if (isset($data['providerId'])) {
51 $packageCustomerService->setProviderId(new Id($data['providerId']));
52 }
53
54 if (isset($data['locationId'])) {
55 $packageCustomerService->setLocationId(new Id($data['locationId']));
56 }
57
58 if (isset($data['bookingsCount'])) {
59 $packageCustomerService->setBookingsCount(new WholeNumber($data['bookingsCount']));
60 }
61
62 return $packageCustomerService;
63 }
64
65 /**
66 * @param array $rows
67 *
68 * @return Collection
69 * @throws InvalidArgumentException
70 */
71 public static function createCollection($rows)
72 {
73 $packagesCustomersServices = [];
74
75 foreach ($rows as $row) {
76 $packageCustomerServiceId = $row['package_customer_service_id'];
77
78 if (!array_key_exists($packageCustomerServiceId, $packagesCustomersServices)) {
79 $packagesCustomersServices[$packageCustomerServiceId] = [
80 'id' => $packageCustomerServiceId,
81 'serviceId' => $row['package_customer_service_serviceId'],
82 'providerId' => $row['package_customer_service_providerId'],
83 'locationId' => $row['package_customer_service_locationId'],
84 'bookingsCount' => $row['package_customer_service_bookingsCount'],
85 'packageCustomer' => [
86 'id' => $row['package_customer_id'],
87 'customerId' => $row['package_customer_customerId'],
88 'customer' => [
89 'id' => $row['package_customer_customerId'],
90 'firstName' => $row['customer_firstName'],
91 'lastName' => $row['customer_lastName'],
92 'email' => $row['customer_email'],
93 'phone' => $row['customer_phone'],
94 ],
95 'packageId' => $row['package_customer_packageId'],
96 'tax' => $row['package_customer_tax'],
97 'price' => $row['package_customer_price'],
98 'start' => $row['package_customer_start'],
99 'end' => $row['package_customer_end'],
100 'purchased' => DateTimeService::getCustomDateTimeFromUtc(
101 $row['package_customer_purchased']
102 ),
103 'status' => $row['package_customer_status'],
104 'bookingsCount' => $row['package_customer_bookingsCount'],
105 'couponId' => $row['package_customer_couponId'],
106 ]
107 ];
108 }
109 if (!empty($row['payment_id'])) {
110 $packagesCustomersServices[$packageCustomerServiceId]['packageCustomer']['payments'][$row['payment_id']] = [
111 'id' => $row['payment_id'],
112 'customerBookingId' => null,
113 'packageCustomerId' => $row['payment_packageCustomerId'],
114 'status' => $row['payment_status'],
115 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']),
116 'gateway' => $row['payment_gateway'],
117 'gatewayTitle' => $row['payment_gatewayTitle'],
118 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
119 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
120 'amount' => $row['payment_amount'],
121 'data' => $row['payment_data'],
122 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
123 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ? $row['payment_wcOrderItemId'] : null,
124 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
125 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null,
126 ];
127 }
128 }
129
130 /** @var Collection $collection */
131 $collection = new Collection();
132
133 foreach ($packagesCustomersServices as $key => $value) {
134 $collection->addItem(
135 self::create($value),
136 $key
137 );
138 }
139
140 return $collection;
141 }
142 }
143