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 / PackageCustomerServiceFactory.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
PackageCustomerServiceFactory.php
148 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 '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 'package' => [
109 'name' => $row['package_name']
110 ]
111 ]
112 ];
113 }
114 if (!empty($row['payment_id'])) {
115 $packagesCustomersServices[$packageCustomerServiceId]['packageCustomer']['payments'][$row['payment_id']] = [
116 'id' => $row['payment_id'],
117 'customerBookingId' => null,
118 'packageCustomerId' => $row['payment_packageCustomerId'],
119 'status' => $row['payment_status'],
120 'dateTime' => DateTimeService::getCustomDateTimeFromUtc($row['payment_dateTime']),
121 'gateway' => $row['payment_gateway'],
122 'gatewayTitle' => $row['payment_gatewayTitle'],
123 'transactionId' => !empty($row['payment_transactionId']) ? $row['payment_transactionId'] : null,
124 'parentId' => !empty($row['payment_parentId']) ? $row['payment_parentId'] : null,
125 'amount' => $row['payment_amount'],
126 'data' => $row['payment_data'],
127 'wcOrderId' => !empty($row['payment_wcOrderId']) ? $row['payment_wcOrderId'] : null,
128 'wcOrderItemId' => !empty($row['payment_wcOrderItemId']) ? $row['payment_wcOrderItemId'] : null,
129 'created' => !empty($row['payment_created']) ? $row['payment_created'] : null,
130 'invoiceNumber' => !empty($row['payment_invoiceNumber']) ? $row['payment_invoiceNumber'] : null,
131 ];
132 }
133 }
134
135 /** @var Collection $collection */
136 $collection = new Collection();
137
138 foreach ($packagesCustomersServices as $key => $value) {
139 $collection->addItem(
140 self::create($value),
141 $key
142 );
143 }
144
145 return $collection;
146 }
147 }
148