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
PackageCustomerFactory.php
119 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\Factory\Coupon\CouponFactory; |
| 13 | use AmeliaBooking\Domain\Factory\Payment\PaymentFactory; |
| 14 | use AmeliaBooking\Domain\Factory\User\UserFactory; |
| 15 | use AmeliaBooking\Domain\Services\DateTime\DateTimeService; |
| 16 | use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue; |
| 17 | use AmeliaBooking\Domain\ValueObjects\Json; |
| 18 | use AmeliaBooking\Domain\ValueObjects\Number\Float\Price; |
| 19 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 20 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber; |
| 21 | use AmeliaBooking\Domain\ValueObjects\String\BookingStatus; |
| 22 | |
| 23 | /** |
| 24 | * Class PackageCustomerFactory |
| 25 | * |
| 26 | * @package AmeliaBooking\Domain\Factory\Bookable\Service |
| 27 | */ |
| 28 | class PackageCustomerFactory |
| 29 | { |
| 30 | /** |
| 31 | * @param $data |
| 32 | * |
| 33 | * @return PackageCustomer |
| 34 | * @throws InvalidArgumentException |
| 35 | */ |
| 36 | public static function create($data) |
| 37 | { |
| 38 | /** @var PackageCustomer $packageCustomer */ |
| 39 | $packageCustomer = new PackageCustomer(); |
| 40 | |
| 41 | if (isset($data['id'])) { |
| 42 | $packageCustomer->setId(new Id($data['id'])); |
| 43 | } |
| 44 | |
| 45 | if (isset($data['packageId'])) { |
| 46 | $packageCustomer->setPackageId(new Id($data['packageId'])); |
| 47 | } |
| 48 | |
| 49 | if (isset($data['customerId'])) { |
| 50 | $packageCustomer->setCustomerId(new Id($data['customerId'])); |
| 51 | } |
| 52 | |
| 53 | if (isset($data['customer'])) { |
| 54 | $packageCustomer->setCustomer(UserFactory::create($data['customer'])); |
| 55 | } |
| 56 | |
| 57 | if (isset($data['price'])) { |
| 58 | $packageCustomer->setPrice(new Price($data['price'])); |
| 59 | } |
| 60 | |
| 61 | $payments = new Collection(); |
| 62 | if (!empty($data['payments'])) { |
| 63 | /** @var array $paymentsList */ |
| 64 | $paymentsList = $data['payments']; |
| 65 | foreach ($paymentsList as $paymentKey => $payment) { |
| 66 | $payments->addItem(PaymentFactory::create($payment), $paymentKey); |
| 67 | } |
| 68 | } |
| 69 | $packageCustomer->setPayments($payments); |
| 70 | |
| 71 | |
| 72 | if (!empty($data['end'])) { |
| 73 | $packageCustomer->setEnd( |
| 74 | new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['end'])) |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | if (!empty($data['start'])) { |
| 79 | $packageCustomer->setStart( |
| 80 | new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['start'])) |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | if (!empty($data['purchased'])) { |
| 85 | $packageCustomer->setPurchased( |
| 86 | new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['purchased'])) |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | if (!empty($data['status'])) { |
| 91 | $packageCustomer->setStatus( |
| 92 | new BookingStatus($data['status']) |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | if (isset($data['bookingsCount'])) { |
| 97 | $packageCustomer->setBookingsCount(new WholeNumber($data['bookingsCount'])); |
| 98 | } |
| 99 | |
| 100 | if (isset($data['couponId'])) { |
| 101 | $packageCustomer->setCouponId(new Id($data['couponId'])); |
| 102 | } |
| 103 | |
| 104 | if (isset($data['coupon'])) { |
| 105 | $packageCustomer->setCoupon(CouponFactory::create($data['coupon'])); |
| 106 | } |
| 107 | |
| 108 | if (!empty($data['tax'])) { |
| 109 | if (is_string($data['tax'])) { |
| 110 | $packageCustomer->setTax(new Json($data['tax'])); |
| 111 | } else if (json_encode($data['tax']) !== false) { |
| 112 | $packageCustomer->setTax(new Json(json_encode($data['tax']))); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return $packageCustomer; |
| 117 | } |
| 118 | } |
| 119 |