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