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