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 / PackageCustomerServiceFactory.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 3 months ago PackageServiceFactory.php 6 months ago ResourceFactory.php 6 months ago ServiceFactory.php 6 months ago
PackageCustomerServiceFactory.php
150 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\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 'countryPhoneIso' => !empty($row['customer_countryPhoneIso']) ? $row['customer_countryPhoneIso'] : null,
96 'status' => !empty($row['customer_status']) ? $row['customer_status'] : null,
97 ],
98 'packageId' => $row['package_customer_packageId'],
99 'tax' => $row['package_customer_tax'],
100 'price' => $row['package_customer_price'],
101 'start' => $row['package_customer_start'],
102 'end' => $row['package_customer_end'],
103 'purchased' => DateTimeService::getCustomDateTimeFromUtc(
104 $row['package_customer_purchased']
105 ),
106 'status' => $row['package_customer_status'],
107 'bookingsCount' => $row['package_customer_bookingsCount'],
108 'couponId' => $row['package_customer_couponId'],
109 'package' => [
110 'name' => $row['package_name']
111 ],
112 'ivyEntryId' => $row['package_customer_ivyEntryId'],
113 ]
114 ];
115 }
116 if (!empty($row['payment_id'])) {
117 $packagesCustomersServices[$packageCustomerServiceId]['packageCustomer']['payments'][$row['payment_id']] = [
118 'id' => $row['payment_id'],
119 'customerBookingId' => null,
120 'packageCustomerId' => $row['payment_packageCustomerId'],
121 'status' => $row['payment_status'],
122 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']),
123 'gateway' => $row['payment_gateway'],
124 'gatewayTitle' => $row['payment_gatewayTitle'],
125 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
126 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
127 'amount' => $row['payment_amount'],
128 'data' => $row['payment_data'],
129 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
130 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ? $row['payment_wcOrderItemId'] : null,
131 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
132 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null,
133 ];
134 }
135 }
136
137 /** @var Collection $collection */
138 $collection = new Collection();
139
140 foreach ($packagesCustomersServices as $key => $value) {
141 $collection->addItem(
142 self::create($value),
143 $key
144 );
145 }
146
147 return $collection;
148 }
149 }
150