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