PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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 / PackageCustomerFactory.php
ameliabooking / src / Domain / Factory / Bookable / Service Last commit date
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